-
Notifications
You must be signed in to change notification settings - Fork 3
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] feat: Club 페이징 적용 및 batch size 설정 #622
base: develop
Are you sure you want to change the base?
Changes from all commits
6abbe66
8f5605e
3f1fa1c
d71cb20
29edf1e
c6b582a
171e2d2
b659fff
4675df1
925df3b
b215f8f
8f3b1c6
c7eb13d
eb1c84a
c28300d
9c108e8
d3748e5
f6f2d0a
6ef57a3
446c230
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,8 @@ | |
import com.happy.friendogly.club.dto.request.SaveClubMemberRequest; | ||
import com.happy.friendogly.club.dto.request.SaveClubRequest; | ||
import com.happy.friendogly.club.dto.request.UpdateClubRequest; | ||
import com.happy.friendogly.club.dto.response.FindClubByFilterResponse; | ||
import com.happy.friendogly.club.dto.response.FindClubOwningResponse; | ||
import com.happy.friendogly.club.dto.response.FindClubPageByFilterResponse; | ||
import com.happy.friendogly.club.dto.response.FindClubParticipatingResponse; | ||
import com.happy.friendogly.club.dto.response.FindClubResponse; | ||
import com.happy.friendogly.club.dto.response.SaveClubMemberResponse; | ||
|
@@ -49,7 +49,7 @@ public ApiResponse<FindClubResponse> findById(@Auth Long memberId, @PathVariable | |
} | ||
|
||
@GetMapping("/searching") | ||
public ApiResponse<List<FindClubByFilterResponse>> findByFilter( | ||
public ApiResponse<FindClubPageByFilterResponse> findByFilter( | ||
@Auth Long memberId, | ||
@Valid @ModelAttribute FindClubByFilterRequest request | ||
) { | ||
Comment on lines
51
to
55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이전 버전 앱 사용자는 명세가 바뀌면서 예외가 터질 수도 있을 것 같아요. |
||
|
@@ -105,5 +105,4 @@ public ResponseEntity<ApiResponse<UpdateClubResponse>> update( | |
UpdateClubResponse response = clubCommandService.update(clubId, memberId, request); | ||
return ResponseEntity.ok(ApiResponse.ofSuccess(response)); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,7 @@ | |
import com.happy.friendogly.pet.domain.Pet; | ||
import com.happy.friendogly.pet.domain.SizeType; | ||
import jakarta.persistence.CascadeType; | ||
import jakarta.persistence.CollectionTable; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.ElementCollection; | ||
import jakarta.persistence.Embedded; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
|
@@ -19,15 +17,12 @@ | |
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.NamedAttributeNode; | ||
import jakarta.persistence.NamedEntityGraph; | ||
import jakarta.persistence.OneToMany; | ||
import jakarta.persistence.OneToOne; | ||
import jakarta.persistence.OrderBy; | ||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import lombok.AccessLevel; | ||
|
@@ -36,15 +31,6 @@ | |
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NamedEntityGraph( | ||
name = "graph.Club", | ||
attributeNodes = { | ||
@NamedAttributeNode("clubMembers"), | ||
@NamedAttributeNode("clubPets"), | ||
@NamedAttributeNode("allowedSizes"), | ||
@NamedAttributeNode("allowedGenders"), | ||
} | ||
) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
public class Club { | ||
|
@@ -62,18 +48,6 @@ public class Club { | |
@Embedded | ||
private MemberCapacity memberCapacity; | ||
|
||
@ElementCollection | ||
@Enumerated(EnumType.STRING) | ||
@CollectionTable(name = "club_gender", joinColumns = @JoinColumn(name = "club_id")) | ||
@Column(name = "allowed_gender", nullable = false) | ||
private Set<Gender> allowedGenders; | ||
|
||
@ElementCollection | ||
@Enumerated(EnumType.STRING) | ||
@CollectionTable(name = "club_size", joinColumns = @JoinColumn(name = "club_id")) | ||
@Column(name = "allowed_size", nullable = false) | ||
private Set<SizeType> allowedSizes; | ||
|
||
@Embedded | ||
private Address address; | ||
|
||
|
@@ -87,13 +61,18 @@ public class Club { | |
@Column(name = "status", nullable = false) | ||
private Status status; | ||
|
||
@OneToMany(mappedBy = "clubGenderId.club", orphanRemoval = true, cascade = CascadeType.ALL) | ||
private List<ClubGender> allowedGenders = new ArrayList<>(); | ||
|
||
@OneToMany(mappedBy = "clubSizeId.club", orphanRemoval = true, cascade = CascadeType.ALL) | ||
private List<ClubSize> allowedSizes = new ArrayList<>(); | ||
|
||
@OneToMany(mappedBy = "clubMemberId.club", orphanRemoval = true, cascade = CascadeType.ALL) | ||
@OrderBy("createdAt") | ||
private Set<ClubMember> clubMembers = new HashSet<>(); | ||
private List<ClubMember> clubMembers = new ArrayList<>(); | ||
|
||
@OneToMany(mappedBy = "clubPetId.club", orphanRemoval = true, cascade = CascadeType.ALL) | ||
@OrderBy | ||
private Set<ClubPet> clubPets = new HashSet<>(); | ||
private List<ClubPet> clubPets = new ArrayList<>(); | ||
|
||
@OneToOne(fetch = FetchType.LAZY, orphanRemoval = true, cascade = CascadeType.ALL) | ||
private ChatRoom chatRoom; | ||
|
@@ -117,8 +96,8 @@ private Club( | |
this.content = new Content(content); | ||
this.address = new Address(province, city, village); | ||
this.memberCapacity = new MemberCapacity(memberCapacity); | ||
this.allowedGenders = allowedGenders; | ||
this.allowedSizes = allowedSizes; | ||
this.allowedGenders = allowedGenders.stream().map(gender -> new ClubGender(this, gender)).toList(); | ||
this.allowedSizes = allowedSizes.stream().map(sizeType -> new ClubSize(this, sizeType)).toList(); | ||
Comment on lines
+99
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 stream까지 필요없을 것 같아요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. map때문에 stream한 것 같은데 다른 방법이 있나요?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앗 맞네요 ㅋㅋ |
||
this.imageUrl = imageUrl; | ||
this.status = status; | ||
this.createdAt = createdAt; | ||
|
@@ -209,15 +188,19 @@ private void validateParticipatePet(Pet pet) { | |
} | ||
|
||
private boolean canJoinWith(Pet pet) { | ||
return allowedGenders.contains(pet.getGender()) && allowedSizes.contains(pet.getSizeType()); | ||
boolean isGenderMatch = allowedGenders.stream() | ||
.anyMatch(clubGender -> clubGender.isSameGenderWith(pet.getGender())); | ||
boolean isSizeMatch = allowedSizes.stream() | ||
.anyMatch(clubSize -> clubSize.isSameSizeWith(pet.getSizeType())); | ||
|
||
return isGenderMatch && isSizeMatch; | ||
} | ||
|
||
public boolean isJoinable(Member member, List<Pet> pets) { | ||
boolean hasJoinablePet = pets.stream() | ||
.anyMatch(this::canJoinWith); | ||
boolean isNotFull = !this.memberCapacity.isCapacityReached(countClubMember()); | ||
|
||
return hasJoinablePet && isNotFull && !isAlreadyJoined(member) && isOpen(); | ||
return hasJoinablePet && !isAlreadyJoined(member) && isOpen(); | ||
Comment on lines
-218
to
+203
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isOpen에 isNotFull이 포함이군요 ~!! |
||
} | ||
|
||
public void removeClubMember(Member member) { | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,40 @@ | ||||||||||||||
package com.happy.friendogly.club.domain; | ||||||||||||||
|
||||||||||||||
import com.happy.friendogly.exception.FriendoglyException; | ||||||||||||||
import com.happy.friendogly.pet.domain.Gender; | ||||||||||||||
import jakarta.persistence.EmbeddedId; | ||||||||||||||
import jakarta.persistence.Entity; | ||||||||||||||
import lombok.AccessLevel; | ||||||||||||||
import lombok.Getter; | ||||||||||||||
import lombok.NoArgsConstructor; | ||||||||||||||
|
||||||||||||||
@Entity | ||||||||||||||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||||||||||||||
@Getter | ||||||||||||||
public class ClubGender { | ||||||||||||||
|
||||||||||||||
@EmbeddedId | ||||||||||||||
private ClubGenderId clubGenderId; | ||||||||||||||
|
||||||||||||||
public ClubGender(Club club, Gender gender) { | ||||||||||||||
validateClub(club); | ||||||||||||||
validateGender(gender); | ||||||||||||||
this.clubGenderId = new ClubGenderId(club, gender); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
private void validateClub(Club club) { | ||||||||||||||
if (club == null) { | ||||||||||||||
throw new FriendoglyException("모임 정보는 필수입니다."); | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
private void validateGender(Gender gender) { | ||||||||||||||
if (gender == null) { | ||||||||||||||
throw new FriendoglyException("모임에 참여하는 반려견의 성별 정보는 필수입니다."); | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
public boolean isSameGenderWith(Gender gender) { | ||||||||||||||
return this.getClubGenderId().getAllowedGender() == gender; | ||||||||||||||
} | ||||||||||||||
Comment on lines
+37
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
이름 제안해봅니당 |
||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.happy.friendogly.club.domain; | ||
|
||
import com.happy.friendogly.pet.domain.Gender; | ||
import jakarta.persistence.Embeddable; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import java.io.Serializable; | ||
import lombok.AccessLevel; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Embeddable | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
@EqualsAndHashCode | ||
public class ClubGenderId implements Serializable { | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "club_id", nullable = false) | ||
private Club club; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private Gender allowedGender; | ||
|
||
public ClubGenderId(Club club, Gender allowedGender) { | ||
this.club = club; | ||
this.allowedGender = allowedGender; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,40 @@ | ||||||||||||||
package com.happy.friendogly.club.domain; | ||||||||||||||
|
||||||||||||||
import com.happy.friendogly.exception.FriendoglyException; | ||||||||||||||
import com.happy.friendogly.pet.domain.SizeType; | ||||||||||||||
import jakarta.persistence.EmbeddedId; | ||||||||||||||
import jakarta.persistence.Entity; | ||||||||||||||
import lombok.AccessLevel; | ||||||||||||||
import lombok.Getter; | ||||||||||||||
import lombok.NoArgsConstructor; | ||||||||||||||
|
||||||||||||||
@Entity | ||||||||||||||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||||||||||||||
@Getter | ||||||||||||||
public class ClubSize { | ||||||||||||||
|
||||||||||||||
@EmbeddedId | ||||||||||||||
private ClubSizeId clubSizeId; | ||||||||||||||
|
||||||||||||||
public ClubSize(Club club, SizeType sizeType) { | ||||||||||||||
validateClub(club); | ||||||||||||||
validateSizeType(sizeType); | ||||||||||||||
this.clubSizeId = new ClubSizeId(club, sizeType); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
private void validateClub(Club club) { | ||||||||||||||
if (club == null) { | ||||||||||||||
throw new FriendoglyException("모임 정보는 필수입니다."); | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
private void validateSizeType(SizeType sizeType) { | ||||||||||||||
if (sizeType == null) { | ||||||||||||||
throw new FriendoglyException("모임에 참여하는 반려견의 크기 정보는 필수입니다."); | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
public boolean isSameSizeWith(SizeType sizeType) { | ||||||||||||||
return this.getClubSizeId().getAllowedSize() == sizeType; | ||||||||||||||
} | ||||||||||||||
Comment on lines
+37
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
제안 |
||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.happy.friendogly.club.domain; | ||
|
||
import com.happy.friendogly.pet.domain.SizeType; | ||
import jakarta.persistence.Embeddable; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import java.io.Serializable; | ||
import lombok.AccessLevel; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Embeddable | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
@EqualsAndHashCode | ||
public class ClubSizeId implements Serializable { | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "club_id", nullable = false) | ||
private Club club; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private SizeType allowedSize; | ||
|
||
public ClubSizeId(Club club, SizeType allowedSize) { | ||
this.club = club; | ||
this.allowedSize = allowedSize; | ||
} | ||
} |
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.
이거 List -> Set으로 바꾸는거죠? 한 줄로 될 것 같아요!