Skip to content

Commit

Permalink
Merge pull request #50 from kookmin-sw/BE_Feature/#25-content-and-quiz
Browse files Browse the repository at this point in the history
컨텐츠 생성 방식 변경
  • Loading branch information
wjdwlghks authored May 3, 2024
2 parents bef190e + 7373146 commit 2b80bd6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 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,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;
Expand Down

0 comments on commit 2b80bd6

Please sign in to comment.