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] refactor: Club 매핑 테이블 엔티티 연관 관계 개선 #165

Merged
merged 2 commits into from
Jul 22, 2024

Conversation

jimi567
Copy link
Member

@jimi567 jimi567 commented Jul 22, 2024

이슈

개발 사항

  • Club 의 매핑 테이블 엔티티 연관 관계 개선
  • 검색 API 서비스 클래스 테스트 케이스 추가 및 픽스처 개선

리뷰 요청 사항 (없으면 삭제해 주세요)

전달 사항 (없으면 삭제해 주세요)

@jimi567 jimi567 linked an issue Jul 22, 2024 that may be closed by this pull request
Copy link

Unit Test Results

79 tests   79 ✔️  4s ⏱️
18 suites    0 💤
18 files      0

Results for commit 2af4ea1.

@jimi567 jimi567 requested review from ehtjsv2 and J-I-H-O July 22, 2024 08:45
@jimi567 jimi567 self-assigned this Jul 22, 2024
@jimi567 jimi567 added the 🖥 backend backend label Jul 22, 2024
Copy link
Contributor

@ehtjsv2 ehtjsv2 left a comment

Choose a reason for hiding this comment

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

위브 고생했습니다~~ 테스트도 나중에 작성하기 편하게 되어있네요~!

private List<String> collectOverviewPetImages(Club club) {
Map<Long, List<Pet>> groupPetsByMemberId = clubPetRepository.findAllByClubId(club.getId()).stream()
.map(ClubPet::getPet)
.collect(Collectors.groupingBy(pet -> pet.getMember().getId()));
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

@takoyakimchi takoyakimchi left a comment

Choose a reason for hiding this comment

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

연관관계 개선 고생 많았습니다!!!
이번에도 사소한 네이밍이랑 테스트 코드 위주로 리뷰해봤어요.
저번 PR에도 리뷰 있으니까 참고해주세요~!!

중요한 부분은 아니라서 approve 하겠습니다!

Comment on lines 26 to 29
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "club_member_id", nullable = false)
private ClubMember clubMember;
@JoinColumn(name = "club_id", nullable = false)
private Club club;

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Comment on lines 51 to 55
ClubMember clubMember = ClubMember.builder()
.member(member)
.club(club)
.build();

Copy link
Contributor

Choose a reason for hiding this comment

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

clubMember는 member, club 순으로 생성하고
clubPet은 club, pet 순으로 생성하고 있네요.
빌더 패턴을 쓴다고 하더라도, 하나로 통일시키면 좋을 것 같아요!

"https://image.com");

protected Club saveNewClub() {
protected Club getSavedClub(Set<Gender> genders, Set<SizeType> sizes) {
Copy link
Contributor

@takoyakimchi takoyakimchi Jul 22, 2024

Choose a reason for hiding this comment

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

Suggested change
protected Club getSavedClub(Set<Gender> genders, Set<SizeType> sizes) {
protected Club createClub(Set<Gender> genders, Set<SizeType> sizes) {

메서드명은 get으로 되어 있지만 내부적으로는 생성도 하고 있네요.
create라는 이름은 어떨까요?


List<FindSearchingClubResponse> responses = clubQueryService.findSearching(request);

assertThat(responses.isEmpty()).isTrue();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assertThat(responses.isEmpty()).isTrue();
assertThat(responses).isEmpty();

Comment on lines +55 to +63
private List<String> collectOverviewPetImages(Club club) {
Map<Long, List<Pet>> groupPetsByMemberId = clubPetRepository.findAllByClubId(club.getId()).stream()
.map(ClubPet::getPet)
.collect(Collectors.groupingBy(pet -> pet.getMember().getId()));

return groupPetsByMemberId.values().stream()
.map(petList -> petList.get(0).getImageUrl().getValue())
.collect(toList());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private List<String> collectOverviewPetImages(Club club) {
Map<Long, List<Pet>> groupPetsByMemberId = clubPetRepository.findAllByClubId(club.getId()).stream()
.map(ClubPet::getPet)
.collect(Collectors.groupingBy(pet -> pet.getMember().getId()));
return groupPetsByMemberId.values().stream()
.map(petList -> petList.get(0).getImageUrl().getValue())
.collect(toList());
}
private List<String> findPetImageUrls(Club club) {
Map<Long, List<Pet>> groupPetsByMemberId = clubPetRepository.findAllByClubId(club.getId()).stream()
.map(ClubPet::getPet)
.collect(groupingBy(pet -> pet.getMember().getId()));
return groupPetsByMemberId.values().stream()
.map(petList -> petList.get(0).getImageUrl().getValue())
.toList();
}
  1. 메서드 이름이 더 직관적이면 좋겠어요. overview는 전체 펫의 요약이라는 느낌이 들어서요.
  2. 불변 리스트로 리턴하면 더 좋겠네요!

Copy link
Contributor

@J-I-H-O J-I-H-O left a comment

Choose a reason for hiding this comment

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

위브 고생 정말 많으셨어요!
밤새 작성한 코드 다시 엎기 쉽지 않았을텐데 수고하셨습니다!
참고로 동적 쿼리 생성 시 복잡한 JpaSpecification (Criteria) 보다는 QueryDSL이나 Jooq 와 같은 프레임워크가 권장된다고 합니다~
관련 내용 더 찾아보시면 개선할 부분이 생길 것 같아요!

@jimi567 jimi567 merged commit 7ad8054 into develop Jul 22, 2024
3 checks passed
@jimi567 jimi567 deleted the refactor/club-entity branch July 29, 2024 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

모임(멍개) 테이블 구조 개선
4 participants