Skip to content

Commit

Permalink
Merge pull request #210 from prgrms-web-devcourse-final-project/develop
Browse files Browse the repository at this point in the history
CI-CD
  • Loading branch information
l2yujw authored Dec 9, 2024
2 parents ed89acd + 6137603 commit ce0377c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,12 +85,13 @@ public ApiResponse<PageResponseDTO<ReplyLetterHeadersResponseDTO>> getReplyForLe
description = "지정된 답장 편지의 ID에 대한 상세 정보를 반환합니다."
)
@GetMapping("/detail/{replyLetterId}")
public ApiResponse<ReplyLetterResponseDTO> getReplyLetter(
public ApiResponse<ReplyLetterDetailResponseDTO> 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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public interface ReplyLetterJpaRepository extends JpaRepository<ReplyLetterEntit
void blockById(Long id);

boolean existsByLetterIdAndSenderId(Long letterId, Long senderId);

boolean existsByIdAndSenderId(Long id, Long senderId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ public void blockReplyLetterById(Long replyLetterId) {
public boolean existsByLetterIdAndSenderId(Long letterId, Long senderId) {
return replyLetterJpaRepository.existsByLetterIdAndSenderId(letterId, senderId);
}

@Override
public boolean existsByIdAndSenderId(Long replyLetterId, Long userId) {
return replyLetterJpaRepository.existsByIdAndSenderId(replyLetterId, userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public interface ReplyLetterRepository {
void blockReplyLetterById(Long replyLetterId);

boolean existsByLetterIdAndSenderId(Long letterId, Long senderId);

boolean existsByIdAndSenderId(Long replyLetterId, Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import postman.bottler.letter.dto.ReceiverDTO;
import postman.bottler.letter.dto.request.PageRequestDTO;
import postman.bottler.letter.dto.request.ReplyLetterRequestDTO;
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.DuplicateReplyLetterException;
Expand Down Expand Up @@ -81,9 +82,10 @@ public Page<ReplyLetterHeadersResponseDTO> 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
Expand Down

0 comments on commit ce0377c

Please sign in to comment.