-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
9d66589
commit 0afd474
Showing
4 changed files
with
88 additions
and
0 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
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
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
71 changes: 71 additions & 0 deletions
71
...c/main/java/tify/server/domain/domains/question/strategy/HEEXERecommendationStrategy.java
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,71 @@ | ||
package tify.server.domain.domains.question.strategy; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import tify.server.domain.domains.product.adaptor.ProductAdaptor; | ||
import tify.server.domain.domains.product.domain.Product; | ||
import tify.server.domain.domains.question.adaptor.FavorAnswerAdaptor; | ||
import tify.server.domain.domains.question.domain.FavorAnswer; | ||
import tify.server.domain.domains.question.dto.condition.FavorRecommendationDTO; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class HEEXERecommendationStrategy implements ProductRecommendationStrategy { | ||
|
||
private final ProductAdaptor productAdaptor; | ||
private final FavorAnswerAdaptor favorAnswerAdaptor; | ||
|
||
private static final String CATEGORY_NAME = "HEEXE"; | ||
|
||
@Override | ||
public List<Product> recommendation(Long userId, String categoryName, | ||
List<FavorRecommendationDTO> dto) { | ||
|
||
List<FavorRecommendationDTO> recommendationDTO = getRecommendDTO(userId); | ||
|
||
List<String> splitAnswer = Arrays.stream(recommendationDTO.get(0).getAnswer().split(", ")) | ||
.toList(); | ||
|
||
if (splitAnswer.contains("그 외")) { | ||
return etcStep(splitAnswer); | ||
} else { | ||
return specificStep(splitAnswer); | ||
} | ||
} | ||
|
||
private List<FavorRecommendationDTO> getRecommendDTO(Long userId) { | ||
List<FavorAnswer> favorAnswers = new ArrayList<>(); | ||
favorAnswers.add( | ||
favorAnswerAdaptor.searchByCategoryNameAndNumber(userId, CATEGORY_NAME, 2L)); | ||
return favorAnswers.stream().map(FavorRecommendationDTO::from).toList(); | ||
} | ||
|
||
private List<Product> etcStep(List<String> splitAnswer) { // 그 외 라는 답변 존재할 때 | ||
if (splitAnswer.size() > 1) { // ex) 그 외, 헬스 | ||
String answer = splitAnswer.stream().filter(s -> !s.contains("그 외")).toString(); | ||
return productAdaptor.queryAllByCategoryNameAndCharacter(CATEGORY_NAME, answer); | ||
} else { // ex) 그 외 | ||
return productAdaptor.queryAllByCategoryName(CATEGORY_NAME); | ||
} | ||
} | ||
|
||
private List<Product> specificStep(List<String> splitAnswer) { // 그 외 라는 답변 존재하지 않을 때 | ||
List<Product> result = new ArrayList<>(); | ||
if (splitAnswer.size() > 1) { // ex) 헬스, 요가&필라테스 | ||
result.addAll(productAdaptor.queryAllByCategoryNameAndCharacter(CATEGORY_NAME, | ||
splitAnswer.get(0))); | ||
result.addAll(productAdaptor.queryAllByCategoryNameAndCharacter(CATEGORY_NAME, | ||
splitAnswer.get(1))); | ||
} else { // ex) 헬스 | ||
result.addAll(productAdaptor.queryAllByCategoryNameAndCharacter(CATEGORY_NAME, | ||
splitAnswer.get(0))); | ||
} | ||
return result; | ||
} | ||
} |