Skip to content

Commit

Permalink
feat: 작가 마이페이지 조회시 나의 책 리스트도 반환하게 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
dong2ast committed Jul 13, 2023
1 parent 1e0283e commit 7e7376b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/sophy/sophy/InitDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void dbInit() {
.isOperator(false)
.authority(Authority.ROLE_USER)
.build();
author.setAuthor(memauthor);
author.setAuthorProperty(memauthor);
author.setCompleteBookTalkCounto(3);
author.setWaitingBookTalkCount(3);
em.persist(author);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/sophy/sophy/domain/Booktalk.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Booktalk extends AuditingTimeEntity {

private String booktalkImageUrl;

@OneToOne
@ManyToOne
@JoinColumn(name = "member_id")
private Member member; //작가 = 북토크당 1명

Expand Down Expand Up @@ -85,10 +85,10 @@ public void setAuthor(Member member) {
}
this.member = member;
this.authorProperty = member.getAuthorProperty();
authorProperty.getMyBookTalkList().add(this);
if (!member.getAuthorProperty().getMyBookTalkList().contains(this)) {
member.getAuthorProperty().getMyBookTalkList().add(this);
}
member.getAuthorProperty().getMyBookTalkList().add(this);
// if (!member.getAuthorProperty().getMyBookTalkList().contains(this)) {
// member.getAuthorProperty().getMyBookTalkList().add(this);
// }
}

@Builder
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/sophy/sophy/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Member(String name, String email, String password, String phoneNum, boole
this.userBookTalkList = new ArrayList<>();
}

public void setAuthor(AuthorProperty authorProperty) {
public void setAuthorProperty(AuthorProperty authorProperty) {
this.authorProperty = authorProperty;
}

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/sophy/sophy/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import lombok.RequiredArgsConstructor;
import org.sophy.sophy.controller.dto.request.MemberAdditionalInfoDto;
import org.sophy.sophy.domain.Book;
import org.sophy.sophy.domain.Booktalk;
import org.sophy.sophy.domain.Member;
import org.sophy.sophy.domain.MemberBooktalk;
import org.sophy.sophy.domain.dto.MyBookDto;
import org.sophy.sophy.domain.dto.MyPageBooktalkDto;
import org.sophy.sophy.domain.dto.MyPageDto;
import org.sophy.sophy.domain.dto.MyInfoDto;
Expand Down Expand Up @@ -34,6 +36,7 @@ public MyPageDto getMyPage(Long memberId) {
.waitingBookTalkCount(member.getWaitingBookTalkCount())
.completeBookTalkCount(member.getCompleteBookTalkCount())
.myPageBooktalkDtos(getBooktalksByMemberId(memberId))
.myBookDtos(getAuthorBooksByMemberId(memberId))
.build();
} else {
return MyPageDto.builder()
Expand Down Expand Up @@ -118,4 +121,19 @@ public List<MyPageBooktalkDto> getAuthorBooktalksByMemberId(Long memberId) { //
return booktalkResponseDtoList;
}

@Transactional
public List<MyBookDto> getAuthorBooksByMemberId(Long memberId) { //작가가 쓴 책 조회 메서드
List<Book> authorBookList = getMemberById(memberId).getAuthorProperty().getMyBookList();
List<MyBookDto> bookResponseDtoList = new ArrayList<>();
authorBookList.forEach(book -> {
bookResponseDtoList.add(MyBookDto.builder()
.title(book.getTitle())
.bookCategory(book.getBookCategory())
.booktalkOpenCount(book.getBooktalkOpenCount())
.isRegistration(book.getIsRegistration())
.build());
});
return bookResponseDtoList;
}

}

0 comments on commit 7e7376b

Please sign in to comment.