From eed64583f7e72dd4cf9f5c88b348a0f3e643b627 Mon Sep 17 00:00:00 2001 From: ji hwan Date: Fri, 3 May 2024 16:31:21 +0900 Subject: [PATCH] =?UTF-8?q?#25=20feat:=20=EC=BB=A8=ED=85=90=EC=B8=A0=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../content/controller/ContentController.java | 4 ++-- .../controller/dto/ContentCreateRequest.java | 6 +++++- .../capstone/content/domain/Content.java | 6 ++++++ .../content/service/ContentService.java | 17 +++++++++++++---- 4 files changed, 26 insertions(+), 7 deletions(-) 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..ba068bcbc9 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,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;