Skip to content

Commit 6978944

Browse files
authored
Merge pull request #71 from BusanVibe/dev
큐레이션 수정 & 챗봇 이미지 적용
2 parents 03fbc1f + b08cfaf commit 6978944

5 files changed

Lines changed: 65 additions & 34 deletions

File tree

src/main/kotlin/busanVibe/busan/domain/chat/service/ChatMongoService.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ class ChatMongoService(
3030
private val userRepository: UserRepository,
3131
private val openAiService: OpenAiService,
3232
@Value("\${image.chat-bot}")
33-
private val chatBotImage: String
33+
private val chatBotImage: String,
34+
@Value("\${image.guest}")
35+
private val guestImage: String,
3436
) {
3537

3638
val log: Logger = LoggerFactory.getLogger(ChatMongoService::class.java)
@@ -165,9 +167,17 @@ class ChatMongoService(
165167
// DTO 변환
166168
val dtoList = chatHistory.map { chat ->
167169
val user: User? = userMap[chat.userId ?: -1]
170+
val profileImage = when (chat.type) {
171+
MessageType.CHAT, MessageType.BOT_REQUEST -> {
172+
user?.profileImageUrl
173+
}
174+
MessageType.BOT_RESPONSE -> {
175+
chatBotImage
176+
}
177+
}
168178
ChatMessageResponseDTO.ChatInfoDto(
169179
userName = user?.nickname ?: "알 수 없음",
170-
userImage = user?.profileImageUrl,
180+
userImage = profileImage,
171181
dateTime = chat.time,
172182
content = chat.message,
173183
isMy = user?.id == currentUser.id,

src/main/kotlin/busanVibe/busan/domain/home/controller/HomeController.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package busanVibe.busan.domain.home.controller
22

33
import busanVibe.busan.domain.home.dto.HomeResponseDTO
4+
import busanVibe.busan.domain.home.enums.CurationType
45
import busanVibe.busan.domain.home.service.HomeQueryService
56
import busanVibe.busan.global.apiPayload.exception.ApiResponse
67
import io.swagger.v3.oas.annotations.Operation
78
import io.swagger.v3.oas.annotations.tags.Tag
89
import org.springframework.web.bind.annotation.GetMapping
910
import org.springframework.web.bind.annotation.RequestMapping
11+
import org.springframework.web.bind.annotation.RequestParam
1012
import org.springframework.web.bind.annotation.RestController
1113

1214
@Tag(name = "홈화면 API")
@@ -25,15 +27,16 @@ class HomeController(
2527
}
2628

2729
@GetMapping("/curation")
28-
@Operation(summary = "홈화면 큐레이션 조회 API",
30+
@Operation(summary = "큐레이션 조회 API",
2931
description =
3032
"""
31-
임의의 명소 1개, 축제 2개 반환
32-
( 이미지 없는것 베재, 장소는 관광지만 조회 )
33+
명소 혹은 축제에 대한 큐레이션 정보를 반환합니다.
34+
type이 필요합니다. - [ PLACE, FESTIVAL ]
35+
( 이미지 없는것은 베재, 장소는 관광지만 조회 )
3336
"""
3437
)
35-
fun getHomeCuration(): ApiResponse<HomeResponseDTO.CurationList>{
36-
val curations = homeQueryService.getCurations()
38+
fun getHomeCuration(@RequestParam("type", required = true) type: CurationType): ApiResponse<HomeResponseDTO.CurationList>{
39+
val curations = homeQueryService.getCurations(type)
3740
return ApiResponse.onSuccess(curations)
3841
}
3942

src/main/kotlin/busanVibe/busan/domain/home/converter/CurationConverter.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@ class CurationConverter {
2828
imgUrl = festival.festivalImages.first().imgUrl
2929
)
3030

31-
fun toListDto(placeList: List<Place>, festivalList: List<Festival>) : HomeResponseDTO.CurationList{
32-
val placeDtoList = placeList.map { placeToDto(it) }.toList()
33-
val festivalDtoList = festivalList.map { festivalToDto(it) }.toList()
31+
fun placeListToDto(placeList: List<Place>): HomeResponseDTO.CurationList {
32+
val placeDtoList = placeList.map { placeToDto(it) }
33+
return HomeResponseDTO.CurationList(placeDtoList)
34+
}
3435

35-
return HomeResponseDTO.CurationList( placeDtoList + festivalDtoList )
36+
fun festivalListToDto(festivalList: List<Festival>): HomeResponseDTO.CurationList {
37+
val festivalDtoList = festivalList.map { festivalToDto(it) }
38+
return HomeResponseDTO.CurationList(festivalDtoList)
3639
}
3740

3841

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package busanVibe.busan.domain.home.enums
2+
3+
enum class CurationType {
4+
5+
PLACE,
6+
FESTIVAL
7+
8+
}

src/main/kotlin/busanVibe/busan/domain/home/service/HomeQueryService.kt

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import busanVibe.busan.domain.festival.domain.Festival
44
import busanVibe.busan.domain.festival.repository.FestivalRepository
55
import busanVibe.busan.domain.home.converter.CurationConverter
66
import busanVibe.busan.domain.home.dto.HomeResponseDTO
7+
import busanVibe.busan.domain.home.enums.CurationType
78
import busanVibe.busan.domain.place.domain.Place
89
import busanVibe.busan.domain.place.repository.PlaceRepository
910
import busanVibe.busan.domain.place.util.PlaceRedisUtil
@@ -35,31 +36,37 @@ class HomeQueryService(
3536
}
3637

3738
@Transactional(readOnly = true)
38-
fun getCurations(): HomeResponseDTO.CurationList{
39+
fun getCurations(type: CurationType): HomeResponseDTO.CurationList{
3940

4041
// 자원 생성
41-
val placeCount = 1
42-
val festivalCount = 2
43-
44-
// 명소 조회
45-
val placeList: List<Place> = placeRepository.findPlaceImageNotNull() // 이미지 데이터가 있는 Place 목록 조회
46-
val randomPlace: List<Place> = placeList
47-
.takeIf { it.size >= placeCount }
48-
?.shuffled()
49-
?.take(placeCount)
50-
?: throw ExceptionHandler(ErrorStatus.PLACE_NOT_FOUND) // 그 중 랜덤한 항목 가져옴. list 비어있을 시 예외처리
51-
52-
53-
// 축제 조회
54-
val festivalList = festivalRepository.findFestivalImageNotNull() // 이미지 데이터가 있는 Festival 목록 조회
55-
val randomFestival: List<Festival> = festivalList
56-
.takeIf { it.size >= festivalCount }
57-
?.shuffled()
58-
?.take(festivalCount)
59-
?: throw ExceptionHandler(ErrorStatus.FESTIVAL_NOT_FOUND) // 그 중 랜덤한 항목 가져옴. list 비어있을 시 예외처리
60-
61-
// DTO 생성 및 반환
62-
return CurationConverter().toListDto(randomPlace, randomFestival)
42+
val resultCount = 3
43+
44+
// 조건에 따라 조회 후 DTO 반환
45+
return when (type) {
46+
// 명소 조회
47+
CurationType.PLACE -> {
48+
val placeList: List<Place> = placeRepository.findPlaceImageNotNull() // 이미지 데이터가 있는 Place 목록 조회
49+
val randomPlace: List<Place> = placeList
50+
.takeIf { it.size >= resultCount }
51+
?.shuffled()
52+
?.take(resultCount)
53+
?: throw ExceptionHandler(ErrorStatus.PLACE_NOT_FOUND) // 그 중 랜덤한 항목 가져옴. list 비어있을 시 예외처리
54+
CurationConverter().placeListToDto(randomPlace)
55+
}
56+
57+
// 축제 조회
58+
CurationType.FESTIVAL -> {
59+
val festivalList = festivalRepository.findFestivalImageNotNull() // 이미지 데이터가 있는 Festival 목록 조회
60+
val randomFestival: List<Festival> = festivalList
61+
.takeIf { it.size >= resultCount }
62+
?.shuffled()
63+
?.take(resultCount)
64+
?: throw ExceptionHandler(ErrorStatus.FESTIVAL_NOT_FOUND) // 그 중 랜덤한 항목 가져옴. list 비어있을 시 예외처리
65+
CurationConverter().festivalListToDto(randomFestival)
66+
}
67+
68+
}
69+
6370
}
6471

6572
// 가장 붐비는 곳 조회 하여 List<DTO> 반환 - 5개

0 commit comments

Comments
 (0)