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

refactor : store review like count 추가 #100

Merged
merged 1 commit into from
Feb 26, 2024
Merged

Conversation

Qbeom0925
Copy link
Member

작업 내용

Review 엔티티의 addMark 및 removeMark 메서드 수정
restaurant가 null일 때 store의 등급 통계를 업데이트하도록 수정

작업 확인 방법

이 코드의 변경 사항은 테스트 케이스를 실행하여 확인할 수 있습니다. 리뷰에 대한 표시를 추가하고 제거하는 경우 해당 식당 또는 가게의 등급 통계가 올바르게 업데이트되는지 확인할 수 있습니다. 특히 restaurant가 null인 경우에도 store의 등급 통계가 올바르게 업데이트되는지 확인해야 합니다.

추가 정보 (선택 사항)

이 수정된 코드는 리뷰에 대한 표시(mark)를 추가하거나 제거할 때 등급 통계를 업데이트합니다. 만약 리뷰가 식당(restaurant)에 속한다면 해당 식당의 등급 통계를 업데이트하고, 그렇지 않은 경우에는 가게(store)의 등급 통계를 업데이트합니다.

@Qbeom0925 Qbeom0925 self-assigned this Feb 26, 2024
Copy link

sonarcloud bot commented Feb 26, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Comment on lines -110 to +123
this.restaurant.getGradeStatistics().addRecommendedCount();
if (this.restaurant == null) {
this.store.getGradeStatistics().addRecommendedCount();
} else {
this.restaurant.getGradeStatistics().addRecommendedCount();
}
}

public void removeMark(User user) {
this.reviewMarks.removeIf(mark -> mark.getUser().getIdx().equals(user.getIdx()));
this.restaurant.getGradeStatistics().removeRecommendedCount();
if (this.restaurant == null) {
this.store.getGradeStatistics().addRecommendedCount();
} else {
this.restaurant.getGradeStatistics().addRecommendedCount();
}
Copy link
Member Author

Choose a reason for hiding this comment

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

가장 고민이 되었던 부분 같습니다.

1안, api request에 store, restaurant flag 추가
2안, 다음과 같이 null 체크

null을 통해 flag를 가르는 방식은 편리할 수 있으나 해당 코드에 문제도 존재합니다. 여전히 NPE 문제가 발생 할 수 있으며 디버깅에 대해서 추가 작업이 필요합니다. 또한, Java8 부터 적용된 함수형 프로그래밍 방식과도 어울리지 않습니다!

2안을 선택했습니다. 이유는 이미 공개가 된 api에서 required request 추가 되는 것은 리소스가 부가적(프론트)으로 들기에 2안을 선택했습니다. 코드의 길이는 2안이 더욱 간단하게 나올 것으로 예상되었습니다.
또한, 기획상으로 리뷰는 store와 restaurant를 동시에 가질 수 없습니다.

Copy link
Member

Choose a reason for hiding this comment

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

2안 채택 이유 확인했습니다!

기획적으로도, 추가 개발 리소스 측면에서도 2안이 더 적합한 거 같아요.

Copy link
Member

@dldmsql dldmsql left a comment

Choose a reason for hiding this comment

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

수고하셨습니다

@dldmsql dldmsql merged commit 093831c into develop Feb 26, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants