From c22d029127eb16fd76aa672e980dcce7f9c149df Mon Sep 17 00:00:00 2001 From: yjs30 Date: Sun, 22 Dec 2024 14:16:13 +0900 Subject: [PATCH] =?UTF-8?q?replies=20api=20=ED=99=95=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blism/controller/ReplyRestController.java | 8 +++++ .../blism/dto/request/RepliesRequestDTO.java | 5 ---- .../dto/response/RepliesResponseDTO.java | 21 ++++++++++++++ .../blism/service/RepliesServiceImpl.java | 29 ++++++++++++++++--- 4 files changed, 54 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/example/blism/controller/ReplyRestController.java b/src/main/java/com/example/blism/controller/ReplyRestController.java index c3b4cbf..0f8f57f 100644 --- a/src/main/java/com/example/blism/controller/ReplyRestController.java +++ b/src/main/java/com/example/blism/controller/ReplyRestController.java @@ -54,4 +54,12 @@ public ApiResponse> getAllReceive return ApiResponse.onSuccess(repliesService.getAllReceivedReplies(member_id)); } + @GetMapping("/{replyid}") + @Operation(summary = "답장 조회",description = "답장을 조회하는 API 입니다") + public ApiResponse getreply( + @RequestParam(name = "replyid") Long replyid + ){ + return ApiResponse.onSuccess(repliesService.getreply(replyid)); + } + } diff --git a/src/main/java/com/example/blism/dto/request/RepliesRequestDTO.java b/src/main/java/com/example/blism/dto/request/RepliesRequestDTO.java index 1d59f49..071a29a 100644 --- a/src/main/java/com/example/blism/dto/request/RepliesRequestDTO.java +++ b/src/main/java/com/example/blism/dto/request/RepliesRequestDTO.java @@ -13,17 +13,12 @@ public class RepliesRequestDTO { @NoArgsConstructor @AllArgsConstructor public static class addreplyDTO{ - String photo_url; String content; Long letter_id; - String image_url; Integer font; Long sender_id; Long receiver_id; Long mailbox_id; - LocalDateTime created_at; - - } diff --git a/src/main/java/com/example/blism/dto/response/RepliesResponseDTO.java b/src/main/java/com/example/blism/dto/response/RepliesResponseDTO.java index 3111303..f028d45 100644 --- a/src/main/java/com/example/blism/dto/response/RepliesResponseDTO.java +++ b/src/main/java/com/example/blism/dto/response/RepliesResponseDTO.java @@ -14,6 +14,7 @@ public class RepliesResponseDTO { @NoArgsConstructor @AllArgsConstructor public static class allsentrepliesDTO{ + Long reply_id; Long letter_id; String content; Long receiver_id; @@ -27,6 +28,7 @@ public static class allsentrepliesDTO{ @NoArgsConstructor @AllArgsConstructor public static class allreceivedrepliesDTO{ + Long reply_id; Long letter_id; String content; Long sender_id; @@ -34,4 +36,23 @@ public static class allreceivedrepliesDTO{ LocalDateTime created_at; Integer font; } + + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class getreplyDTO{ + Long letter_id; + String content; + Long sender_id; + String sender_name; + Long receiver_id; + String receiver_name; + LocalDateTime created_at; + Integer font; + String photo_url; + } + + } diff --git a/src/main/java/com/example/blism/service/RepliesServiceImpl.java b/src/main/java/com/example/blism/service/RepliesServiceImpl.java index 9875fc1..1a24c52 100644 --- a/src/main/java/com/example/blism/service/RepliesServiceImpl.java +++ b/src/main/java/com/example/blism/service/RepliesServiceImpl.java @@ -36,7 +36,7 @@ public class RepliesServiceImpl { private final LetterRepository letterRepository; private final S3Service s3Service; - // ---------------------------- 사진 추가 ------------------ + @Transactional public Reply addreplies(MultipartFile image, RepliesRequestDTO.addreplyDTO request) { @@ -51,7 +51,7 @@ public Reply addreplies(MultipartFile image, RepliesRequestDTO.addreplyDTO reque Reply newReply = Reply.builder() .content(request.getContent()) .letter(letter) - .photoUrl(request.getPhoto_url()) + .photoUrl(photoUrl) .font(request.getFont()) .mailbox(mailbox) .sender(sender) @@ -62,7 +62,7 @@ public Reply addreplies(MultipartFile image, RepliesRequestDTO.addreplyDTO reque return repliesRepository.save(newReply); } - // ---------------------------- 사진 추가 ------------------ + @Transactional @@ -75,6 +75,7 @@ public List getAllSentReplies(Long senderI // JSON 형식으로 변환 return allReplies.stream() .map(reply -> RepliesResponseDTO.allsentrepliesDTO.builder() + .reply_id(reply.getId()) .content(reply.getContent()) .letter_id(reply.getLetter().getId()) .receiver_id(reply.getReceiver().getId()) @@ -86,7 +87,7 @@ public List getAllSentReplies(Long senderI } - // ----------------------------- <리스트 부분> --------------------------- + @@ -99,6 +100,7 @@ public List getAllReceivedReplies(Long return allReplies.stream() .map(reply -> RepliesResponseDTO.allreceivedrepliesDTO.builder() + .reply_id(reply.getId()) .content(reply.getContent()) .letter_id(reply.getLetter().getId()) .sender_name(reply.getSender().getNickname()) @@ -110,5 +112,24 @@ public List getAllReceivedReplies(Long } + @Transactional + public RepliesResponseDTO.getreplyDTO getreply(Long request) { + Reply reply = repliesRepository.findById(request).get(); + + + return RepliesResponseDTO.getreplyDTO.builder() + .content(reply.getContent()) + .letter_id(reply.getLetter().getId()) + .sender_id(reply.getSender().getId()) + .sender_name(reply.getSender().getNickname()) + .font(reply.getFont()) + .receiver_id(reply.getReceiver().getId()) + .receiver_name(reply.getReceiver().getNickname()) + .created_at(reply.getCreatedAt()) + .photo_url(reply.getPhotoUrl()) + .build(); + } + + }