Skip to content

Commit

Permalink
feat : HEEXE 상품 추천 전략 작성 #138 (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
bongsh0112 authored Dec 26, 2023
1 parent 9d66589 commit 0afd474
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@ public List<ProductRetrieveDTO> findAllBySmallCategoryId(
ProductCategoryCondition productCategoryCondition) {
return productRepository.findAllBySmallCategory(productCategoryCondition);
}

public List<Product> queryAllByCategoryName(String categoryName) {
return productRepository.searchAllByCategoryName(categoryName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ Slice<ProductRetrieveDTO> searchBySmallCategory(

List<ProductRetrieveDTO> findAllBySmallCategory(
ProductCategoryCondition productCategoryCondition);

List<Product> searchAllByCategoryName(String categoryName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ public List<ProductRetrieveDTO> findAllBySmallCategory(
.fetch();
}

@Override
public List<Product> searchAllByCategoryName(String categoryName) {
return queryFactory
.selectFrom(product)
.innerJoin(favorQuestionCategory)
.on(
favorQuestionCategory.id.eq(product.favorQuestionCategoryId),
favorQuestionCategory.name.eq(categoryName))
.fetch();
}

private OrderSpecifier[] orderByPrice(PriceOrder priceOrder) {
List<OrderSpecifier> orderSpecifiers = new ArrayList<>();
if (priceOrder.equals(PRICE_ASC)) {
Expand Down
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;
}
}

0 comments on commit 0afd474

Please sign in to comment.