캐릭터 챗봇 #338
| @@ -29,7 +29,8 @@ data class CharacterCurationListItemResponse( | ||||
|     val id: Long, | ||||
|     val title: String, | ||||
|     val isAdult: Boolean, | ||||
|     val isActive: Boolean | ||||
|     val isActive: Boolean, | ||||
|     val characterCount: Int | ||||
| ) | ||||
|  | ||||
| // 관리자 큐레이션 상세 - 캐릭터 리스트 항목 응답 DTO | ||||
|   | ||||
| @@ -125,8 +125,22 @@ class CharacterCurationAdminService( | ||||
|  | ||||
|     @Transactional(readOnly = true) | ||||
|     fun listAll(): List<CharacterCurationListItemResponse> { | ||||
|         return curationRepository.findAllByOrderBySortOrderAsc() | ||||
|             .map { CharacterCurationListItemResponse(it.id!!, it.title, it.isAdult, it.isActive) } | ||||
|         val curations = curationRepository.findByIsActiveTrueOrderBySortOrderAsc() | ||||
|         if (curations.isEmpty()) return emptyList() | ||||
|  | ||||
|         // DB 집계로 활성 캐릭터 수 카운트 | ||||
|         val counts = mappingRepository.countActiveCharactersByCurations(curations) | ||||
|         val countByCurationId: Map<Long, Int> = counts.associate { it.curationId to it.count.toInt() } | ||||
|  | ||||
|         return curations.map { curation -> | ||||
|             CharacterCurationListItemResponse( | ||||
|                 id = curation.id!!, | ||||
|                 title = curation.title, | ||||
|                 isAdult = curation.isAdult, | ||||
|                 isActive = curation.isActive, | ||||
|                 characterCount = countByCurationId[curation.id!!] ?: 0 | ||||
|             ) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Transactional(readOnly = true) | ||||
|   | ||||
| @@ -30,4 +30,19 @@ interface CharacterCurationMappingRepository : JpaRepository<CharacterCurationMa | ||||
|     fun findByCurationWithCharacterOrderBySortOrderAsc( | ||||
|         @Param("curation") curation: CharacterCuration | ||||
|     ): List<CharacterCurationMapping> | ||||
|  | ||||
|     interface CharacterCountPerCuration { | ||||
|         val curationId: Long | ||||
|         val count: Long | ||||
|     } | ||||
|  | ||||
|     @Query( | ||||
|         "select m.curation.id as curationId, count(m.id) as count " + | ||||
|             "from CharacterCurationMapping m join m.chatCharacter ch " + | ||||
|             "where m.curation in :curations and ch.isActive = true " + | ||||
|             "group by m.curation.id" | ||||
|     ) | ||||
|     fun countActiveCharactersByCurations( | ||||
|         @Param("curations") curations: List<CharacterCuration> | ||||
|     ): List<CharacterCountPerCuration> | ||||
| } | ||||
|   | ||||
| @@ -8,7 +8,6 @@ import org.springframework.stereotype.Repository | ||||
| @Repository | ||||
| interface CharacterCurationRepository : JpaRepository<CharacterCuration, Long> { | ||||
|     fun findByIsActiveTrueOrderBySortOrderAsc(): List<CharacterCuration> | ||||
|     fun findAllByOrderBySortOrderAsc(): List<CharacterCuration> | ||||
|  | ||||
|     @Query("SELECT MAX(c.sortOrder) FROM CharacterCuration c WHERE c.isActive = true") | ||||
|     fun findMaxSortOrder(): Int? | ||||
|   | ||||
		Reference in New Issue
	
	Block a user