refactor(character): 최근 등록된 캐릭터 조회 로직 개선
조회할 때부터 isActive = true, limit 10개를 불러오도록 리팩토링 - ChatCharacterRepository에 findByIsActiveTrueOrderByCreatedAtDesc 메소드 추가 - ChatCharacterService의 getNewCharacters 메소드 수정
This commit is contained in:
parent
a1533c8e98
commit
7e7a1122fa
|
@ -14,6 +14,11 @@ interface ChatCharacterRepository : JpaRepository<ChatCharacter, Long> {
|
|||
fun findByName(name: String): ChatCharacter?
|
||||
fun findByIsActiveTrue(pageable: Pageable): Page<ChatCharacter>
|
||||
|
||||
/**
|
||||
* 활성화된 캐릭터를 생성일 기준 내림차순으로 조회
|
||||
*/
|
||||
fun findByIsActiveTrueOrderByCreatedAtDesc(pageable: Pageable): List<ChatCharacter>
|
||||
|
||||
/**
|
||||
* 이름, 설명, MBTI, 태그로 캐릭터 검색
|
||||
*/
|
||||
|
|
|
@ -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<ChatCharacter> {
|
||||
return chatCharacterRepository.findAll()
|
||||
.filter { it.isActive }
|
||||
.sortedByDescending { it.createdAt }
|
||||
.take(limit)
|
||||
return chatCharacterRepository.findByIsActiveTrueOrderByCreatedAtDesc(PageRequest.of(0, limit))
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue