Skip to content
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] 방 비교 결과 조회 API에 기능을 추가 구현한다. #215

Merged
merged 19 commits into from
Aug 5, 2024

Conversation

tkdgur0906
Copy link
Contributor

❗ Issue

✨ 구현한 기능

  • 체크리스트 랭킹 계산 기능
  • 질문 미 선택 시 null 처리
  • 논리적 삭제 정책 반영

📢 논의하고 싶은 내용

미 선택 질문에 대한 답변을 전체 점수 계산에 반영할 지에 대한 여부

🎸 기타

Copy link
Contributor

@JINU-CHANG JINU-CHANG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고많으셨습니다 👏👏👏
궁금한부분 몇개 코멘트 남겨두었어요~

Comment on lines 252 to 257
List<Integer> ranks = ChecklistRank.calculateRanksByDescendingScores(scores);

for (int idx = 0; idx < checklistsWithScore.size(); idx++) {
ChecklistWithScoreReadResponse checklistWithScore = checklistsWithScore.get(idx);
checklistWithScore.assignRank(ranks.get(idx));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.sorted(Comparator.comparing(ChecklistWithScoreReadResponse::getScore).reversed())

이미 정렬이 되어 있으니 이 순서로 for문 돌면서 rank 부여하면 될 것 같은데 ChecklistRank.calculateRanksByDescendingScores(scores)의 역할을 잘 모르겠어요 🥲

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전체적인 구현방식을 바꿔 인덱스 대신 객체에 직접 값을 할당하는 방법으루 수정하였습니다!

Copy link
Contributor

@shin-jisong shin-jisong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

간단하게 리뷰 남겼습니다! 수고하셨어요~

@@ -19,6 +19,9 @@ public enum Grade {
}

public static Grade from(String grade) {
if(grade == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

공백이 제대로 들어가지 않은 것 같아요
정책상 수정될 코드 같기는 하네요~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정책에 맞게 수정해놨습니다!

List<CategoryScoreReadResponse> categories
) {
public static ChecklistWithScoreReadResponse of(Checklist checklist, int checklistOptionCount, int checklistScore,
public class ChecklistWithScoreReadResponse {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

record에서 class로 바꾼 이유가 있으신가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

객체 생성시 rank를 할당할 수가 없는데 Record를 사용할 경우 setter 사용이 불가했습니다.
rank 계산 후 값을 할당해주기 위해 class로 변경하였습니다!

@@ -25,7 +25,17 @@ default Checklist getById(long id) {

List<Checklist> findByUser(User user);

List<Checklist> findByUserAndIdIn(User user, List<Long> checklistIds);
@Query("SELECT c FROM Checklist c "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

쿼리를 따로 작성한 코드에 대해서는 테스트를 작성해 보아도 좋을 것 같습니다~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

작성 완료!

@@ -173,13 +174,13 @@ public SelectedChecklistResponse readChecklistById(long id) {

List<SelectedOptionResponse> options = readOptionsByChecklistId(id);

List<SelectedCategoryQuestionsResponse> selectedCategoryQuestionsRespons =
List<SelectedCategoryQuestionsResponse> selectedCategoryQuestionsResponse =
readCategoryQuestionsByChecklistId(id);

int checklistScore = ChecklistScore.calculateTotalScore(checklist.getQuestions());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChecklistScore를 호출하기 위해 체크리스트의 질문들을 꺼내서 넣는 게 어색하게 느껴져요!
checklist 내부에서 checklistScore를 갖고 있고 결과값을 넘기는 함수를 구현하는 게 어떨까요?
고려만 해 주세요 ㅎㅎ

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 부분을 고민해봤는데 저희가 oneToMany를 제거하면 해당로직도 작동하지 않게 되어서,
아예 checklistQuestionRepository에서 질문들을 조회하는 방식으로 구현해야할 것 같습니다!

다만 방 체크리스트 조회 해당 pr이 열려있어서 여기에서 반영하도록 하겠습니다!

@@ -6,6 +6,7 @@ public enum ExceptionCode {

// 전체
INVALID_PARAMETER(HttpStatus.BAD_REQUEST, "잘못된 인자입니다."),
SCORE_NOT_DESCENDING_SORTED(HttpStatus.BAD_REQUEST, "정렬되지 않은 점수입니다."),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

에러코드 컨벤션에 맞게 수정해 보는 건 어떨까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Score 분류를 따로 만들어서 분류했습니다!


import static org.assertj.core.api.Assertions.assertThat;

class ChecklistRankTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

꼼꼼하게 테스트해 주셨네요 👍

…97-checklist-comparison-improvement

# Conflicts:
#	backend/bang-ggood/src/main/java/com/bang_ggood/checklist/repository/ChecklistOptionRepository.java
#	backend/bang-ggood/src/main/java/com/bang_ggood/checklist/service/ChecklistService.java
#	backend/bang-ggood/src/test/java/com/bang_ggood/checklist/service/ChecklistServiceTest.java
#	backend/bang-ggood/src/test/java/com/bang_ggood/user/UserFixture.java
@JINU-CHANG JINU-CHANG merged commit 9bd7f5b into dev-be Aug 5, 2024
1 check passed
@JINU-CHANG JINU-CHANG deleted the feat/197-checklist-comparison-improvement branch August 5, 2024 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants