Skip to content

Commit 9d48fc3

Browse files
authored
Merge pull request #9 from API-Team-Organization/develop
Feat :: 이미지 모두 불러오기
2 parents 51cf9a0 + 243a1bb commit 9d48fc3

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

.DS_Store

0 Bytes
Binary file not shown.

src/main/kotlin/com/teamapi/palette/controller/ChatController.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class ChatController(
2828
return ResponseBody.ok("답변 생성 성공", data)
2929
}
3030

31-
@GetMapping("/{roomId}")
3231
@PageableAsQueryParam
3332
suspend fun getChatList(
3433
@PathVariable("roomId") roomId: Long,
@@ -40,4 +39,8 @@ class ChatController(
4039
)
4140
return ResponseBody.ok("채팅 조회 성공", data)
4241
}
42+
43+
@GetMapping("/my-image")
44+
fun getMyImage(@RequestParam pageNumber: Int, @RequestParam pageSize: Int) = chatService
45+
.getMyImage(pageNumber, pageSize)
4346
}

src/main/kotlin/com/teamapi/palette/repository/ChatRepository.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ import org.springframework.stereotype.Repository
99
@Repository
1010
interface ChatRepository : CoroutineCrudRepository<Chat, Long> {
1111
suspend fun findAllByRoomIdIsOrderByDatetimeDesc(roomId: Long, pageable: Pageable): Flow<Chat>
12+
fun findByIsAiAndUserId(isAi: Boolean, userId: Long, pageable: Pageable): Flux<Chat>
1213
}

src/main/kotlin/com/teamapi/palette/service/ChatService.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import com.teamapi.palette.repository.ChatRepository
1313
import com.teamapi.palette.repository.RoomRepository
1414
import com.teamapi.palette.response.ErrorCode
1515
import com.teamapi.palette.response.exception.CustomException
16+
import org.springframework.ai.image.ImageResponse
17+
import org.springframework.data.domain.*
1618
import kotlinx.coroutines.flow.filter
1719
import kotlinx.coroutines.flow.map
1820
import kotlinx.coroutines.flow.toList
1921
import kotlinx.coroutines.reactor.awaitSingle
2022
import org.slf4j.LoggerFactory
21-
import org.springframework.data.domain.Pageable
2223
import org.springframework.stereotype.Service
2324
import reactor.core.publisher.Mono
2425
import reactor.kotlin.core.util.function.component1
@@ -131,6 +132,18 @@ class ChatService(
131132
// )
132133
// )
133134
// )
135+
fun getMyImage(pageNumber: Int, pageSize: Int): Mono<PageImpl<String>> {
136+
val page = PageRequest.of(pageNumber, pageSize)
137+
return sessionHolder
138+
.me()
139+
.flatMap { userId ->
140+
chatRepository.findByIsAiAndUserId(true, userId, page)
141+
.map { it.resource }
142+
.collectList()
143+
.zipWith(chatRepository.count())
144+
.map { p -> PageImpl(p.t1, page, p.t2) }
145+
}
146+
}
134147

135148
private fun chatCompletion(options: ChatCompletionsOptions) = azure.getChatCompletions(
136149
"PaletteGPT", options

0 commit comments

Comments
 (0)