diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/repository/ChatCharacterRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/repository/ChatCharacterRepository.kt index 464e1b1..59a617c 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/repository/ChatCharacterRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/repository/ChatCharacterRepository.kt @@ -14,6 +14,11 @@ interface ChatCharacterRepository : JpaRepository { fun findByName(name: String): ChatCharacter? fun findByIsActiveTrue(pageable: Pageable): Page + /** + * 활성화된 캐릭터를 생성일 기준 내림차순으로 조회 + */ + fun findByIsActiveTrueOrderByCreatedAtDesc(pageable: Pageable): List + /** * 이름, 설명, MBTI, 태그로 캐릭터 검색 */ diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/service/ChatCharacterService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/service/ChatCharacterService.kt index ba958cc..574ee72 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/service/ChatCharacterService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/chat/character/service/ChatCharacterService.kt @@ -11,6 +11,7 @@ import kr.co.vividnext.sodalive.chat.character.repository.ChatCharacterHobbyRepo import kr.co.vividnext.sodalive.chat.character.repository.ChatCharacterRepository import kr.co.vividnext.sodalive.chat.character.repository.ChatCharacterTagRepository import kr.co.vividnext.sodalive.chat.character.repository.ChatCharacterValueRepository +import org.springframework.data.domain.PageRequest import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @@ -48,10 +49,7 @@ class ChatCharacterService( */ @Transactional(readOnly = true) fun getNewCharacters(limit: Int = 10): List { - return chatCharacterRepository.findAll() - .filter { it.isActive } - .sortedByDescending { it.createdAt } - .take(limit) + return chatCharacterRepository.findByIsActiveTrueOrderByCreatedAtDesc(PageRequest.of(0, limit)) } /**