-
Notifications
You must be signed in to change notification settings - Fork 1
[feat] 유사칵테일 추천 기능 구현 #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d94aef9
{feat} : domain
lkw9241 e9e3b35
{fix}:Cocktail-Wishlist relation
lkw9241 6f18223
fix : enums
lkw9241 d9d8756
fix : bug
lkw9241 eef075c
feat : 조회기능, 조init data
lkw9241 fd5fccb
feat : cocktailSearch
lkw9241 abbcc3b
feat : controller
lkw9241 1e07a13
feat : input dataset
lkw9241 e9c00a6
fix : dto, service
lkw9241 1f25551
feat : cocktail recommend
lkw9241 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/com/back/domain/cocktail/controller/CocktailRecommendController.java
This file contains hidden or 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,30 @@ | ||
| package com.back.domain.cocktail.controller; | ||
|
|
||
| import com.back.domain.cocktail.dto.CocktailRecommendResponseDto; | ||
| import com.back.domain.cocktail.service.RecommendService; | ||
| import com.back.global.rsData.RsData; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/cocktails/recommend") | ||
| @Tag(name = "ApiCocktailRecommendController", description = "API 칵테일 추천 컨트롤러") | ||
| @RequiredArgsConstructor | ||
| public class CocktailRecommendController { | ||
|
|
||
| private final RecommendService recommendService; | ||
|
|
||
| // 상세페이지 추천 (DTO로 반환) | ||
| @Operation(summary = "상세페이지 유사 칵테일 추천", description = "현재 칵테일과 유사한 칵테일 최대 3개를 반환합니다.") | ||
| @GetMapping("/related") | ||
| public RsData<List<CocktailRecommendResponseDto>> recommendRelated(@RequestParam Long cocktailId) { | ||
| return RsData.successOf(recommendService.recommendRelatedCocktails(cocktailId, 3)); | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/back/domain/cocktail/dto/CocktailRecommendResponseDto.java
This file contains hidden or 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,12 @@ | ||
| package com.back.domain.cocktail.dto; | ||
|
|
||
| public record CocktailRecommendResponseDto( | ||
| Long id, // 상세페이지 이동용 ID | ||
| String cocktailNameKo, // 한글 이름 | ||
| String cocktailName, // 영문 이름 | ||
| String cocktailImgUrl, // 이미지 URL (썸네일) | ||
| String alcoholStrength, // 도수 (라이트/미디엄/스트롱 등) | ||
| String alcoholBaseType // 베이스 주종 (진, 럼, 보드카 등) | ||
| ) { | ||
| } | ||
|
|
This file contains hidden or 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
53 changes: 53 additions & 0 deletions
53
src/main/java/com/back/domain/cocktail/service/RecommendService.java
This file contains hidden or 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,53 @@ | ||
| package com.back.domain.cocktail.service; | ||
|
|
||
| import com.back.domain.cocktail.dto.CocktailRecommendResponseDto; | ||
| import com.back.domain.cocktail.entity.Cocktail; | ||
| import com.back.domain.cocktail.repository.CocktailRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class RecommendService { | ||
|
|
||
| private final CocktailRepository cocktailRepository; | ||
|
|
||
| public List<CocktailRecommendResponseDto> recommendRelatedCocktails(Long cocktailId, int maxSize) { | ||
| Cocktail current = cocktailRepository.findById(cocktailId) | ||
| .orElseThrow(() -> new IllegalArgumentException("존재하지 않는 칵테일입니다.")); | ||
|
|
||
| // 3가지 조건으로 유사 칵테일 조회 | ||
| List<Cocktail> byAlcoholStrength = cocktailRepository.findByAlcoholStrengthAndIdNot(current.getAlcoholStrength(), current.getId()); | ||
| List<Cocktail> byCocktailType = cocktailRepository.findByCocktailTypeAndIdNot(current.getCocktailType(), current.getId()); | ||
| List<Cocktail> byAlcoholBase = cocktailRepository.findByAlcoholBaseTypeAndIdNot(current.getAlcoholBaseType(), current.getId()); | ||
|
|
||
| // 합치고 중복 제거 | ||
| Set<Cocktail> combined = new LinkedHashSet<>(); | ||
| combined.addAll(byAlcoholStrength); | ||
| combined.addAll(byCocktailType); | ||
| combined.addAll(byAlcoholBase); | ||
|
|
||
| List<Cocktail> combinedList = new ArrayList<>(combined); | ||
| if (combinedList.size() > maxSize) { | ||
| combinedList = combinedList.subList(0, maxSize); | ||
| } | ||
|
|
||
| // DTO로 변환 | ||
| return combinedList.stream() | ||
| .map(c -> new CocktailRecommendResponseDto( | ||
| c.getId(), | ||
| c.getCocktailNameKo(), | ||
| c.getCocktailName(), | ||
| c.getCocktailImgUrl(), | ||
| c.getAlcoholStrength().name(), | ||
| c.getAlcoholBaseType().name() | ||
| )) | ||
| .toList(); | ||
| } | ||
| } | ||
|
|
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
유사 칵테일 3개를 유저에게 추천한다고 했을 때, 도수가 같은 칵테일 한 개, 기주가 같은 칵테일 한 개, 타입이 같은 칵테일 한 개 이렇게 세 가지로 추천이 되는 게 맞나요?
생각도 못했어요. 이렇게 구현할 수도 있었네요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
헛! 좋은 아이디어 감사합니다~ ㅎㅎ
지금은 아래 순위로 되어있었어욥 ㅎㅎ
다음 PR때 보완해볼게욥 ㅎㅎ
-알코올 강도가 같은 칵테일 먼저
-타입이 같은 칵테일 다음
-베이스가 같은 칵테일 마지막