From 8541a07f7a09fb03d484d2783949d3269f445220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=8D=EA=B9=80=EC=9A=A9=EB=B9=88?= Date: Fri, 27 Sep 2024 22:43:31 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EA=B0=9C=ED=96=89=20=EC=82=AD=EC=A0=9C=20=EB=B0=8F?= =?UTF-8?q?=20=EC=BB=A8=EB=B2=A4=EC=85=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/implement/SummaryAIManager.java | 8 +++--- .../request/PostDetailServiceRequest.java | 2 +- .../post/request/summary/SummaryLevel.java | 1 - .../post/request/summary/SummaryOption.java | 4 +-- .../business/post/response/PostListDto.java | 2 +- .../post/response/PostListResponse.java | 1 - .../post/controller/PostController.java | 26 ++++++++++--------- .../repository/post/PostRepository.java | 1 - 8 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/main/java/project/backend/business/post/implement/SummaryAIManager.java b/src/main/java/project/backend/business/post/implement/SummaryAIManager.java index 87308ac..a23afe0 100644 --- a/src/main/java/project/backend/business/post/implement/SummaryAIManager.java +++ b/src/main/java/project/backend/business/post/implement/SummaryAIManager.java @@ -21,7 +21,9 @@ public String getSummary(CreatePostServiceRequest createPostServiceRequest) { Prompt prompt = getPrompt(createPostServiceRequest); ChatResponse response = chatModel.call(prompt); - return response.getResult().getOutput().getContent(); + return response.getResult() + .getOutput() + .getContent(); } private Prompt getPrompt(CreatePostServiceRequest createPostServiceRequest) { @@ -34,8 +36,8 @@ private Prompt getPrompt(CreatePostServiceRequest createPostServiceRequest) { + "Summary conditions: \n" + "Summary length: " + options.getLevel().getLines() + "\n" + "Summary tone:" + options.getTone().getValue() + "\n" - + "Summary language: " + options.getLanguage().getValue() + - "\n" + "Summary keywords: " + options.getKeywords(); + + "Summary language: " + options.getLanguage().getValue() + "\n" + + "Summary keywords: " + options.getKeywords(); return new Prompt(requestMessage, VertexAiGeminiChatOptions.builder() diff --git a/src/main/java/project/backend/business/post/request/PostDetailServiceRequest.java b/src/main/java/project/backend/business/post/request/PostDetailServiceRequest.java index f4008d9..689197a 100644 --- a/src/main/java/project/backend/business/post/request/PostDetailServiceRequest.java +++ b/src/main/java/project/backend/business/post/request/PostDetailServiceRequest.java @@ -8,6 +8,7 @@ @Getter @Builder public class PostDetailServiceRequest { + private Long postId; private PostStatus status; @@ -20,5 +21,4 @@ public static PostDetailServiceRequest of(Long postId, String status) { .status(postStatus) .build(); } - } diff --git a/src/main/java/project/backend/business/post/request/summary/SummaryLevel.java b/src/main/java/project/backend/business/post/request/summary/SummaryLevel.java index 0bf587f..10143bf 100644 --- a/src/main/java/project/backend/business/post/request/summary/SummaryLevel.java +++ b/src/main/java/project/backend/business/post/request/summary/SummaryLevel.java @@ -8,7 +8,6 @@ public enum SummaryLevel { BASE("moderate summary", 20), DETAIL("detail summary", 30); - private final String value; private final int lines; diff --git a/src/main/java/project/backend/business/post/request/summary/SummaryOption.java b/src/main/java/project/backend/business/post/request/summary/SummaryOption.java index 845befa..11b9e49 100644 --- a/src/main/java/project/backend/business/post/request/summary/SummaryOption.java +++ b/src/main/java/project/backend/business/post/request/summary/SummaryOption.java @@ -16,14 +16,12 @@ public class SummaryOption { private SummaryLanguage language; private String keywords; - public static SummaryOption of(String level, String tone, String language, String keywords) { try { return SummaryOption.builder() .level(SummaryLevel.stringToEnum(level.toUpperCase())) .tone(SummaryTone.stringToEnum(tone.toUpperCase())) - .language( - SummaryLanguage.stringToEnum(language.toUpperCase())) + .language(SummaryLanguage.stringToEnum(language.toUpperCase())) .keywords(keywords) .build(); } catch (IllegalArgumentException e) { diff --git a/src/main/java/project/backend/business/post/response/PostListDto.java b/src/main/java/project/backend/business/post/response/PostListDto.java index 9eb3d65..a07aca3 100644 --- a/src/main/java/project/backend/business/post/response/PostListDto.java +++ b/src/main/java/project/backend/business/post/response/PostListDto.java @@ -7,9 +7,9 @@ @Getter @Builder public class PostListDto { + private final Long id; private final String title; private final String createdAt; private final List tagList; - } diff --git a/src/main/java/project/backend/business/post/response/PostListResponse.java b/src/main/java/project/backend/business/post/response/PostListResponse.java index bd03eec..aa626f0 100644 --- a/src/main/java/project/backend/business/post/response/PostListResponse.java +++ b/src/main/java/project/backend/business/post/response/PostListResponse.java @@ -3,7 +3,6 @@ import java.util.List; import lombok.Builder; import lombok.Getter; -import project.backend.business.post.request.PostListServiceRequest; @Getter public class PostListResponse { diff --git a/src/main/java/project/backend/presentation/post/controller/PostController.java b/src/main/java/project/backend/presentation/post/controller/PostController.java index 5fb1e73..55748d3 100644 --- a/src/main/java/project/backend/presentation/post/controller/PostController.java +++ b/src/main/java/project/backend/presentation/post/controller/PostController.java @@ -4,20 +4,27 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import project.backend.business.post.PostService; import project.backend.business.post.request.PostDetailServiceRequest; import project.backend.business.post.request.PostListServiceRequest; import project.backend.business.post.response.CreateUpdatePostResponse; -import project.backend.business.post.response.PostListResponse; import project.backend.business.post.response.PostDetailResponse; +import project.backend.business.post.response.PostListResponse; import project.backend.presentation.post.request.SummaryUrlRequest; import project.backend.presentation.post.request.UpdatePostRequest; import project.backend.security.aop.AssignCurrentUserInfo; import project.backend.security.aop.AssignOrNullCurrentUserInfo; import project.backend.security.aop.CurrentUserInfo; - @Slf4j @RestController @RequiredArgsConstructor @@ -46,16 +53,14 @@ public ResponseEntity getPosts(CurrentUserInfo userInfo, public ResponseEntity createNewPost(CurrentUserInfo userInfo, @RequestBody SummaryUrlRequest summaryUrlRequest) { CreateUpdatePostResponse createUpdatePostResponse = postService.createNewPostDetail( - userInfo.getUserId(), - summaryUrlRequest.toServiceRequest()); + userInfo.getUserId(), summaryUrlRequest.toServiceRequest()); return new ResponseEntity<>(createUpdatePostResponse, HttpStatus.CREATED); } @AssignOrNullCurrentUserInfo @GetMapping("/{id}") public ResponseEntity getPostDetail(CurrentUserInfo userInfo, - @PathVariable("id") Long id, - @RequestParam String status) { + @PathVariable("id") Long id, @RequestParam String status) { PostDetailServiceRequest request = PostDetailServiceRequest.of(id, status); PostDetailResponse response = postService.getPostDetail(userInfo.getUserId(), request); return new ResponseEntity<>(response, HttpStatus.OK); @@ -64,8 +69,7 @@ public ResponseEntity getPostDetail(CurrentUserInfo userInfo @AssignCurrentUserInfo @PatchMapping("/{id}") public ResponseEntity updatePost(CurrentUserInfo userInfo, - @PathVariable("id") Long postId, - @RequestBody UpdatePostRequest updatePostRequest) { + @PathVariable("id") Long postId, @RequestBody UpdatePostRequest updatePostRequest) { CreateUpdatePostResponse response = postService.updatePostDetail(userInfo.getUserId(), postId, updatePostRequest.toServiceRequest()); @@ -80,12 +84,10 @@ public ResponseEntity deletePost(CurrentUserInfo userInfo, return new ResponseEntity<>(HttpStatus.OK); } - @AssignOrNullCurrentUserInfo @PatchMapping("/{id}/summary") public ResponseEntity updateSummaryPost(CurrentUserInfo userInfo, - @PathVariable("id") Long postId, - @RequestBody SummaryUrlRequest summaryUrlRequest) { + @PathVariable("id") Long postId, @RequestBody SummaryUrlRequest summaryUrlRequest) { CreateUpdatePostResponse response = postService.updateSummaryPost(userInfo.getUserId(), postId, summaryUrlRequest.toServiceRequest()); return new ResponseEntity<>(response, HttpStatus.OK); diff --git a/src/main/java/project/backend/repository/post/PostRepository.java b/src/main/java/project/backend/repository/post/PostRepository.java index 605cea8..45db5c9 100644 --- a/src/main/java/project/backend/repository/post/PostRepository.java +++ b/src/main/java/project/backend/repository/post/PostRepository.java @@ -6,7 +6,6 @@ import project.backend.entity.post.Post; import project.backend.entity.post.PostStatus; - @Repository public interface PostRepository extends JpaRepository, JpaSpecificationExecutor {