Skip to content

Commit

Permalink
#25 feat: 컨텐츠 생성 로직 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
wjdwlghks committed May 3, 2024
1 parent bef190e commit eed6458
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class ContentController {
@PostMapping("/create")
public ResponseEntity<?> createContent(@AuthenticationPrincipal PrincipalDetails details,
@RequestBody ContentCreateRequest request,
@RequestParam Long bookId, @RequestParam(required = false) Long clubId) {
contentService.createContent(details.getUserId(), request, bookId, clubId);
@RequestParam(required = false) Long clubId) {
contentService.createContent(details.getUserId(), request, clubId);
return ResponseEntity.ok().body("컨텐츠 생성 완료");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.project.capstone.content.controller.dto;

import com.project.capstone.book.controller.dto.AddBookRequest;
import com.project.capstone.content.domain.ContentType;

public record ContentCreateRequest(
AddBookRequest addBookRequest,
ContentType contentType,
String title,
String body
String body,
String startDate,
String endDate
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public class Content {
private String body;
private int likes;

@Column(name = "start_date")
private String startDate;

@Column(name = "end_date")
private String endDate;

@JsonBackReference
@ManyToOne
private Member member;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.project.capstone.book.domain.BookRepository;
import com.project.capstone.book.exception.BookException;
import com.project.capstone.book.exception.BookExceptionType;
import com.project.capstone.book.service.BookService;
import com.project.capstone.club.domain.Club;
import com.project.capstone.club.domain.ClubRepository;
import com.project.capstone.club.exception.ClubException;
Expand Down Expand Up @@ -44,13 +45,21 @@ public class ContentService {
private final ClubRepository clubRepository;
private final MemberRepository memberRepository;

public void createContent(String userId, ContentCreateRequest request, Long bookId, Long clubId) {
public void createContent(String userId, ContentCreateRequest request, Long clubId) {
Member member = memberRepository.findMemberById(UUID.fromString(userId)).orElseThrow(
() -> new MemberException(MEMBER_NOT_FOUND)
);
Book book = bookRepository.findBookById(bookId).orElseThrow(
() -> new BookException(BOOK_NOT_FOUND)
);

Book book;
if (bookRepository.findBookByIsbn(request.addBookRequest().isbn()).isEmpty()) {
book = bookRepository.save(new Book(request.addBookRequest()));
}
else {
book = bookRepository.findBookByIsbn(request.addBookRequest().isbn()).orElseThrow(
() -> new BookException(BOOK_NOT_FOUND)
);
}

Club club;
if (clubId == null) {
club = null;
Expand Down

0 comments on commit eed6458

Please sign in to comment.