feat(chat): 채팅방 리스트 조회 API를 추가한다
This commit is contained in:
@@ -9,6 +9,8 @@ import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.data.repository.query.Param
|
||||
import org.springframework.stereotype.Repository
|
||||
import java.time.LocalDateTime
|
||||
import kr.co.vividnext.sodalive.v2.chat.dto.ChatRoomListQueryDto as V2ChatRoomListQueryDto
|
||||
|
||||
@Repository
|
||||
interface ChatRoomRepository : JpaRepository<ChatRoom, Long> {
|
||||
@@ -64,5 +66,52 @@ interface ChatRoomRepository : JpaRepository<ChatRoom, Long> {
|
||||
pageable: Pageable
|
||||
): List<ChatRoomListQueryDto>
|
||||
|
||||
@Query(
|
||||
"""
|
||||
SELECT new kr.co.vividnext.sodalive.v2.chat.dto.ChatRoomListQueryDto(
|
||||
r.id,
|
||||
'AI',
|
||||
pc.character.name,
|
||||
pc.character.imagePath,
|
||||
m.message,
|
||||
str(m.messageType),
|
||||
m.createdAt
|
||||
)
|
||||
FROM ChatRoom r
|
||||
JOIN r.participants p
|
||||
JOIN r.participants pc
|
||||
JOIN r.messages m
|
||||
WHERE p.member.id = :memberId
|
||||
AND p.isActive = true
|
||||
AND pc.participantType = kr.co.vividnext.sodalive.chat.room.ParticipantType.CHARACTER
|
||||
AND pc.isActive = true
|
||||
AND r.isActive = true
|
||||
AND m.isActive = true
|
||||
AND (
|
||||
:cursorAt IS NULL
|
||||
OR m.createdAt < :cursorAt
|
||||
OR (m.createdAt = :cursorAt AND 'AI' < :cursorChatType)
|
||||
OR (m.createdAt = :cursorAt AND 'AI' = :cursorChatType AND r.id < :cursorRoomId)
|
||||
)
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM ChatMessage newer
|
||||
WHERE newer.chatRoom = r
|
||||
AND newer.isActive = true
|
||||
AND (
|
||||
newer.createdAt > m.createdAt
|
||||
OR (newer.createdAt = m.createdAt AND newer.id > m.id)
|
||||
)
|
||||
)
|
||||
ORDER BY m.createdAt DESC, r.id DESC
|
||||
"""
|
||||
)
|
||||
fun findAiChatListRooms(
|
||||
@Param("memberId") memberId: Long,
|
||||
@Param("cursorAt") cursorAt: LocalDateTime?,
|
||||
@Param("cursorChatType") cursorChatType: String?,
|
||||
@Param("cursorRoomId") cursorRoomId: Long?,
|
||||
pageable: Pageable
|
||||
): List<V2ChatRoomListQueryDto>
|
||||
|
||||
fun findByIdAndIsActiveTrue(id: Long): ChatRoom?
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user