66import lombok .RequiredArgsConstructor ;
77import org .springframework .stereotype .Service ;
88
9- import java .util .ArrayList ;
10- import java .util .LinkedHashSet ;
119import java .util .List ;
12- import java .util .Set ;
1310
1411@ Service
1512@ RequiredArgsConstructor
@@ -21,24 +18,20 @@ public List<CocktailRecommendResponseDto> recommendRelatedCocktails(Long cocktai
2118 Cocktail current = cocktailRepository .findById (cocktailId )
2219 .orElseThrow (() -> new IllegalArgumentException ("존재하지 않는 칵테일입니다." ));
2320
24- // 3가지 조건으로 유사 칵테일 조회
25- List <Cocktail > byAlcoholStrength = cocktailRepository .findByAlcoholStrengthAndIdNot (current .getAlcoholStrength (), current .getId ());
26- List <Cocktail > byCocktailType = cocktailRepository .findByCocktailTypeAndIdNot (current .getCocktailType (), current .getId ());
27- List <Cocktail > byAlcoholBase = cocktailRepository .findByAlcoholBaseTypeAndIdNot (current .getAlcoholBaseType (), current .getId ());
21+ // 알콜 강도와 베이스 타이이 같은 칵테일만 조회
22+ List <Cocktail > related = cocktailRepository
23+ .findByAlcoholStrengthAndAlcoholBaseTypeAndIdNot (
24+ current .getAlcoholStrength (),
25+ current .getAlcoholBaseType (),
26+ current .getId ()
27+ );
2828
29- // 합치고 중복 제거
30- Set <Cocktail > combined = new LinkedHashSet <>();
31- combined .addAll (byAlcoholStrength );
32- combined .addAll (byCocktailType );
33- combined .addAll (byAlcoholBase );
34-
35- List <Cocktail > combinedList = new ArrayList <>(combined );
36- if (combinedList .size () > maxSize ) {
37- combinedList = combinedList .subList (0 , maxSize );
29+ if (related .size () > maxSize ) {
30+ related = related .subList (0 , maxSize );
3831 }
3932
4033 // DTO로 변환
41- return combinedList .stream ()
34+ return related .stream ()
4235 .map (c -> new CocktailRecommendResponseDto (
4336 c .getId (),
4437 c .getCocktailNameKo (),
0 commit comments