forked from kookmin-sw/cap-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
26 changed files
with
627 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
backend/src/main/java/com/project/capstone/book/domain/BookRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.project.capstone.book.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface BookRepository extends JpaRepository<Book, Long> { | ||
Optional<Book> findBookById(Long id); | ||
} |
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/com/project/capstone/book/exception/BookException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.project.capstone.book.exception; | ||
|
||
import com.project.capstone.common.exception.BaseException; | ||
import com.project.capstone.common.exception.ExceptionType; | ||
|
||
public class BookException extends BaseException { | ||
public BookException(ExceptionType exceptionType) { | ||
super(exceptionType); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
backend/src/main/java/com/project/capstone/book/exception/BookExceptionType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.project.capstone.book.exception; | ||
|
||
import com.project.capstone.common.exception.ExceptionType; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import static org.springframework.http.HttpStatus.NOT_FOUND; | ||
|
||
@AllArgsConstructor | ||
public enum BookExceptionType implements ExceptionType { | ||
|
||
BOOK_NOT_FOUND(NOT_FOUND, 801, "해당 책을 찾을 수 없습니다.") | ||
; | ||
|
||
private final HttpStatus status; | ||
private final int exceptionCode; | ||
private final String message; | ||
|
||
@Override | ||
public HttpStatus httpStatus() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public int exceptionCode() { | ||
return exceptionCode; | ||
} | ||
|
||
@Override | ||
public String message() { | ||
return message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
backend/src/main/java/com/project/capstone/content/controller/ContentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.project.capstone.content.controller; | ||
|
||
import com.project.capstone.auth.domain.PrincipalDetails; | ||
import com.project.capstone.content.controller.dto.ContentCreateRequest; | ||
import com.project.capstone.content.controller.dto.ContentResponse; | ||
import com.project.capstone.content.service.ContentService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/content") | ||
public class ContentController { | ||
|
||
private final ContentService contentService; | ||
|
||
// 컨텐츠 생성 | ||
@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); | ||
return ResponseEntity.ok().body("컨텐츠 생성 완료"); | ||
} | ||
|
||
// 단일 컨텐츠 조회 | ||
@GetMapping("/{id}") | ||
public ResponseEntity<ContentResponse> getContent(@PathVariable Long id) { | ||
ContentResponse contentResponse = contentService.getContent(id); | ||
return ResponseEntity.ok().body(contentResponse); | ||
} | ||
|
||
// 컨텐츠 종류별 조회 | ||
@GetMapping("/get") | ||
public ResponseEntity<List<ContentResponse>> getContents(@RequestParam String type) { | ||
List<ContentResponse> contentResponseList = contentService.getContents(type); | ||
return ResponseEntity.ok().body(contentResponseList); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/com/project/capstone/content/controller/dto/ContentCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.project.capstone.content.controller.dto; | ||
|
||
import com.project.capstone.content.domain.ContentType; | ||
|
||
public record ContentCreateRequest( | ||
ContentType contentType, | ||
String title, | ||
String body | ||
) { | ||
} |
22 changes: 22 additions & 0 deletions
22
backend/src/main/java/com/project/capstone/content/controller/dto/ContentResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.project.capstone.content.controller.dto; | ||
|
||
import com.project.capstone.content.domain.Content; | ||
import com.project.capstone.content.domain.ContentType; | ||
|
||
import java.util.UUID; | ||
|
||
public record ContentResponse( | ||
Long id, | ||
UUID memberId, | ||
Long bookId, | ||
Long clubId, | ||
ContentType type, | ||
String title, | ||
String body, | ||
int likes | ||
) { | ||
public ContentResponse(Content content) { | ||
this(content.getId(), content.getMember().getId(), content.getBook().getId(), | ||
content.getClub() == null ? null : content.getClub().getId(), content.getType(), content.getTitle(), content.getBody(), content.getLikes()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
backend/src/main/java/com/project/capstone/content/domain/ContentRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.project.capstone.content.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface ContentRepository extends JpaRepository<Content, Long> { | ||
Optional<Content> findContentById(Long id); | ||
List<Content> findContentsByType(ContentType type); | ||
} |
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/com/project/capstone/content/domain/ContentType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.project.capstone.content.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
@Slf4j | ||
public enum ContentType { | ||
|
||
Review("독후감"), | ||
Quotation("인용구"), | ||
ShortReview("한줄평"); | ||
|
||
private final String type; | ||
|
||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING) | ||
public static ContentType from(String type) { | ||
for (ContentType contentType : ContentType.values()) { | ||
if (contentType.getType().equals(type)) { | ||
return contentType; | ||
} | ||
} | ||
throw new RuntimeException("잘못된 컨텐츠 타입 입니다."); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/com/project/capstone/content/exception/ContentException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.project.capstone.content.exception; | ||
|
||
import com.project.capstone.common.exception.BaseException; | ||
import com.project.capstone.common.exception.ExceptionType; | ||
|
||
public class ContentException extends BaseException { | ||
public ContentException(ExceptionType exceptionType) { | ||
super(exceptionType); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
backend/src/main/java/com/project/capstone/content/exception/ContentExceptionType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.project.capstone.content.exception; | ||
|
||
import com.project.capstone.common.exception.ExceptionType; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import static org.springframework.http.HttpStatus.NOT_FOUND; | ||
|
||
@AllArgsConstructor | ||
public enum ContentExceptionType implements ExceptionType { | ||
CONTENT_NOT_FOUND(NOT_FOUND, 901, "해당 컨텐츠를 찾을 수 없습니다."), | ||
TYPE_NOT_FOUND(NOT_FOUND, 902, "해당 타입을 찾을 수 없습니다.") | ||
; | ||
|
||
|
||
private final HttpStatus status; | ||
private final int exceptionCode; | ||
private final String message; | ||
|
||
@Override | ||
public HttpStatus httpStatus() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public int exceptionCode() { | ||
return exceptionCode; | ||
} | ||
|
||
@Override | ||
public String message() { | ||
return message; | ||
} | ||
} |
Oops, something went wrong.