Skip to content

Commit

Permalink
edit : 유저의 취향 답변 여부 조회 API 로직 롤백 + 유저 취향 답변 중분류 조회에도 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
bongsh0112 committed Dec 20, 2023
1 parent 3f2296d commit 6cafb74
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ public List<RetrieveCategoryIsAnsweredDTO> retrieveIsAnsweredBySmallCategory() {
.size();
// smallCategory와 같은 smallCategory를 가지는 favorAnswerCategoryDTO의 개수

int size =
favorQuestionCategories.stream()
.filter(category -> category.getSmallCategory().equals(smallCategory))
.toList()
.size();
// smallCategory와 같은 smallCategory를 가지는 detailCategory의 개수

categoryIsAnsweredDTOS.add(
RetrieveCategoryIsAnsweredDTO.of(smallCategory, userAnswerCategorySize > 0));
// smallCategory를 중분류로 가지는 DetailCategory에 대한 취향 답변이 된 set이 하나라도 있다면 true
RetrieveCategoryIsAnsweredDTO.of(
smallCategory, userAnswerCategorySize == size));
// 두 size가 같으면 true, 아니면 false
}

return categoryIsAnsweredDTOS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import org.springframework.transaction.annotation.Transactional;
import tify.server.core.annotation.UseCase;
import tify.server.domain.domains.question.adaptor.FavorAnswerAdaptor;
import tify.server.domain.domains.question.adaptor.FavorQuestionAdaptor;
import tify.server.domain.domains.question.domain.FavorAnswer;
import tify.server.domain.domains.question.domain.FavorQuestionCategory;
import tify.server.domain.domains.question.dto.model.FavorAnswerCategoryDto;
import tify.server.domain.domains.user.domain.SmallCategory;
import tify.server.domain.domains.user.vo.FavorAnswerContentVo;
import tify.server.domain.domains.user.vo.UserAnswerVo;
Expand All @@ -18,13 +21,21 @@
public class UserFavorUseCase {

private final FavorAnswerAdaptor favorAnswerAdaptor;
private final FavorQuestionAdaptor favorQuestionAdaptor;

public List<UserAnswerVo> execute(Long userId, List<SmallCategory> smallCategoryList) {
List<FavorAnswerCategoryDto> favorAnswerCategoryDTOs =
favorAnswerAdaptor.searchCategories(userId);

List<FavorQuestionCategory> favorQuestionCategories =
favorQuestionAdaptor.queryAllFavorQuestionCategory();

// TODO : 리팩토링 해봐야할듯
return smallCategoryList.stream()
.map(
smallCategory -> {
List<FavorAnswer> favorAnswers =
favorAnswerAdaptor.searchByUserIdAndSmallCategory(
favorAnswerAdaptor.queryByUserIdAndSmallCategory(
userId, smallCategory);
List<FavorAnswerContentVo> favorAnswerContentList = new ArrayList<>();
favorAnswers.forEach(
Expand All @@ -39,7 +50,30 @@ public List<UserAnswerVo> execute(Long userId, List<SmallCategory> smallCategory
.getFavorQuestion()
.getNumber(),
favorAnswer.getAnswerContent())));
return UserAnswerVo.of(smallCategory, favorAnswerContentList);
int userAnswerCategorySize =
favorAnswerCategoryDTOs.stream()
.filter(
dto ->
dto.getSmallCategory()
.equals(smallCategory))
.toList()
.size();
// smallCategory와 같은 smallCategory를 가지는 favorAnswerCategoryDTO의 개수

int size =
favorQuestionCategories.stream()
.filter(
category ->
category.getSmallCategory()
.equals(smallCategory))
.toList()
.size();
// smallCategory와 같은 smallCategory를 가지는 detailCategory의 개수

return UserAnswerVo.of(
smallCategory,
favorAnswerContentList,
userAnswerCategorySize == size);
})
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public List<FavorAnswerVo> searchBySmallCategory(
return favorAnswerRepository.getFavorAnswerBySmallCategory(userId, smallCategory);
}

public List<FavorAnswer> searchByUserIdAndSmallCategory(
public List<FavorAnswer> queryByUserIdAndSmallCategory(
Long userId, SmallCategory smallCategory) {
return favorAnswerRepository.getFavorAnswerByUserIdAndSmallCategory(userId, smallCategory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ public class UserAnswerVo {

private final List<FavorAnswerContentVo> answerContentList;

private final boolean isAllDetailCategoryAnswered;

public static UserAnswerVo of(
SmallCategory smallCategory, List<FavorAnswerContentVo> answerContentList) {
SmallCategory smallCategory,
List<FavorAnswerContentVo> answerContentList,
boolean isAllDetailCategoryAnswered) {
return UserAnswerVo.builder()
.smallCategory(smallCategory)
.answerContentList(answerContentList)
.isAllDetailCategoryAnswered(isAllDetailCategoryAnswered)
.build();
}
}

0 comments on commit 6cafb74

Please sign in to comment.