Skip to content

Commit

Permalink
Merge branch 'main' into feat/#38-booktalk-participant
Browse files Browse the repository at this point in the history
  • Loading branch information
dong2ast authored Jul 12, 2023
2 parents 05e916a + 8b8e772 commit aef425e
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 29 deletions.
7 changes: 5 additions & 2 deletions src/main/java/org/sophy/sophy/InitDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void dbInit() {
.isOperator(false)
.authority(Authority.ROLE_USER)
.build();
citizen.setBookCount(8);
citizen.setBookTalkCount(5);
em.persist(citizen);

Expand All @@ -49,6 +50,7 @@ public void dbInit() {
.matchingBookTalkCount(3)
.recruitBookTalkCount(3)
.build();

em.persist(memauthor);

Member author = Member.builder()
Expand All @@ -63,6 +65,7 @@ public void dbInit() {
.build();
author.setAuthor(memauthor);
author.setBookTalkCount(3);
author.setBookCount(3);
em.persist(author);

Place place = Place.builder()
Expand All @@ -84,7 +87,7 @@ public void dbInit() {
.place(place2)
.title("테스트 타이틀")
.booktalkImageUrl("dwqE@EWQDQFQEWQ")
.author(author)
.member(author)
.bookCategory(BookCategory.HUMANITIES)
.startDate(LocalDateTime.of(2023, 7, 13, 13, 0))
.endDate(LocalDateTime.of(2023, 7, 13, 15, 0))
Expand All @@ -100,7 +103,7 @@ public void dbInit() {
.place(place)
.title("테스트 타이틀2")
.booktalkImageUrl("dwqE@EWQDQFQEWQ")
.author(author)
.member(author)
.bookCategory(BookCategory.HEALTH_COOKING)
.startDate(LocalDateTime.of(2023, 7, 18, 16, 0))
.endDate(LocalDateTime.of(2023, 7, 18, 18, 0))
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/sophy/sophy/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
//CSRF 설정 Disable
http.csrf().disable()

.cors(cors -> cors.disable())
// .and()
.cors().configurationSource(corsConfigurationSource())
.and()

//exception handling 할 때 우리가 만든 클래스를 추가
.exceptionHandling()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Booktalk toBooktalk(Place place, Member member) {
.preliminaryInfo(preliminaryInfo)
.description(description)
.booktalkStatus(BooktalkStatus.APPLYING)
.author(member)
.member(member)
.place(place)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static BooktalkDetailResponseDto of(Booktalk booktalk) {
return new BooktalkDetailResponseDto(
booktalk.getBooktalkImageUrl(),
booktalk.getTitle(),
booktalk.getAuthor().getName(),
booktalk.getMember().getName(),
booktalk.getBookCategory(),
"책이름", //TODO 추후 연결
booktalk.getStartDate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static BooktalkResponseDto of(Booktalk booktalk) {
booktalk.getId(),
booktalk.getPreliminaryInfo().ordinal(),
booktalk.getTitle(),
booktalk.getAuthor().getName(),
booktalk.getMember().getName(),
booktalk.getStartDate(),
booktalk.getEndDate(),
booktalk.getPlace().getName(),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/sophy/sophy/domain/AuthorProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class AuthorProperty {
@Column(name = "author_property_id")
private Long id;

@OneToMany
@OneToMany(mappedBy = "authorProperty", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
private List<Booktalk> myBookTalkList;
//private List<Book> myBookList
private Integer matchingBookTalkCount;
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/org/sophy/sophy/domain/Booktalk.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@ public class Booktalk extends AuditingTimeEntity {
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn
@JoinColumn(name = "place_id")
private Place place;

@Column(nullable = false)
private String title;

private String booktalkImageUrl;

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

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.CONSTRAINT))
private Member author;
@JoinColumn(name = "author_property_id")
private AuthorProperty authorProperty;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
Expand Down Expand Up @@ -76,21 +80,23 @@ public void setPlace(Place place) {
}

public void setAuthor(Member member) {
if (this.author != null) {
this.author.getAuthorProperty().getMyBookTalkList().remove(this);
if (this.member != null) {
this.member.getAuthorProperty().getMyBookTalkList().remove(this);
}
this.author = member;
this.member = member;
this.authorProperty = member.getAuthorProperty();
authorProperty.getMyBookTalkList().add(this);
if (!member.getAuthorProperty().getMyBookTalkList().contains(this)) {
member.getAuthorProperty().getMyBookTalkList().add(this);
}
}

@Builder
public Booktalk(Place place, String title, String booktalkImageUrl, Member author, BookCategory bookCategory, LocalDateTime startDate, LocalDateTime endDate, Integer maximum, Integer participationFee, PreliminaryInfo preliminaryInfo, String description, BooktalkStatus booktalkStatus) {
public Booktalk(Place place, String title, String booktalkImageUrl, Member member, BookCategory bookCategory, LocalDateTime startDate, LocalDateTime endDate, Integer maximum, Integer participationFee, PreliminaryInfo preliminaryInfo, String description, BooktalkStatus booktalkStatus) {
setPlace(place);
this.title = title;
this.booktalkImageUrl = booktalkImageUrl;
setAuthor(author);
setAuthor(member);
this.bookCategory = bookCategory;
this.startDate = startDate;
this.endDate = endDate;
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/org/sophy/sophy/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,13 @@ public class Member extends AuditingTimeEntity {
@Enumerated(EnumType.STRING)
private Authority authority;

// private Integer bookCount; 나의 서재 기능 삭제
private Integer bookTalkCount;

@OneToOne
private Booktalk imminentBooktalk;

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

@OneToOne
@JoinColumn(name = "author_property_id")
private AuthorProperty authorProperty; //(개설한 북토크 리스트 + 나의 책 리스트 + 공간 매칭 중 북토크 수 + 청중 모집 중 북토크 수)

@Builder
Expand All @@ -81,15 +78,14 @@ public void setAuthor(AuthorProperty authorProperty) {
this.authorProperty = authorProperty;
}

public void setBookCount(int count) {
this.bookCount = count;
}

public void setBookTalkCount(int count) {
this.bookTalkCount = count;
}

public void changeImminentBooktalk(Booktalk booktalk) {
this.imminentBooktalk = booktalk;
}

public void setAdditionalInfo(MemberAdditionalInfoDto memberAdditionalInfoDto) {
this.gender = memberAdditionalInfoDto.getGender();
this.birth = memberAdditionalInfoDto.getBirth();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/sophy/sophy/domain/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
public class Place extends AuditingTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "place_id")
private Long id;

private City city;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BooktalkRepository extends JpaRepository<Booktalk, Long> {
List<Booktalk> findAllByAuthorId(Long authorId); //Booktalk의 작가
}
2 changes: 1 addition & 1 deletion src/main/java/org/sophy/sophy/service/BooktalkService.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public BooktalkDeleteResponseDto deleteBooktalk(Long booktalkId) {
//TODO soft delete?
//공간이 거절 됐거나 공간 매칭중일 때만 삭제가능
booktalk.getPlace().deleteBooktalk(booktalk);
booktalk.getAuthor().getAuthorProperty().deleteBooktalk(booktalk);
booktalk.getMember().getAuthorProperty().deleteBooktalk(booktalk);
booktalkRepository.deleteById(booktalkId);
return BooktalkDeleteResponseDto.of(booktalkId);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/sophy/sophy/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public List<MyPageBooktalkDto> getBooktalksByMemberId(Long memberId) { //예정
.booktalkId(booktalk.getId())
.booktalkImageUrl(booktalk.getBooktalkImageUrl())
.title(booktalk.getTitle())
.author(booktalk.getAuthor().getName())
.author(booktalk.getMember().getName())
.startDate(booktalk.getStartDate())
.endDate(booktalk.getEndDate())
.place(booktalk.getPlace().getName())
Expand All @@ -105,7 +105,7 @@ public List<MyPageBooktalkDto> getAuthorBooktalksByMemberId(Long memberId) { //
.booktalkId(booktalk.getId())
.booktalkImageUrl(booktalk.getBooktalkImageUrl())
.title(booktalk.getTitle())
.author(booktalk.getAuthor().getName())
.author(booktalk.getMember().getName())
.startDate(booktalk.getStartDate())
.endDate(booktalk.getEndDate())
.place(booktalk.getPlace().getName())
Expand Down

0 comments on commit aef425e

Please sign in to comment.