diff --git a/Domain/src/main/java/tify/server/domain/domains/question/strategy/FEFASRecommendationStrategy.java b/Domain/src/main/java/tify/server/domain/domains/question/strategy/FEFASRecommendationStrategy.java index 9b1b2be..8df1a44 100644 --- a/Domain/src/main/java/tify/server/domain/domains/question/strategy/FEFASRecommendationStrategy.java +++ b/Domain/src/main/java/tify/server/domain/domains/question/strategy/FEFASRecommendationStrategy.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.stream.Stream; import lombok.RequiredArgsConstructor; +import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import tify.server.domain.domains.product.adaptor.ProductAdaptor; @@ -42,6 +43,7 @@ public List recommendation(Long userId, String categoryName) { fefasProducts.addAll( productAdaptor.queryAllByCategoryNameAndCharacter(categoryName, "장갑")); } + fefasProducts.addAll(productAdaptor.queryAllByCategoryNameAndCharacter(categoryName, "지갑")); List products = new ArrayList<>(); products.addAll(hatStep(userId, fefasProducts)); @@ -71,6 +73,7 @@ private List getInitRecommendationDTO(Long userId) { // 장갑 initFavorAnswers.add( favorAnswerAdaptor.searchByCategoryNameAndNumber(userId, CATEGORY_NAME, 7L)); + return initFavorAnswers.stream().map(FavorRecommendationDTO::from).toList(); } @@ -91,13 +94,29 @@ private List hatStep(Long userId, List products) { products.stream() .filter(product -> product.getCharacteristic().contains("모자")) .toList(); - String hatAnswer = - stringBuilder - .append(dto.get(0).getAnswer()) - .append(", ") - .append(dto.get(1).getAnswer()) - .toString(); - return hatList.stream().filter(hat -> hat.getCharacteristic().contains(hatAnswer)).toList(); + + return hatList.stream() + .filter( + product -> { + String[] splitAnswer = dto.get(0).getAnswer().split(", "); + if (splitAnswer.length == 1) { + return product.getCharacteristic().contains(splitAnswer[0]); + } else { + return product.getCharacteristic().contains(splitAnswer[0]) + || product.getCharacteristic().contains(splitAnswer[1]); + } + }) + .filter( + hat -> { + String[] splitAnswer = dto.get(1).getAnswer().split(", "); + if (splitAnswer.length == 1) { + return hat.getCharacteristic().contains(splitAnswer[0]); + } else { + return hat.getCharacteristic().contains(splitAnswer[0]) + || hat.getCharacteristic().contains(splitAnswer[1]); + } + }) + .toList(); } private List walletStep(Long userId, List products) { @@ -110,38 +129,51 @@ private List walletStep(Long userId, List products) { products.stream() .filter(product -> product.getCharacteristic().contains("지갑")) .toList(); - return walletList.stream() - .filter(wallet -> wallet.getCharacteristic().contains(answerContent)) - .toList(); + + return getProducts(answerContent, walletList); } private List mufflerStep(Long userId, List products) { - String answerContent = favorAnswerAdaptor .searchByCategoryNameAndNumber(userId, CATEGORY_NAME, 6L) .getAnswerContent(); + List mufflerList = products.stream() .filter(product -> product.getCharacteristic().contains("목도리")) .toList(); - return mufflerList.stream() - .filter(muffler -> muffler.getCharacteristic().contains(answerContent)) - .toList(); + + return getProducts(answerContent, mufflerList); } private List gloveStep(Long userId, List products) { - String answerContent = favorAnswerAdaptor .searchByCategoryNameAndNumber(userId, CATEGORY_NAME, 8L) .getAnswerContent(); + List gloveList = products.stream() .filter(product -> product.getCharacteristic().contains("장갑")) .toList(); - return gloveList.stream() - .filter(glove -> glove.getCharacteristic().contains(answerContent)) + + return getProducts(answerContent, gloveList); + } + + @NotNull + private List getProducts(String answerContent, List productList) { + return productList.stream() + .filter( + product -> { + String[] splitAnswer = answerContent.split(", "); + if (splitAnswer.length == 1) { + return product.getCharacteristic().contains(splitAnswer[0]); + } else { + return product.getCharacteristic().contains(splitAnswer[0]) + || product.getCharacteristic().contains(splitAnswer[1]); + } + }) .toList(); } }