-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KAN-101] chat gpt 기반 음식점 추천 (오늘의픽 API)
- Loading branch information
1 parent
676bded
commit a763586
Showing
3 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/com/restaurant/be/restaurant/domain/service/RecommendRestaurantService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.restaurant.be.restaurant.domain.service | ||
|
||
import com.restaurant.be.common.exception.NotFoundUserException | ||
import com.restaurant.be.common.redis.RedisRepository | ||
import com.restaurant.be.restaurant.presentation.controller.dto.RecommendRestaurantResponse | ||
import com.restaurant.be.restaurant.repository.RestaurantRepository | ||
import com.restaurant.be.user.repository.UserRepository | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
class RecommendRestaurantService( | ||
private val redisRepository: RedisRepository, | ||
private val restaurantRepository: RestaurantRepository, | ||
private val userRepository: UserRepository | ||
) { | ||
|
||
@Transactional(readOnly = true) | ||
fun recommendRestaurants(email: String): RecommendRestaurantResponse { | ||
val userId = userRepository.findByEmail(email)?.id ?: throw NotFoundUserException() | ||
|
||
val restaurantIds = redisRepository.getRecommendation(userId) | ||
|
||
val restaurantDtos = restaurantRepository.findDtoByIds(restaurantIds, userId) | ||
|
||
val randomRestaurantDtos = if (restaurantDtos.size > 5) { | ||
restaurantDtos.shuffled().take(5) | ||
} else { | ||
restaurantDtos | ||
} | ||
|
||
return RecommendRestaurantResponse( | ||
restaurants = randomRestaurantDtos.map { it.toDto() } | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters