Skip to content

Commit

Permalink
♻️ 쪽지 답장 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdals4716 committed Nov 1, 2024
1 parent fea92cf commit 0a84ab4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/com/example/moyeothon/Service/MessageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ public MessageDTO replyMessage(Long messageId, String uid, Long bucketListId, Me
UserEntity sender = userRepository.findByUid(uid);
UserEntity receiver = originalMessage.getSender();
BucketlistEntity bucketList = bucketRepository.findById(bucketListId).orElseThrow();
if (!bucketList.getUser().getUid().equals(receiver.getUid())) {
throw new RuntimeException("해당 버킷리스트의 생성자에게만 쪽지를 답장할 수 있습니다.");
// 원본 쪽지가 해당 버킷리스트에서 생성된 쪽지인지 확인
if (!originalMessage.getBucketList().getId().equals(bucketListId)) {
throw new RuntimeException("해당 버킷리스트에서 생성된 쪽지에만 답장할 수 있습니다.");
}
// 원본 쪽지의 발신자에게만 답장을 허용
if (!originalMessage.getReceiver().getUid().equals(uid)) {
throw new RuntimeException("원본 쪽지의 발신자에게만 답장을 보낼 수 있습니다.");
}
MessageEntity messageEntity = messageDTO.dtoToEntity(sender, receiver, bucketList);
messageEntity.setCreateTime(LocalDateTime.now());
Expand All @@ -64,6 +69,7 @@ public MessageDTO replyMessage(Long messageId, String uid, Long bucketListId, Me
return MessageDTO.entityToDTO(messageRepository.save(messageEntity));
}


// 쪽지 읽음 상태로 변경
public MessageDTO readMessage(Long messageId, String uid, UserDetails userDetails) {
if (!userDetails.getUsername().equals(uid)) {
Expand Down

0 comments on commit 0a84ab4

Please sign in to comment.