diff --git a/src/main/java/postman/bottler/letter/controller/ReplyLetterController.java b/src/main/java/postman/bottler/letter/controller/ReplyLetterController.java index 262716a6..dbd8a3d2 100644 --- a/src/main/java/postman/bottler/letter/controller/ReplyLetterController.java +++ b/src/main/java/postman/bottler/letter/controller/ReplyLetterController.java @@ -21,6 +21,7 @@ import postman.bottler.letter.dto.request.ReplyLetterDeleteRequestDTO; import postman.bottler.letter.dto.request.ReplyLetterRequestDTO; import postman.bottler.letter.dto.response.PageResponseDTO; +import postman.bottler.letter.dto.response.ReplyLetterDetailResponseDTO; import postman.bottler.letter.dto.response.ReplyLetterHeadersResponseDTO; import postman.bottler.letter.dto.response.ReplyLetterResponseDTO; import postman.bottler.letter.exception.InvalidPageRequestException; @@ -84,12 +85,13 @@ public ApiResponse> getReplyForLe description = "지정된 답장 편지의 ID에 대한 상세 정보를 반환합니다." ) @GetMapping("/detail/{replyLetterId}") - public ApiResponse getReplyLetter( + public ApiResponse getReplyLetter( @PathVariable Long replyLetterId, @AuthenticationPrincipal CustomUserDetails userDetails ) { letterBoxService.validateLetterInUserBox(replyLetterId, userDetails.getUserId()); - ReplyLetterResponseDTO result = letterReplyService.getReplyLetterDetail(replyLetterId); + ReplyLetterDetailResponseDTO result = letterReplyService.getReplyLetterDetail(replyLetterId, + userDetails.getUserId()); return ApiResponse.onSuccess(result); } diff --git a/src/main/java/postman/bottler/letter/dto/response/ReplyLetterDetailResponseDTO.java b/src/main/java/postman/bottler/letter/dto/response/ReplyLetterDetailResponseDTO.java new file mode 100644 index 00000000..e34a3d72 --- /dev/null +++ b/src/main/java/postman/bottler/letter/dto/response/ReplyLetterDetailResponseDTO.java @@ -0,0 +1,26 @@ +package postman.bottler.letter.dto.response; + +import java.time.LocalDateTime; +import postman.bottler.letter.domain.ReplyLetter; + +public record ReplyLetterDetailResponseDTO( + Long replyLetterId, + String content, + String font, + String paper, + String label, + boolean isReplied, + LocalDateTime createdAt +) { + public static ReplyLetterDetailResponseDTO from(ReplyLetter replyLetter, boolean isReplied) { + return new ReplyLetterDetailResponseDTO( + replyLetter.getId(), + replyLetter.getContent(), + replyLetter.getFont(), + replyLetter.getPaper(), + replyLetter.getLabel(), + isReplied, + replyLetter.getCreatedAt() + ); + } +} diff --git a/src/main/java/postman/bottler/letter/infra/ReplyLetterJpaRepository.java b/src/main/java/postman/bottler/letter/infra/ReplyLetterJpaRepository.java index f44f9799..0b1914b9 100644 --- a/src/main/java/postman/bottler/letter/infra/ReplyLetterJpaRepository.java +++ b/src/main/java/postman/bottler/letter/infra/ReplyLetterJpaRepository.java @@ -26,4 +26,6 @@ public interface ReplyLetterJpaRepository extends JpaRepository getReplyLetterHeadersById( } @Transactional(readOnly = true) - public ReplyLetterResponseDTO getReplyLetterDetail(Long replyLetterId) { + public ReplyLetterDetailResponseDTO getReplyLetterDetail(Long replyLetterId, Long userId) { + boolean isReplied = replyLetterRepository.existsByIdAndSenderId(replyLetterId, userId); ReplyLetter replyLetter = findReplyLetter(replyLetterId); - return ReplyLetterResponseDTO.from(replyLetter); + return ReplyLetterDetailResponseDTO.from(replyLetter, isReplied); } @Transactional