Skip to content

Commit

Permalink
add: 북토크 개설 및 참가신청 때 member와 작가 내부 데이터 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
dong2ast committed Jul 21, 2023
1 parent 4c68811 commit f6bd630
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/java/org/sophy/sophy/domain/AuthorProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ public void deleteBooktalk(Booktalk booktalk) {
public void setExpectedBookTalkCount(Integer count) {
this.expectedBookTalkCount = count;
}
public void increaseBooktalkCount(){ this.expectedBookTalkCount +=1; }
}
4 changes: 3 additions & 1 deletion src/main/java/org/sophy/sophy/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ public class Member extends AuditingTimeEntity {
private Integer waitingBookTalkCount; // 참여 예정 북토크
private Integer completeBookTalkCount; // 참여 완료 북토크 ( 북토크 complete 시킬 때 숫자 증가시키는거 필요함)

public void increaseWaitingBooktalkCount(){ this.waitingBookTalkCount +=1; }

@OneToMany(mappedBy = "member")
private List<MemberBooktalk> userBookTalkList;

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

@OneToOne
@JoinColumn(name = "author_property_id")
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/sophy/sophy/service/BooktalkService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public BooktalkCreateResponseDto createBooktalk(BooktalkRequestDto booktalkReque
throw new ForbiddenException(ErrorStatus.FORBIDDEN_USER_EXCEPTION, ErrorStatus.FORBIDDEN_USER_EXCEPTION.getMessage());
}
Booktalk booktalk = booktalkRequestDto.toBooktalk(place, member);
//작가 정보에 북토크 업데이트
member.getAuthorProperty().getMyBookTalkList().add(booktalk);
member.getAuthorProperty().increaseBooktalkCount();
return BooktalkCreateResponseDto.of(booktalkRepository.save(booktalk));
}

Expand Down Expand Up @@ -68,10 +71,15 @@ public BooktalkDetailResponseDto getBooktalkDetail(Long booktalkId) {
// 북토크 참여 신청
@Transactional
public void postBooktalkParticipation(BooktalkParticipationRequestDto booktalkParticipationRequestDto) {
//북토크 현재 인원이 최대인원을 넘지 않았는지 체크하는 메서드 필요할듯
Member member = memberRepository.getMemberById(booktalkParticipationRequestDto.getMemberId());
Booktalk booktalk = booktalkRepository.getBooktalkById(booktalkParticipationRequestDto.getBooktalkId());
// 복합키?
MemberBooktalk memberBooktalk = booktalkParticipationRequestDto.toMemberBooktalk(booktalk, member);
//연관 객체 변경 ( member 객체 북토크 수 표시하는 메서드 리팩터 필요 )
booktalk.getParticipantList().add(memberBooktalk);
member.getUserBookTalkList().add(memberBooktalk);
member.increaseWaitingBooktalkCount();
memberBooktalkRepository.save(memberBooktalk);
}

Expand Down

0 comments on commit f6bd630

Please sign in to comment.