fixed controllers

This commit is contained in:
SlimusMinus
2026-07-31 01:08:53 +03:00
parent 74f7c88843
commit 2468c26b84
32 changed files with 536 additions and 432 deletions

View File

@@ -1,8 +1,10 @@
package com.krylov.refound.repository;
import com.krylov.refound.dto.DialogResponse;
import com.krylov.refound.entity.Message;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
@@ -10,10 +12,14 @@ import org.springframework.data.repository.query.Param;
public interface MessageRepository extends JpaRepository<Message, Long> {
List<Message> findByChatIdOrderByCreatedAtAsc(Long chatId);
long countByChatIdAndIsReadFalseAndSenderIdNot(Long chatId, Long currentUserId);
Page<Message> findByChatIdOrderByCreatedAtDesc(Long chatId, Pageable pageable);
Optional<Message> findFirstByChatIdOrderByCreatedAtDesc(Long chatId);
long countByChatIdAndIsReadFalseAndSenderIdNot(Long chatId, Long userId);
@Modifying
@Query("UPDATE Message m SET m.isRead = true WHERE m.chatId = :chatId AND m.senderId != :userId")
int markAsReadByChatIdAndRecipient(@Param("chatId") Long chatId, @Param("userId") Long userId);
@Query("update Message m set m.isRead = true where m.chatId = :chatId and m.senderId != :userId")
void markAsReadByChatIdAndRecipient(@Param("chatId") Long chatId, @Param("userId") Long userId);
}