-
Notifications
You must be signed in to change notification settings - Fork 6
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] 체크리스트 방 비교 기능을 구현한다. #979
Conversation
…course-teams/2024-bang-ggood into feat/974-checklist-compare
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.
시소 코드양만 보아도 고생이 정말 많으셨을 것 같아요 🥹 수고하셨습니다~~~~
@@ -74,6 +77,12 @@ public ResponseEntity<ChecklistsPreviewResponseV1> readLikedChecklistsPreviewV1( | |||
return ResponseEntity.ok(checklistManageService.readLikedChecklistsPreviewV1(user)); | |||
} | |||
|
|||
@GetMapping("/v1/checklists/compare") |
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.
REST API에서는 자원 중심으로 설계하기 때문에 행위는 HTTP 메서드로 나타내고 URI는 명사구를 사용한다고 알고 있는데, 다른 방식으로 표현해보는 건 어떤가요 ???🤔
int allAnsweredQuestionCount = checklistQuestionRepository.countAnsweredQuestionsByChecklistIdAndCategoryId( | ||
checklistId, categoryId); | ||
int goodAnsweredQuestionCount = checklistQuestionRepository.countAnsweredQuestionsByChecklistIdAndCategoryIdAndAnswer( | ||
checklistId, categoryId, Answer.GOOD); |
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.
AnsweredQuestions을 먼저 가져오고 Answer.GOOD인 것만 필터링해서 갯수를 확인하면 2번 데이터베이스에 요청을 보내지 않아도 될 것 같아요!
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.
리팩토링 PR로 반영하겠습니다!!
|
||
double score = ((double) goodAnsweredQuestionCount / allAnsweredQuestionCount) * 100; | ||
return (int) Math.round(score); | ||
} |
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.
비교를 위한 계산 로직이 꽤 중요한 도메인이라고 생각하는데 도메인 내부에서 처리하는 건 어떤가요? 🤔
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.
리팩토링 PR로 반영하겠습니다!!
@DisplayName("카테고리 점수 계산 성공 : 답변이 없는 경우") | ||
@Test | ||
void calculateCategoryScore_noAnswers() { | ||
// given & when | ||
Integer categoryId = QuestionFixture.QUESTION1_CATEGORY1.getCategory().getId(); | ||
Integer score = checklistQuestionService.calculateCategoryScore(checklist.getId(), categoryId); | ||
|
||
// then | ||
assertThat(score).isEqualTo(0); | ||
} |
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.
계산 로직을 가진 도메인이 있다면 해당 테스트도 도메인 테스트로 변경할 수 있을 것 같아요~
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.
리팩토링 PR로 반영하겠습니다!!
❗ Issue
✨ 구현한 기능
체크리스트 방 비교 기능 구현
📢 논의하고 싶은 내용
🎸 기타