Skip to content

Commit

Permalink
refactor: 다른 객체 수를 파악하는 의존성 필드 제거 (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
dong2ast authored Oct 26, 2023
1 parent 5449c8b commit 5121dd9
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 47 deletions.
11 changes: 0 additions & 11 deletions src/main/java/org/sophy/sophy/domain/AuthorProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ public class AuthorProperty {
@OneToMany(mappedBy = "authorProperty", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
private List<Booktalk> myBookTalkList;

private Integer myBookTalkSize;

public void plusMyBookTalkSize() {
this.myBookTalkSize += 1;
}

public void minusMyBookTalkSize() { // 북토크가 완료 되었을 때 (개최한 북토크 -> 참여한 북토크로 변하는지에 따라 나뉠듯)
this.myBookTalkSize -= 1;
}

@OneToMany(mappedBy = "authorProperty", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
private List<Book> myBookList;

Expand All @@ -40,7 +30,6 @@ public void deleteBooktalk(Booktalk booktalk) {

public static AuthorProperty toBuild() {
return AuthorProperty.builder()
.myBookTalkSize(0)
.myBookList(new ArrayList<>())
.myBookTalkList(new ArrayList<>())
.build();
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/org/sophy/sophy/domain/Booktalk.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ public class Booktalk extends AuditingEntity {
@Column(nullable = false)
private LocalDateTime endDate;

private Integer participantNum;

@Column(nullable = false)
private Integer maximum;

Expand Down Expand Up @@ -107,10 +105,6 @@ public class Booktalk extends AuditingEntity {

private final Boolean deleted = Boolean.FALSE;

public void plusParticipant() {
this.participantNum += 1;
}

public void setBooktalkStatus(BooktalkStatus booktalkStatus) {
this.booktalkStatus = booktalkStatus;
}
Expand All @@ -136,7 +130,6 @@ public void setAuthor(Member member) {
this.member = member;
this.authorProperty = member.getAuthorProperty();
member.getAuthorProperty().getMyBookTalkList().add(this);
member.getAuthorProperty().plusMyBookTalkSize();
}

@Builder
Expand All @@ -152,7 +145,6 @@ public Booktalk(Place place, String title, String booktalkImageUrl, Book book, M
this.bookCategory = bookCategory;
this.startDate = startDate;
this.endDate = endDate;
this.participantNum = 0;
this.maximum = maximum;
this.participationFee = participationFee;
this.preliminaryInfo = preliminaryInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,5 @@ public static CompletedBooktalk toBuild(Booktalk booktalk) {
public void setMember(Member member) {
this.member = member;
member.getCompletedBookTalkList().add(this);
member.plusCompletedBooktalk();
}
}
18 changes: 0 additions & 18 deletions src/main/java/org/sophy/sophy/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,9 @@ public class Member extends AuditingTimeEntity {
@OneToMany(mappedBy = "member")
private List<MemberBooktalk> userBookTalkList; // -> 참여 예정 북토크 수

private Integer userBookTalkSize;

@OneToMany(mappedBy = "member")
private List<CompletedBooktalk> completedBookTalkList; //이거 길이로 북토크 수 보여줄 수 있지 않을까? -> 참여 완료 북토크 수

private Integer completedBookTalkSize;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "author_property_id")
private AuthorProperty authorProperty; //(개설한 북토크 리스트 + 나의 책 리스트 + 공간 매칭 중 북토크 수 + 청중 모집 중 북토크 수)
Expand All @@ -96,21 +92,7 @@ public Member(String name, String email, String password, String phoneNum,
this.authority = authority;
this.socialId = socialId;
this.userBookTalkList = new ArrayList<>();
this.userBookTalkSize = 0;
this.completedBookTalkList = new ArrayList<>();
this.completedBookTalkSize = 0;
}

public void plusUserBooktalk() {
this.userBookTalkSize += 1;
}

public void minusUserBooktalk() {
this.userBookTalkSize -= 1;
}

public void plusCompletedBooktalk() {
this.completedBookTalkSize += 1;
}

public void setAuthorProperty(AuthorProperty authorProperty) {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/sophy/sophy/domain/MemberBooktalk.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ public void setMember(Member member) {
if (!member.getUserBookTalkList().contains(this)) {
// 시작날짜로 순으로 정렬해서 추가
member.getUserBookTalkList().add(this);
member.plusUserBooktalk();
}
}

public void setBooktalk(Booktalk booktalk) {
this.booktalk = booktalk;
if (!booktalk.getParticipantList().contains(this)) {
booktalk.getParticipantList().add(this);
booktalk.plusParticipant();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public interface BooktalkQueryRepository extends JpaRepository<Booktalk, Long> {

@Query("select new org.sophy.sophy.domain.dto.booktalk.response.BooktalkResponseDto("
+ " b.id, b.preliminaryInfo, b.title, m.name, b.startDate, b.endDate, p.name, b.participantNum, b.maximum, b.booktalkImageUrl, b.booktalkStatus)"
+ " b.id, b.preliminaryInfo, b.title, m.name, b.startDate, b.endDate, p.name, b.participantList.size, b.maximum, b.booktalkImageUrl, b.booktalkStatus)"
+ " from Booktalk b"
+ " join b.member m"
+ " join b.place p"
Expand Down Expand Up @@ -47,7 +47,7 @@ List<Booktalk> findByBooktalkStatuses(
@Param("booktalkStatuses") List<BooktalkStatus> booktalkStatuses);

@Query("select new org.sophy.sophy.domain.dto.mypage.MyPageBooktalkDto("
+ " b.id, b.booktalkImageUrl, b.title, m.name, b.startDate, b.endDate, p.name, b.participantNum, b.maximum, b.booktalkStatus)"
+ " b.id, b.booktalkImageUrl, b.title, m.name, b.startDate, b.endDate, p.name, b.participantList.size, b.maximum, b.booktalkStatus)"
+ " from Booktalk b"
+ " join b.member m"
+ " join b.place p"
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/sophy/sophy/service/BooktalkService.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void postBooktalkParticipation(
ErrorStatus.BOOKTALK_RECRUITING_CLOSED_EXCEPTION.getMessage());
}
//북토크 현재 인원이 최대인원을 넘지 않았는지 체크하는 메서드
if (booktalk.getMaximum() <= booktalk.getParticipantNum()) {
if (booktalk.getMaximum() <= booktalk.getParticipantList().size()) {
throw new OverMaxParticipationException(ErrorStatus.OVER_MAX_PARTICIPATION_EXCEPTION,
ErrorStatus.OVER_MAX_PARTICIPATION_EXCEPTION.getMessage());
}
Expand All @@ -126,7 +126,7 @@ public void postBooktalkParticipation(
// 복합키?
memberBooktalkRepository.save(
booktalkParticipationRequestDto.toMemberBooktalk(booktalk, member));
if (booktalk.getMaximum().equals(booktalk.getParticipantNum())) { //인원이 다 찬 경우 마감
if (booktalk.getMaximum().equals(booktalk.getParticipantList().size())) { //인원이 다 찬 경우 마감
booktalk.setBooktalkStatus(BooktalkStatus.RECRUITING_CLOSED);
}
}
Expand Down Expand Up @@ -171,11 +171,9 @@ public CompletedBooktalk changeBooktalkToComplete(Booktalk booktalk) {
for (MemberBooktalk memberBooktalk : booktalk.getParticipantList()) { //참가 인원들 소피스토리 세팅
Member member = memberBooktalk.getMember();
completedBooktalkSetting(booktalk, member);
member.minusUserBooktalk(); //예정된 북토크 수 감소
}
Member member = booktalk.getMember(); //작가 소피스토리 세팅
CompletedBooktalk completedBooktalk = completedBooktalkSetting(booktalk, member);
member.getAuthorProperty().minusMyBookTalkSize(); //개최한 북토크 수 감소
booktalkRepository.delete(booktalk);
return completedBooktalk;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/sophy/sophy/service/HomeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class HomeService {

public HomeResponseDto getHome(String email) {
Member member = memberRepository.getMemberByEmail(email);
Integer booktalkCount = member.getUserBookTalkSize();
Integer booktalkCount = member.getUserBookTalkList().size();
List<BooktalkDeadlineUpcomingDto> booktalkDeadlineUpcoming = booktalkService.getBooktalkDeadlineUpcoming();

if (member.getAuthority().equals(Authority.AUTHOR)) { //작가냐 아니냐에 따라 홈 화면 분리
Expand Down

0 comments on commit 5121dd9

Please sign in to comment.