diff --git a/backend/src/main/java/com/project/capstone/content/controller/ContentController.java b/backend/src/main/java/com/project/capstone/content/controller/ContentController.java index 92b6c3b014..e56f1b0ee4 100644 --- a/backend/src/main/java/com/project/capstone/content/controller/ContentController.java +++ b/backend/src/main/java/com/project/capstone/content/controller/ContentController.java @@ -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("컨텐츠 생성 완료"); } diff --git a/backend/src/main/java/com/project/capstone/content/controller/dto/ContentCreateRequest.java b/backend/src/main/java/com/project/capstone/content/controller/dto/ContentCreateRequest.java index f35b74de83..0ded890463 100644 --- a/backend/src/main/java/com/project/capstone/content/controller/dto/ContentCreateRequest.java +++ b/backend/src/main/java/com/project/capstone/content/controller/dto/ContentCreateRequest.java @@ -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 ) { } diff --git a/backend/src/main/java/com/project/capstone/content/domain/Content.java b/backend/src/main/java/com/project/capstone/content/domain/Content.java index b042f06fe1..b70bf829d9 100644 --- a/backend/src/main/java/com/project/capstone/content/domain/Content.java +++ b/backend/src/main/java/com/project/capstone/content/domain/Content.java @@ -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; diff --git a/backend/src/main/java/com/project/capstone/content/service/ContentService.java b/backend/src/main/java/com/project/capstone/content/service/ContentService.java index 3efb4238b3..fa8261c05f 100644 --- a/backend/src/main/java/com/project/capstone/content/service/ContentService.java +++ b/backend/src/main/java/com/project/capstone/content/service/ContentService.java @@ -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; @@ -44,13 +45,15 @@ 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 = bookRepository.findBookByIsbn(request.addBookRequest().isbn()).orElseGet( + () -> bookRepository.save(new Book(request.addBookRequest())) ); + Club club; if (clubId == null) { club = null;