Skip to content

Commit

Permalink
feat: AI 결과 조회 API 추가(post)
Browse files Browse the repository at this point in the history
  • Loading branch information
mangowhoiscloud committed Nov 7, 2024
1 parent 848ab28 commit 9aee458
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,6 +53,11 @@ public ResponseEntity<DataResponse<FindPostAndCommentsByIdResponse>> findPostAnd
return ResponseEntity.ok(DataResponse.from(postService.findPostAndCommentsDtoById(postId)));
}

@GetMapping("/{postId}/judgement")
public ResponseEntity<DataResponse<JudgementResponse>> findJudgement(@PathVariable Long postId) {
return ResponseEntity.ok(DataResponse.from(postService.findJudgementBy(postId)));
}

@DeleteMapping("/{postId}")
public ResponseEntity<DataResponse<Void>> deletePost(@PathVariable Long postId) {
postService.deletePostBy(postId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package aimo.backend.domains.post.dto.response;

public record FindJudgmentFromPostResponse() {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public ResponseEntity<DataResponse<SaveAudioSuccessResponse>> saveAudioRecord(
public ResponseEntity<DataResponse<PrivatePostResponse>> findPrivatePost(
@Valid @PathVariable Long privatePostId) {
return ResponseEntity.status(HttpStatus.CREATED)
.body(DataResponse.from(privatePostService.findPrivatePostBy(privatePostId)));
.body(DataResponse.from(privatePostService.findPrivatePostResponseBy(privatePostId)));
}

@GetMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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<PrivatePostPreviewResponse> findPrivatePostPreviewsBy(Pageable pageable) {
return privatePostRepository.findByMemberId(memberLoader.getMemberId(), pageable)
.map(PrivatePostMapper::toPreviewResponse);
Expand Down

0 comments on commit 9aee458

Please sign in to comment.