Conversation
Summary of ChangesHello @jiminnimij, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request implements a significant refactoring of how exhibition viewing and reviewing statuses are managed. By introducing a new 'View' domain, the system now clearly separates the concept of a 'viewed' exhibition from a 'scrapped' one. This change simplifies the 'Scrap' entity, making it more focused, and allows for dynamic determination of 'viewed' and 'reviewed' statuses based on the new 'View' entity and existing review posts. The refactoring enhances modularity, improves data integrity, and provides a more robust foundation for future feature development. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
이번 PR은 '관람(view)' 기능을 '스크랩(scrap)' 기능에서 분리하는 리팩토링을 중심으로 진행되었습니다. 전반적으로 기능 분리가 잘 이루어졌으며, 이에 따라 관련 컨트롤러, 서비스, 리포지토리, DTO가 깔끔하게 정리되었습니다. 몇 가지 코드 개선점을 제안 드립니다. ViewErrorCode의 오타 수정, PostService의 분기문 개선, ViewService의 중복 코드 제거, 그리고 테스트 코드의 오류 수정이 필요해 보입니다. 자세한 내용은 각 파일의 리뷰 코멘트를 확인해주세요.
| if (post.getPostType() == PostType.REVIEW) { | ||
| scrapService.markReviewed(memberId, post.getExhibition().getExhibitionId()); // TODO: N+1 문제 해결 | ||
| post.getExhibition().decreaseReviewCount(); | ||
| viewService.removeView(memberId, post.getExhibition().getExhibitionId()); | ||
| } | ||
| if (post.getPostType() == PostType.CHEER) { | ||
| post.getExhibition().decreaseCheerCount(); | ||
| } | ||
| if (post.getPostType() == PostType.QUESTION) { | ||
| post.getExhibition().decreaseQuestionCount(); | ||
| } |
There was a problem hiding this comment.
PostType enum 값에 따라 분기 처리를 위해 여러 if 문을 사용하고 있습니다. 이 경우 switch 문을 사용하면 코드가 더 명확해지고 가독성이 향상됩니다.
switch (post.getPostType()) {
case REVIEW -> {
post.getExhibition().decreaseReviewCount();
viewService.removeView(memberId, post.getExhibition().getExhibitionId());
}
case CHEER -> post.getExhibition().decreaseCheerCount();
case QUESTION -> post.getExhibition().decreaseQuestionCount();
}| @Getter | ||
| @AllArgsConstructor | ||
| public enum ViewErrorCode implements BaseErrorCode { | ||
| ALREADE_EXIST_VIEW(HttpStatus.CONFLICT, "VIEW_409_1", "이미 관람한 내역입니다."), |
| public void addView(Long memberId, Long exhibitionId) { | ||
| Member member = memberValidator.validateMember(memberId); | ||
| Exhibition exhibition = exhibitionValidator.validateExhibition(exhibitionId); | ||
|
|
||
| if (viewRepository.existsByMemberAndExhibition(member, exhibition)) { | ||
| throw new BaseErrorException(ViewErrorCode.ALREADE_EXIST_VIEW); | ||
| } | ||
|
|
||
| View view = View.builder() | ||
| .member(member) | ||
| .exhibition(exhibition) | ||
| .build(); | ||
|
|
||
| viewRepository.save(view); | ||
| } | ||
|
|
||
| @Transactional | ||
| public void addViewByReview(Member member, Exhibition exhibition) { | ||
| if (viewRepository.existsByMemberAndExhibition(member, exhibition)) { | ||
| throw new BaseErrorException(ViewErrorCode.ALREADE_EXIST_VIEW); | ||
| } | ||
|
|
||
| View view = View.builder() | ||
| .member(member) | ||
| .exhibition(exhibition) | ||
| .build(); | ||
|
|
||
| viewRepository.save(view); | ||
| } |
There was a problem hiding this comment.
addView와 addViewByReview 메서드에 중복된 코드가 많습니다. 관람 내역이 이미 존재하는지 확인하고, 없으면 생성하여 저장하는 로직이 동일합니다. 이 부분을 별도의 private 메서드로 추출하여 중복을 제거하는 것이 좋습니다.
@Transactional
public void addView(Long memberId, Long exhibitionId) {
Member member = memberValidator.validateMember(memberId);
Exhibition exhibition = exhibitionValidator.validateExhibition(exhibitionId);
createViewIfNotExists(member, exhibition);
}
@Transactional
public void addViewByReview(Member member, Exhibition exhibition) {
createViewIfNotExists(member, exhibition);
}
private void createViewIfNotExists(Member member, Exhibition exhibition) {
if (viewRepository.existsByMemberAndExhibition(member, exhibition)) {
throw new BaseErrorException(ViewErrorCode.ALREADE_EXIST_VIEW);
}
View view = View.builder()
.member(member)
.exhibition(exhibition)
.build();
viewRepository.save(view);
}| ScrapListItemDto dto1 = ScrapListItemDto.from(s1, true); | ||
| ScrapListItemDto dto2 = ScrapListItemDto.from(s2, true); |
There was a problem hiding this comment.
테스트 데이터 설정이 이후의 검증 코드와 일치하지 않습니다. dto1을 isViewed=true로 생성했지만, 59행의 assertThat(item0.isViewed()).isFalse() 검증으로 인해 테스트가 실패할 것입니다. 검증 코드에 맞게 테스트 데이터를 수정해야 합니다.
| ScrapListItemDto dto1 = ScrapListItemDto.from(s1, true); | |
| ScrapListItemDto dto2 = ScrapListItemDto.from(s2, true); | |
| ScrapListItemDto dto1 = ScrapListItemDto.from(s1, false); | |
| ScrapListItemDto dto2 = ScrapListItemDto.from(s2, true); |
#️⃣ 연관된 이슈
#️⃣ 작업 내용
#️⃣ 테스트 결과
#️⃣ 변경 사항 체크리스트
#️⃣ 스크린샷 (선택)
#️⃣ 리뷰 요구사항 (선택)
📎 참고 자료 (선택)