Skip to content

Commit

Permalink
refactor: private post/post save response에id를 내리도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
mangowhoiscloud committed Nov 8, 2024
1 parent b4270cc commit c2a5945
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public static Post toEntity(SavePostRequest request, Member member) {

public static FindJudgementResponse toJudgement(Post post){
return new FindJudgementResponse(
post.getId(),
post.getTitle(),
post.getSummaryAi(),
post.getStancePlaintiff(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import aimo.backend.domains.post.dto.response.FindJudgementResponse;
import aimo.backend.domains.post.dto.response.FindPostAndCommentsByIdResponse;
import aimo.backend.domains.post.dto.response.FindPostsByPostTypeResponse;
import aimo.backend.domains.post.dto.response.SavePostResponse;
import aimo.backend.domains.post.entity.Post;
import aimo.backend.domains.post.model.PostType;
import aimo.backend.domains.post.service.PostService;
import aimo.backend.domains.post.service.PostViewService;
Expand All @@ -34,9 +36,10 @@ public class PostController {
private final PostViewService postViewService;

@PostMapping
public ResponseEntity<DataResponse<Void>> savePost(@RequestBody @Valid SavePostRequest request) {
postService.save(request);
return ResponseEntity.status(HttpStatus.CREATED).body(DataResponse.created());
public ResponseEntity<DataResponse<SavePostResponse>> savePost(@RequestBody @Valid SavePostRequest request) {
Post post = postService.save(request);
return ResponseEntity.status(HttpStatus.CREATED)
.body(DataResponse.created(new SavePostResponse(post.getId())));
}

@GetMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import jakarta.persistence.Enumerated;

public record FindJudgementResponse(
Long postId,
String title,
String summary,
String stancePlaintiff,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package aimo.backend.domains.post.dto.response;

public record SavePostResponse(
Long postId
)
{ }
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public class PostService {

// 글 저장
@Transactional
public void save(SavePostRequest savePostRequest) {
public Post save(SavePostRequest savePostRequest) {
Member member = memberLoader.getMember();
privatePostService.publishPrivatePost(savePostRequest.privatePostId());
postRepository.save(PostMapper.toEntity(savePostRequest, member));
return postRepository.save(PostMapper.toEntity(savePostRequest, member));
}

// 글 조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
import aimo.backend.domains.privatePost.dto.request.SaveAudioSuccessRequest;
import aimo.backend.domains.privatePost.dto.response.SaveAudioSuccessResponse;
import aimo.backend.domains.privatePost.dto.request.SpeechToTextRequest;
import aimo.backend.domains.privatePost.dto.response.SavePrivatePostResponse;
import aimo.backend.domains.privatePost.dto.response.SpeechToTextResponse;

import aimo.backend.domains.privatePost.dto.request.TextRecordRequest;
import aimo.backend.domains.privatePost.entity.PrivatePost;
import aimo.backend.domains.privatePost.service.AudioRecordService;
import aimo.backend.domains.privatePost.service.ChatRecordService;
import aimo.backend.domains.privatePost.service.PrivatePostService;
Expand Down Expand Up @@ -57,11 +59,13 @@ public class PrivatePostController {

// 판결
@PostMapping("/judgement")
public ResponseEntity<DataResponse<JudgementResponse>> summaryAndJudgment(@Valid @RequestBody JudgementToAiRequest judgementToAiRequest) {
public ResponseEntity<DataResponse<SavePrivatePostResponse>> summaryAndJudgment(@Valid @RequestBody JudgementToAiRequest judgementToAiRequest) {

JudgementResponse judgementResponse = privatePostService.serveScriptToAi(judgementToAiRequest);
privatePostService.save(judgementResponse);
return ResponseEntity.status(HttpStatus.CREATED).body(DataResponse.created(judgementResponse));
PrivatePost privatePost = privatePostService.save(judgementResponse);

return ResponseEntity.status(HttpStatus.CREATED)
.body(DataResponse.created(new SavePrivatePostResponse(privatePost.getId())));
}

// 대화록 업로드
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package aimo.backend.domains.privatePost.dto.response;

public record SavePrivatePostResponse(
Long privatePostId
) {
}

0 comments on commit c2a5945

Please sign in to comment.