Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#41 add booktalk list return api #42

Merged
merged 28 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
60a4f6c
add: BooktalkCreateRequestDto, ResponseDto μΆ”κ°€
onpyeong Jul 10, 2023
43cdfc3
feat: POST 뢁토크 생성 κ΅¬ν˜„
onpyeong Jul 10, 2023
72c4a16
add: BooktalkUpdateDto μΆ”κ°€
onpyeong Jul 10, 2023
c659252
modify: Booktalk에 patchBooktalkμΆ”κ°€
onpyeong Jul 10, 2023
759e0d2
feat: PATCH 뢁토크 μˆ˜μ •ν•˜κΈ° κ΅¬ν˜„
onpyeong Jul 10, 2023
3a7b5bb
fix: 뢁토크 생성 μ‹œ member와 place μ—°κ²°
onpyeong Jul 10, 2023
85efa87
add: BooktalkDeleteResponseDto μΆ”κ°€
onpyeong Jul 10, 2023
968c91e
modify: Author와 Booktalk에 deleteBooktalk μΆ”κ°€
onpyeong Jul 10, 2023
3f1aeba
feat: DELETE 뢁토크 μ‚­μ œ κ΅¬ν˜„
onpyeong Jul 10, 2023
0135e6f
feat: GET 뢁토크 μƒμ„Έμ‘°νšŒ κ΅¬ν˜„
onpyeong Jul 10, 2023
0b1e04d
Merge branch 'main' into feat/#33-open-booktalk
dong2ast Jul 11, 2023
219179c
refactor: μ›μ‹œνƒ€μž… 제거
dong2ast Jul 11, 2023
7b5fb14
refactor: access level μˆ˜μ •
dong2ast Jul 11, 2023
887229d
refactor: μ›μ‹œνƒ€μž… 제거
dong2ast Jul 11, 2023
4943b1a
fix: λ¦¬νŒ©ν„° 였λ₯˜ μˆ˜μ •
dong2ast Jul 11, 2023
9ff02bd
feat: μ§€μ—­μœΌλ‘œ 뢁토크 리슀트 쑰회 (#35)
onpyeong Jul 11, 2023
6669ce4
feat: κ°€μž₯ κ°€κΉŒμš΄ 뢁토크 멀버 ν•„λ“œμ— μΆ”κ°€
dong2ast Jul 11, 2023
a5ab0cf
feat: μ˜ˆμ •λœ 뢁토크 쑰회 λ©”μ„œλ“œ μΆ”κ°€
dong2ast Jul 11, 2023
b7e8f96
Merge branch 'main' into feat/#41-add-booktalk-list-return-api
onpyeong Jul 11, 2023
8810a72
chore: μ›μ‹œ νƒ€μž… μˆ˜μ • 였λ₯˜ ν•΄κ²°
dong2ast Jul 11, 2023
6f421e3
fix: μ˜ˆμ •λœ 뢁토크 μ‘°νšŒν•΄μ˜€λŠ” λ©”μ„œλ“œ μˆ˜μ •
dong2ast Jul 11, 2023
cdd03c2
add: initDB에 데이터 μΆ”κ°€
dong2ast Jul 11, 2023
bf977e2
add: initDB에 데이터 μΆ”κ°€
dong2ast Jul 11, 2023
d19f54e
chore: Booktalk의 멀버 λ³€μˆ˜ -> author μ΄λ¦„μœΌλ‘œ λ³€κ²½
dong2ast Jul 11, 2023
c2c7ce2
chore: Booktalk의 멀버 λ³€μˆ˜ -> author μ΄λ¦„μœΌλ‘œ λ³€κ²½
dong2ast Jul 11, 2023
22267e1
refactor: Memberκ°€ 가진 Author ν•„λ“œλ₯Ό AuthorProperty둜 이름 λ³€κ²½ μž‘μ—…
dong2ast Jul 11, 2023
823f3c7
feat: ν˜„μž¬ Issue에 λŒ€ν•œ ν…ŒμŠ€νŠΈ 데이터 InitDb에 μΆ”κ°€
dong2ast Jul 11, 2023
8efb249
fix: BooktalkResponseDto에 image String도 μΆ”κ°€
dong2ast Jul 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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의 μž‘κ°€
}
4 changes: 2 additions & 2 deletions src/main/java/org/sophy/sophy/service/BooktalkService.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public BooktalkCreateResponseDto createBooktalk(BooktalkRequestDto booktalkReque
Place place = getPlaceById(booktalkRequestDto.getPlaceId());
//μž‘κ°€μΈμ§€ 확인할 ν•„μš”κ°€ μžˆλŠ”μ§€?
Member member = getMemberById(booktalkRequestDto.getMemberId());
if(!member.isAuthor()) {
if(!member.getIsAuthor()) {
throw new ForbiddenException(ErrorStatus.FORBIDDEN_USER_EXCEPTION, ErrorStatus.FORBIDDEN_USER_EXCEPTION.getMessage());
}
Booktalk booktalk = booktalkRequestDto.toBooktalk(place, member);
Expand All @@ -54,7 +54,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;
}

}