Skip to content

Commit

Permalink
FEBAG 추천 전략 로직 수정 #138
Browse files Browse the repository at this point in the history
  • Loading branch information
bongsh0112 committed Feb 2, 2024
1 parent f9336d7 commit cf6d652
Showing 1 changed file with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@ public class FEBAGRecommendationStrategy implements ProductRecommendationStrateg

@Override
public List<Product> recommendation(Long userId, String categoryName) {

List<FavorRecommendationDTO> recommendationDTO = getRecommendationDTO(userId);

validateAnswerSize(recommendationDTO);

List<Product> firstProducts = firstStep(categoryName, recommendationDTO.get(0).getAnswer());

List<Product> secondProducts =
secondStep(firstProducts, recommendationDTO.get(1).getAnswer());

if (validateProductCount(secondProducts)) {
return secondProducts;
}
return secondStep(secondProducts, recommendationDTO.get(2).getAnswer());

return thirdStep(secondProducts, recommendationDTO.get(2).getAnswer());
}

@Override
Expand All @@ -67,12 +68,17 @@ private List<Product> firstStep(String categoryName, String answer) {
return productAdaptor.queryAllByCategoryNameAndCharacter(
categoryName, answerSplits.get(0));
} else {
List<Product> findProducts =
List<Product> productList = new ArrayList<>();
productList.addAll(
productAdaptor.queryAllByCategoryNameAndCharacter(
categoryName, answerSplits.get(0));
return findProducts.stream()
.filter(product -> product.getCharacteristic().contains(answerSplits.get(1)))
.toList();
categoryName, answerSplits.get(0)));
productList.addAll(
productAdaptor
.queryAllByCategoryNameAndCharacter(categoryName, answerSplits.get(1))
.stream()
.filter(product -> !productList.contains(product))
.toList());
return productList;
}
}

Expand All @@ -94,6 +100,14 @@ private List<Product> secondStep(List<Product> findProducts, String answer) {
}
}

private List<Product> thirdStep(List<Product> findProducts, String answer) {
String str = answer.replaceAll(" 들어가면 충분", "");

return findProducts.stream()
.filter(product -> product.getCharacteristic().contains(str))
.toList();
}

private boolean validateProductCount(List<Product> products) {
return products.size() <= MINIMUM_COUNT;
}
Expand Down

0 comments on commit cf6d652

Please sign in to comment.