-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BE] 체크리스트 카테고리별 질문 비교 기능을 구현한다. #963
base: dev-be
Are you sure you want to change the base?
Changes from all commits
aaf20ea
91e7e16
c5bebda
af7c05e
10910e5
a0df72a
4b50599
1b5f5b3
705c8ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,10 @@ public boolean isCategory(Category category) { | |
return question.getCategory().equals(category); | ||
} | ||
|
||
public boolean hasAnswer(Answer answer) { | ||
return this.answer.equals(answer); | ||
} | ||
Comment on lines
+65
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hasAnswer라는 메서드 명이 그냥 Answer를 가지고 있는지 여부를 반환하는 의미로 해석될 수도 있을 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. matchAnswer로 변경했습니다! |
||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.bang_ggood.question.domain; | ||
|
||
import java.util.List; | ||
|
||
public class ChecklistQuestions { | ||
|
||
private final List<ChecklistQuestion> questions; | ||
|
||
public ChecklistQuestions(List<ChecklistQuestion> questions) { | ||
this.questions = questions; | ||
} | ||
|
||
public List<ChecklistQuestion> filterByAnswer(Answer answer) { | ||
return questions.stream() | ||
.filter(question -> question.hasAnswer(answer)) | ||
.toList(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.bang_ggood.question.dto.response; | ||
|
||
import java.util.List; | ||
|
||
public record ComparisonCategoryChecklistQuestionResponse(List<QuestionResponse> good, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dto이름이 한눈에 와닿지 않는 것 같은데, 가지고 있는 데이터를 이름에 담는 방향은 어떻게 생각하시나요?
|
||
List<QuestionResponse> bad, | ||
List<QuestionResponse> none) { | ||
public static ComparisonCategoryChecklistQuestionResponse of(List<QuestionResponse> good, | ||
List<QuestionResponse> bad, | ||
List<QuestionResponse> none) { | ||
return new ComparisonCategoryChecklistQuestionResponse(good, bad, none); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.bang_ggood.question.dto.response; | ||
|
||
import java.util.List; | ||
|
||
public record ComparisonCategoryChecklistQuestionsResponse(ComparisonCategoryChecklistQuestionResponse questions) { | ||
|
||
public static ComparisonCategoryChecklistQuestionsResponse of(List<QuestionResponse> good, | ||
List<QuestionResponse> bad, | ||
List<QuestionResponse> none){ | ||
return new ComparisonCategoryChecklistQuestionsResponse(new ComparisonCategoryChecklistQuestionResponse(good, bad, none)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
package com.bang_ggood.question.service; | ||
|
||
import com.bang_ggood.checklist.domain.Checklist; | ||
import com.bang_ggood.checklist.service.ChecklistService; | ||
import com.bang_ggood.question.domain.Answer; | ||
import com.bang_ggood.question.domain.Category; | ||
import com.bang_ggood.question.domain.ChecklistQuestions; | ||
import com.bang_ggood.question.domain.CustomChecklistQuestion; | ||
import com.bang_ggood.question.domain.Question; | ||
import com.bang_ggood.question.dto.request.CustomChecklistUpdateRequest; | ||
import com.bang_ggood.question.dto.response.CategoryCustomChecklistQuestionResponse; | ||
import com.bang_ggood.question.dto.response.CategoryCustomChecklistQuestionsResponse; | ||
import com.bang_ggood.question.dto.response.CategoryQuestionsResponse; | ||
import com.bang_ggood.question.dto.response.ComparisonCategoryChecklistQuestionsResponse; | ||
import com.bang_ggood.question.dto.response.CustomChecklistQuestionResponse; | ||
import com.bang_ggood.question.dto.response.CustomChecklistQuestionsResponse; | ||
import com.bang_ggood.question.dto.response.QuestionResponse; | ||
|
@@ -21,6 +26,7 @@ | |
@Service | ||
public class QuestionManageService { | ||
|
||
private final ChecklistService checklistService; | ||
private final ChecklistQuestionService checklistQuestionService; | ||
private final QuestionService questionService; | ||
|
||
|
@@ -85,6 +91,26 @@ private CategoryCustomChecklistQuestionsResponse categorizeAllQuestionsWithSelec | |
return CategoryCustomChecklistQuestionsResponse.from(response); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public ComparisonCategoryChecklistQuestionsResponse readComparisonChecklistQuestionsByCategory(User user, Long checklistId, Integer categoryId) { | ||
Checklist checklist = checklistService.readChecklist(user, checklistId); | ||
Category category = questionService.readCategory(categoryId); | ||
ChecklistQuestions checklistQuestions = new ChecklistQuestions(checklistQuestionService.readChecklistQuestionsByCategory(checklist, category)); | ||
|
||
List<QuestionResponse> good = categorizeQuestionsByAnswer(checklistQuestions, Answer.GOOD); | ||
List<QuestionResponse> bad = categorizeQuestionsByAnswer(checklistQuestions, Answer.BAD); | ||
List<QuestionResponse> none = categorizeQuestionsByAnswer(checklistQuestions, Answer.NONE); | ||
|
||
return ComparisonCategoryChecklistQuestionsResponse.of(good, bad, none); | ||
} | ||
|
||
private List<QuestionResponse> categorizeQuestionsByAnswer(ChecklistQuestions checklistQuestions, Answer answer) { | ||
return checklistQuestions.filterByAnswer(answer) | ||
.stream() | ||
.map(checklistQuestion -> new QuestionResponse(checklistQuestion.getQuestion(), questionService.readHighlights(checklistQuestion.getQuestionId()))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Highlight가 비교 페이지에서 꼭 필요하지 않다면 가져오지 않는 방향으로 가는 게 더 좋아보이긴 합니다! |
||
.toList(); | ||
} | ||
|
||
@Transactional | ||
public void updateCustomChecklist(User user, CustomChecklistUpdateRequest request) { | ||
List<Question> questions = questionService.readAllQuestionByIds(request.questionIds()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
queryString으로 설계하지 않고 계층적으로 설계하신 이유가 궁금해요!
계층적 설계가 들어가서 checklists가 먼저 나오니 QuestionController에 위치한 게 어색하다는 생각도 들어서요~