From 9aee45892089d000b874b3af1796f36f480f2ea9 Mon Sep 17 00:00:00 2001 From: mng990 Date: Thu, 7 Nov 2024 16:51:44 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20AI=20=EA=B2=B0=EA=B3=BC=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=20=EC=B6=94=EA=B0=80(post)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/common/config/SecurityConfig.java | 4 +-- .../common/mapper/PrivatePostMapper.java | 25 +++++++++++-------- .../post/controller/PostController.java | 6 +++++ .../FindJudgmentFromPostResponse.java | 4 +++ .../domains/post/service/PostService.java | 7 ++++++ .../controller/PrivatePostController.java | 2 +- .../service/PrivatePostService.java | 7 +++++- 7 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 backend/src/main/java/aimo/backend/domains/post/dto/response/FindJudgmentFromPostResponse.java diff --git a/backend/src/main/java/aimo/backend/common/config/SecurityConfig.java b/backend/src/main/java/aimo/backend/common/config/SecurityConfig.java index e20e4a2..3f49f1c 100644 --- a/backend/src/main/java/aimo/backend/common/config/SecurityConfig.java +++ b/backend/src/main/java/aimo/backend/common/config/SecurityConfig.java @@ -36,7 +36,7 @@ public class SecurityConfig { private final UserDetailsService userDetailsService; private final JwtTokenProvider jwtTokenProvider; - private final UrlBasedCorsConfigurationSource ConfigurationSource; + private final UrlBasedCorsConfigurationSource configurationSource; private final SecurityProperties securityProperties; private final PasswordEncoder passwordEncoder; private final AntPathMatcher pathMatcher = new AntPathMatcher(); @@ -54,7 +54,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti // cors 설정 http - .cors(cors -> cors.configurationSource(ConfigurationSource)); + .cors(cors -> cors.configurationSource(configurationSource)); // url 관리 http diff --git a/backend/src/main/java/aimo/backend/common/mapper/PrivatePostMapper.java b/backend/src/main/java/aimo/backend/common/mapper/PrivatePostMapper.java index 1e67e0b..1415baa 100644 --- a/backend/src/main/java/aimo/backend/common/mapper/PrivatePostMapper.java +++ b/backend/src/main/java/aimo/backend/common/mapper/PrivatePostMapper.java @@ -23,6 +23,18 @@ public static PrivatePost toEntity(JudgementResponse judgementResponse, Member m .build(); } + public static JudgementResponse toJudgement(PrivatePost privatePost) { + return new JudgementResponse( + privatePost.getTitle(), + privatePost.getSummaryAi(), + privatePost.getStancePlaintiff(), + privatePost.getStanceDefendant(), + privatePost.getJudgement(), + privatePost.getFaultRatePlaintiff(), + privatePost.getFaultRateDefendant(), + privatePost.getOriginType()); + } + public static PrivatePostPreviewResponse toPreviewResponse(PrivatePost privatePost) { return new PrivatePostPreviewResponse(privatePost.getId(), privatePost.getTitle(), getPreview(privatePost.getSummaryAi(), 21), privatePost.getOriginType(), privatePost.getCreatedAt(), @@ -34,15 +46,8 @@ public static String getPreview(String summaryAi, Integer length) { } public static PrivatePostResponse toResponse(PrivatePost privatePost) { - return new PrivatePostResponse( - privatePost.getId(), - privatePost.getTitle(), - privatePost.getSummaryAi(), - privatePost.getStancePlaintiff(), - privatePost.getStanceDefendant(), - privatePost.getJudgement(), - privatePost.getFaultRatePlaintiff(), - privatePost.getFaultRateDefendant(), - privatePost.getPublished()); + return new PrivatePostResponse(privatePost.getId(), privatePost.getTitle(), privatePost.getSummaryAi(), + privatePost.getStancePlaintiff(), privatePost.getStanceDefendant(), privatePost.getJudgement(), + privatePost.getFaultRatePlaintiff(), privatePost.getFaultRateDefendant(), privatePost.getPublished()); } } diff --git a/backend/src/main/java/aimo/backend/domains/post/controller/PostController.java b/backend/src/main/java/aimo/backend/domains/post/controller/PostController.java index 4a6b88e..8e44ed2 100644 --- a/backend/src/main/java/aimo/backend/domains/post/controller/PostController.java +++ b/backend/src/main/java/aimo/backend/domains/post/controller/PostController.java @@ -19,6 +19,7 @@ import aimo.backend.domains.post.model.PostType; import aimo.backend.domains.post.service.PostService; import aimo.backend.domains.post.service.PostViewService; +import aimo.backend.domains.privatePost.dto.response.JudgementResponse; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import lombok.RequiredArgsConstructor; @@ -52,6 +53,11 @@ public ResponseEntity> findPostAnd return ResponseEntity.ok(DataResponse.from(postService.findPostAndCommentsDtoById(postId))); } + @GetMapping("/{postId}/judgement") + public ResponseEntity> findJudgement(@PathVariable Long postId) { + return ResponseEntity.ok(DataResponse.from(postService.findJudgementBy(postId))); + } + @DeleteMapping("/{postId}") public ResponseEntity> deletePost(@PathVariable Long postId) { postService.deletePostBy(postId); diff --git a/backend/src/main/java/aimo/backend/domains/post/dto/response/FindJudgmentFromPostResponse.java b/backend/src/main/java/aimo/backend/domains/post/dto/response/FindJudgmentFromPostResponse.java new file mode 100644 index 0000000..0e009a4 --- /dev/null +++ b/backend/src/main/java/aimo/backend/domains/post/dto/response/FindJudgmentFromPostResponse.java @@ -0,0 +1,4 @@ +package aimo.backend.domains.post.dto.response; + +public record FindJudgmentFromPostResponse() { +} diff --git a/backend/src/main/java/aimo/backend/domains/post/service/PostService.java b/backend/src/main/java/aimo/backend/domains/post/service/PostService.java index 061e189..b59f055 100644 --- a/backend/src/main/java/aimo/backend/domains/post/service/PostService.java +++ b/backend/src/main/java/aimo/backend/domains/post/service/PostService.java @@ -17,6 +17,7 @@ import aimo.backend.common.exception.ApiException; import aimo.backend.common.mapper.PostMapper; +import aimo.backend.common.mapper.PrivatePostMapper; import aimo.backend.domains.comment.entity.ChildComment; import aimo.backend.domains.comment.entity.ParentComment; import aimo.backend.domains.member.entity.Member; @@ -27,6 +28,7 @@ import aimo.backend.domains.post.entity.Post; import aimo.backend.domains.post.model.PostType; import aimo.backend.domains.post.repository.PostRepository; +import aimo.backend.domains.privatePost.dto.response.JudgementResponse; import aimo.backend.domains.privatePost.service.PrivatePostService; import aimo.backend.util.memberLoader.MemberLoader; import lombok.RequiredArgsConstructor; @@ -57,6 +59,11 @@ public Post findById(Long postId) { .orElseThrow(() -> ApiException.from(POST_NOT_FOUND)); } + public JudgementResponse findJudgementBy(Long postId) { + Long privatePostId = findById(postId).getPrivatePostId(); + return PrivatePostMapper.toJudgement(privatePostService.findPrivatePostBy(privatePostId)); + } + // 글 조회, dto로 응답 public FindPostAndCommentsByIdResponse findPostAndCommentsDtoById(Long postId) { Post post = findById(postId); diff --git a/backend/src/main/java/aimo/backend/domains/privatePost/controller/PrivatePostController.java b/backend/src/main/java/aimo/backend/domains/privatePost/controller/PrivatePostController.java index b25a7d4..de89db3 100644 --- a/backend/src/main/java/aimo/backend/domains/privatePost/controller/PrivatePostController.java +++ b/backend/src/main/java/aimo/backend/domains/privatePost/controller/PrivatePostController.java @@ -105,7 +105,7 @@ public ResponseEntity> saveAudioRecord( public ResponseEntity> findPrivatePost( @Valid @PathVariable Long privatePostId) { return ResponseEntity.status(HttpStatus.CREATED) - .body(DataResponse.from(privatePostService.findPrivatePostBy(privatePostId))); + .body(DataResponse.from(privatePostService.findPrivatePostResponseBy(privatePostId))); } @GetMapping diff --git a/backend/src/main/java/aimo/backend/domains/privatePost/service/PrivatePostService.java b/backend/src/main/java/aimo/backend/domains/privatePost/service/PrivatePostService.java index 3e0dcec..7dc406b 100644 --- a/backend/src/main/java/aimo/backend/domains/privatePost/service/PrivatePostService.java +++ b/backend/src/main/java/aimo/backend/domains/privatePost/service/PrivatePostService.java @@ -107,7 +107,7 @@ public void deletePrivatePostBy(Long privatePostId) { privatePostRepository.delete(privatePost); } - public PrivatePostResponse findPrivatePostBy(Long id) { + public PrivatePostResponse findPrivatePostResponseBy(Long id) { PrivatePost privatePost = privatePostRepository.findById(id) .orElseThrow(() -> ApiException.from(ErrorCode.PRIVATE_POST_NOT_FOUND)); @@ -118,6 +118,11 @@ public PrivatePostResponse findPrivatePostBy(Long id) { return PrivatePostMapper.toResponse(privatePost); } + public PrivatePost findPrivatePostBy(Long id){ + return privatePostRepository.findById(id) + .orElseThrow(() -> ApiException.from(ErrorCode.PRIVATE_POST_NOT_FOUND)); + } + public Page findPrivatePostPreviewsBy(Pageable pageable) { return privatePostRepository.findByMemberId(memberLoader.getMemberId(), pageable) .map(PrivatePostMapper::toPreviewResponse);