Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
onpyeong committed Jul 11, 2023
2 parents 75e1ef3 + 1ad0beb commit 3ba206e
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 37 deletions.
52 changes: 50 additions & 2 deletions src/main/java/org/sophy/sophy/InitDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import javax.annotation.PostConstruct;
import javax.persistence.EntityManager;
import java.time.LocalDateTime;
import java.util.ArrayList;

@Component
@RequiredArgsConstructor
Expand Down Expand Up @@ -43,7 +45,8 @@ public void dbInit() {
citizen.setBookTalkCount(5);
em.persist(citizen);

Author memauthor = Author.builder()
AuthorProperty memauthor = AuthorProperty.builder()
.myBookTalkList(new ArrayList<>())
.matchingBookTalkCount(3)
.recruitBookTalkCount(3)
.build();
Expand All @@ -59,7 +62,7 @@ public void dbInit() {
.isOperator(false)
.authority(Authority.ROLE_USER)
.build();
author.serAuthor(memauthor);
author.setAuthor(memauthor);
author.setBookTalkCount(3);
author.setBookCount(3);
em.persist(author);
Expand All @@ -78,6 +81,51 @@ public void dbInit() {
.build();
em.persist(place);
em.persist(place2);

Booktalk booktalk = Booktalk.builder()
.place(place2)
.title("테스트 타이틀")
.booktalkImageUrl("dwqE@EWQDQFQEWQ")
.author(author)
.bookCategory(BookCategory.HUMANITIES)
.startDate(LocalDateTime.of(2023, 7, 13, 13, 0))
.endDate(LocalDateTime.of(2023, 7, 13, 15, 0))
.maximum(6)
.participationFee(1000)
.preliminaryInfo(PreliminaryInfo.PRE_READING)
.description("테스트입니당")
.booktalkStatus(BooktalkStatus.RECRUITING)
.build();
em.persist(booktalk);

Booktalk booktalk2 = Booktalk.builder()
.place(place)
.title("테스트 타이틀2")
.booktalkImageUrl("dwqE@EWQDQFQEWQ")
.author(author)
.bookCategory(BookCategory.HEALTH_COOKING)
.startDate(LocalDateTime.of(2023, 7, 18, 16, 0))
.endDate(LocalDateTime.of(2023, 7, 18, 18, 0))
.maximum(6)
.participationFee(10000)
.preliminaryInfo(PreliminaryInfo.PRE_READING)
.description("재밌습니다~")
.booktalkStatus(BooktalkStatus.PLACE_CONFIRMED)
.build();
em.persist(booktalk2);

MemberBooktalk memberBooktalk = MemberBooktalk.builder()
.member(citizen)
.booktalk(booktalk)
.build();

MemberBooktalk memberBooktalk2 = MemberBooktalk.builder()
.member(citizen)
.booktalk(booktalk2)
.build();

em.persist(memberBooktalk);
em.persist(memberBooktalk2);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import lombok.RequiredArgsConstructor;
import org.sophy.sophy.common.dto.ApiResponseDto;
import org.sophy.sophy.controller.dto.request.MemberAdditionalInfoDto;
import org.sophy.sophy.controller.dto.response.BooktalkResponseDto;
import org.sophy.sophy.domain.dto.MyPageDto;
import org.sophy.sophy.domain.dto.MyInfoDto;
import org.sophy.sophy.exception.SuccessStatus;
import org.sophy.sophy.service.MemberService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/member")
Expand Down Expand Up @@ -39,4 +42,10 @@ public ApiResponseDto<MemberAdditionalInfoDto> postAdditionalInfo(@PathVariable(
public ApiResponseDto<MyInfoDto> patchInfo(@PathVariable("memberId") Long memberId, @RequestBody MyInfoDto myInfoDto) {
return ApiResponseDto.success(SuccessStatus.PATCH_MYINFO_SUCCESS, memberService.patchMyInfo(memberId, myInfoDto));
}

@GetMapping("/my-booktalks/{memberId}")
@ResponseStatus(HttpStatus.OK)
public ApiResponseDto<List<BooktalkResponseDto>> getMyBooktalks(@PathVariable("memberId") Long memberId) {
return ApiResponseDto.success(SuccessStatus.GET_MY_BOOKTALKS_SUCCESS, memberService.getBooktalksByMemberId(memberId));
}
}
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)
.member(member)
.author(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.getMember().getName(),
booktalk.getAuthor().getName(),
booktalk.getBookCategory(),
"책이름", //TODO 추후 연결
booktalk.getStartDate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.sophy.sophy.domain.Booktalk;
import org.sophy.sophy.domain.PreliminaryInfo;

import java.time.LocalDateTime;
import java.util.ArrayList;

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
Expand All @@ -21,17 +19,19 @@ public class BooktalkResponseDto {
private String place;
private Integer participant;
private Integer maximum;
private String booktalkImageUrl;

public static BooktalkResponseDto of(Booktalk booktalk) {
return new BooktalkResponseDto(
booktalk.getId(),
booktalk.getPreliminaryInfo().ordinal(),
booktalk.getTitle(),
booktalk.getMember().getName(),
booktalk.getAuthor().getName(),
booktalk.getStartDate(),
booktalk.getEndDate(),
booktalk.getPlace().getName(),
booktalk.getParticipantList().size(),
booktalk.getMaximum());
booktalk.getMaximum(),
booktalk.getBooktalkImageUrl());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
public class Author {
public class AuthorProperty {
@Id
@GeneratedValue
@Column(name = "author_id")
@Column(name = "author_property_id")
private Long id;

@OneToMany
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/org/sophy/sophy/domain/Booktalk.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Booktalk extends AuditingTimeEntity {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.CONSTRAINT))
private Member member;
private Member author;

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

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

@Builder
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) {
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) {
setPlace(place);
this.title = title;
this.booktalkImageUrl = booktalkImageUrl;
setMember(member);
setAuthor(author);
this.bookCategory = bookCategory;
this.startDate = startDate;
this.endDate = endDate;
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/org/sophy/sophy/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.sophy.sophy.domain.dto.MyInfoDto;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
Expand Down Expand Up @@ -50,30 +51,30 @@ public class Member extends AuditingTimeEntity{
private Integer bookCount;
private Integer bookTalkCount;

@OneToOne
private Booktalk imminentBooktalk;

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

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

@Builder
public Member(String name, String email, String password, String phoneNum, String gender, String birth
, City myCity, boolean marketingAgree, boolean isAuthor, boolean isOperator, Authority authority) {
public Member(String name, String email, String password, String phoneNum, boolean marketingAgree, boolean isAuthor, boolean isOperator, Authority authority) {
this.name = name;
this.email = email;
this.password = password;
this.phoneNum = phoneNum;
this.gender = gender;
this.birth = birth;
this.myCity = myCity;
this.marketingAgree = marketingAgree;
this.isAuthor = isAuthor;
this.isOperator = isOperator;
this.authority = authority;
this.userBookTalkList = new ArrayList<>();
}

public void serAuthor(Author author) {
this.author = author;
public void setAuthor(AuthorProperty authorProperty) {
this.authorProperty = authorProperty;
}

public void setBookCount(int count) {
Expand All @@ -84,6 +85,10 @@ 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
7 changes: 2 additions & 5 deletions src/main/java/org/sophy/sophy/domain/MemberBooktalk.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public class MemberBooktalk extends AuditingTimeEntity {
@JoinColumn(name = "booktalk_id", nullable = false, foreignKey = @ForeignKey(ConstraintMode.CONSTRAINT))
private Booktalk booktalk;

private Boolean isConfirmed;

// 연관 관계 편의 메서드
public void setMember(Member member) {
this.member = member;
Expand All @@ -42,9 +40,8 @@ public void setBooktalk(Booktalk booktalk) {
}

@Builder
public MemberBooktalk(Member member, Booktalk booktalk, Boolean isConfirmed) {
this.member = member;
public MemberBooktalk(Member member, Booktalk booktalk) {
setMember(member);
setBooktalk(booktalk);
this.isConfirmed = isConfirmed;
}
}
3 changes: 2 additions & 1 deletion src/main/java/org/sophy/sophy/domain/dto/MyPageDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import org.sophy.sophy.domain.Booktalk;

@Getter
@AllArgsConstructor
@Builder
public class MyPageDto {
private String name;
// private Booktalk imminentBooktalk;
private Booktalk imminentBooktalk;
private Integer bookCount;
private Integer bookTalkCount;
private Integer matchingBookTalkCount;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/sophy/sophy/exception/SuccessStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum SuccessStatus {
DELETE_BOOKTALK_SUCCESS(HttpStatus.OK, "북토크를 성공적으로 삭제했습니다."),
GET_BOOKTALK_DETAIL_SUCCESS(HttpStatus.OK, "북토크 상세정보를 성공적으로 불러왔습니다."),
GET_BOOKTALKS_BY_CITY_SUCCESS(HttpStatus.OK, "지역으로 북토크 리스트를 성공적으로 불러왔습니다"),
GET_MY_BOOKTALKS_SUCCESS(HttpStatus.OK, "예정된 북토크 리스트를 성공적으로 불러왔습니다"),
TEST_SUCCESS(HttpStatus.OK, "Test :: OK"),
/*
* 201 created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
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 @@ -53,7 +53,7 @@ public BooktalkDeleteResponseDto deleteBooktalk(Long booktalkId) {
//TODO soft delete?
//공간이 거절 됐거나 공간 매칭중일 때만 삭제가능
booktalk.getPlace().deleteBooktalk(booktalk);
booktalk.getMember().getAuthor().deleteBooktalk(booktalk);
booktalk.getAuthor().getAuthorProperty().deleteBooktalk(booktalk);
booktalkRepository.deleteById(booktalkId);
return BooktalkDeleteResponseDto.of(booktalkId);
}
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/org/sophy/sophy/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@

import lombok.RequiredArgsConstructor;
import org.sophy.sophy.controller.dto.request.MemberAdditionalInfoDto;
import org.sophy.sophy.controller.dto.response.BooktalkResponseDto;
import org.sophy.sophy.domain.Member;
import org.sophy.sophy.domain.MemberBooktalk;
import org.sophy.sophy.domain.dto.MyPageDto;
import org.sophy.sophy.domain.dto.MyInfoDto;
import org.sophy.sophy.exception.ErrorStatus;
import org.sophy.sophy.exception.model.NotFoundException;
import org.sophy.sophy.infrastructure.BooktalkRepository;
import org.sophy.sophy.infrastructure.MemberRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;


@Service
@RequiredArgsConstructor
public class MemberService {
private final MemberRepository memberRepository;
private final BooktalkRepository booktalkRepository;

@Transactional
public MyPageDto getMyPage(Long memberId) {
Expand All @@ -26,8 +33,8 @@ public MyPageDto getMyPage(Long memberId) {
.name(member.getName())
.bookCount(member.getBookCount())
.bookTalkCount(member.getBookTalkCount())
.matchingBookTalkCount(member.getAuthor().getMatchingBookTalkCount())
.recruitBookTalkCount(member.getAuthor().getRecruitBookTalkCount())
.matchingBookTalkCount(member.getAuthorProperty().getMatchingBookTalkCount())
.recruitBookTalkCount(member.getAuthorProperty().getRecruitBookTalkCount())
.build();
} else {
return MyPageDto.builder()
Expand Down Expand Up @@ -69,5 +76,14 @@ private Member getMemberById(Long memberId) {
.orElseThrow(() -> new NotFoundException(ErrorStatus.NOT_FOUND_USER_EXCEPTION, ErrorStatus.NOT_FOUND_USER_EXCEPTION.getMessage()));
}

@Transactional
public List<BooktalkResponseDto> getBooktalksByMemberId(Long memberId) {
List<MemberBooktalk> userBookTalkList = getMemberById(memberId).getUserBookTalkList();
List<BooktalkResponseDto> booktalkResponseDtoList = new ArrayList<>();
userBookTalkList.forEach(booktalk -> {
booktalkResponseDtoList.add(BooktalkResponseDto.of(booktalk.getBooktalk()));
});
return booktalkResponseDtoList;
}

}

0 comments on commit 3ba206e

Please sign in to comment.