diff --git a/src/main/java/com/salmalteam/salmal/comment/application/CommentService.java b/src/main/java/com/salmalteam/salmal/comment/application/CommentService.java index 94cf491..9d67130 100644 --- a/src/main/java/com/salmalteam/salmal/comment/application/CommentService.java +++ b/src/main/java/com/salmalteam/salmal/comment/application/CommentService.java @@ -10,12 +10,15 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import com.salmalteam.salmal.auth.entity.MemberPayLoad; +import com.salmalteam.salmal.comment.dto.request.CommentPageRequest; +import com.salmalteam.salmal.comment.dto.request.CommentReplyCreateRequest; +import com.salmalteam.salmal.comment.dto.request.ReplyPageRequest; +import com.salmalteam.salmal.comment.dto.response.CommentPageResponse; +import com.salmalteam.salmal.comment.dto.response.CommentResponse; import com.salmalteam.salmal.comment.dto.response.ReplayCommentDto; -import com.salmalteam.salmal.comment.exception.like.CommentLikeException; -import com.salmalteam.salmal.comment.exception.like.CommentLikeExceptionType; -import com.salmalteam.salmal.comment.exception.report.CommentReportException; -import com.salmalteam.salmal.comment.exception.report.CommentReportExceptionType; -import com.salmalteam.salmal.member.application.MemberService; +import com.salmalteam.salmal.comment.dto.response.ReplyPageResponse; +import com.salmalteam.salmal.comment.dto.response.ReplyResponse; import com.salmalteam.salmal.comment.entity.Comment; import com.salmalteam.salmal.comment.entity.CommentRepository; import com.salmalteam.salmal.comment.entity.CommentType; @@ -23,20 +26,17 @@ import com.salmalteam.salmal.comment.entity.like.CommentLikeRepository; import com.salmalteam.salmal.comment.entity.report.CommentReport; import com.salmalteam.salmal.comment.entity.report.CommentReportRepository; +import com.salmalteam.salmal.comment.exception.CommentException; +import com.salmalteam.salmal.comment.exception.CommentExceptionType; +import com.salmalteam.salmal.comment.exception.like.CommentLikeException; +import com.salmalteam.salmal.comment.exception.like.CommentLikeExceptionType; +import com.salmalteam.salmal.comment.exception.report.CommentReportException; +import com.salmalteam.salmal.comment.exception.report.CommentReportExceptionType; +import com.salmalteam.salmal.member.application.MemberService; import com.salmalteam.salmal.member.entity.Member; +import com.salmalteam.salmal.vote.dto.request.VoteCommentUpdateRequest; import com.salmalteam.salmal.vote.entity.Vote; import com.salmalteam.salmal.vote.entity.VoteRepository; -import com.salmalteam.salmal.comment.dto.request.CommentPageRequest; -import com.salmalteam.salmal.comment.dto.request.CommentReplyCreateRequest; -import com.salmalteam.salmal.comment.dto.request.ReplyPageRequest; -import com.salmalteam.salmal.vote.dto.request.VoteCommentUpdateRequest; -import com.salmalteam.salmal.comment.dto.response.CommentPageResponse; -import com.salmalteam.salmal.comment.dto.response.CommentResponse; -import com.salmalteam.salmal.comment.dto.response.ReplyPageResponse; -import com.salmalteam.salmal.comment.dto.response.ReplyResponse; -import com.salmalteam.salmal.comment.exception.CommentException; -import com.salmalteam.salmal.comment.exception.CommentExceptionType; -import com.salmalteam.salmal.auth.entity.MemberPayLoad; import lombok.RequiredArgsConstructor; @@ -81,21 +81,14 @@ private void validateDeleteAuthority(final Long commenterId, final Long requeste public ReplayCommentDto replyComment(final MemberPayLoad memberPayLoad, final Long commentId, final CommentReplyCreateRequest commentReplyCreateRequest) { - final Member member = memberService.findMemberById(memberPayLoad.getId()); - final Comment comment = getCommentById(commentId); - final Member commenterOwner = comment.getCommenter(); - - final Comment reply = Comment.ofReply(commentReplyCreateRequest.getContent(), comment, member); - + final Member replyer = memberService.findMemberById(memberPayLoad.getId()); //대댓글 작성자 + final Comment comment = getCommentById(commentId); //대댓글을 작성한 댓글(대댓글 주인) + final Comment reply = Comment.ofReply(commentReplyCreateRequest.getContent(), comment, replyer); //대댓글 + final Member commenterOwner = comment.getCommenter(); //댓글 주인 commentRepository.save(reply); commentRepository.increaseReplyCount(commentId); - return new ReplayCommentDto(commenterOwner.getId(), - member.getId(), - commentId, - member.getNickName().getValue(), - commentReplyCreateRequest.getContent() - ); + return ReplayCommentDto.createNotificationType(replyer, commenterOwner, comment, reply, comment.getVote()); } @Transactional(readOnly = true) diff --git a/src/main/java/com/salmalteam/salmal/comment/dto/response/ReplayCommentDto.java b/src/main/java/com/salmalteam/salmal/comment/dto/response/ReplayCommentDto.java index 785b643..fb16212 100644 --- a/src/main/java/com/salmalteam/salmal/comment/dto/response/ReplayCommentDto.java +++ b/src/main/java/com/salmalteam/salmal/comment/dto/response/ReplayCommentDto.java @@ -1,5 +1,9 @@ package com.salmalteam.salmal.comment.dto.response; +import com.salmalteam.salmal.comment.entity.Comment; +import com.salmalteam.salmal.member.entity.Member; +import com.salmalteam.salmal.vote.entity.Vote; + import lombok.AllArgsConstructor; import lombok.Getter; @@ -7,12 +11,27 @@ @Getter public class ReplayCommentDto { private final Long commentOwnerId; - private final Long commenterId; + private final Long replyerId; private final Long commentId; private final String nickName; private final String content; + private final String replyerImageUrl; + private final String VoteImageUrl; + + public static ReplayCommentDto createNotificationType(Member replyer, Member commenterOwner, Comment comment, Comment reply, + Vote vote) { + return new ReplayCommentDto( + commenterOwner.getId(), //알림 타켓 ID + replyer.getId(), //대댓글 작성자 + comment.getId(), //대댓글을 작성한 댓글 ID + replyer.getNickName().getValue(), //대댓글 작성자 ID + reply.getContent().getValue(), //대댓글 내용 + replyer.getMemberImage().getImageUrl(), //대댓글 작성자 이미지 + vote.getVoteImage().getImageUrl() //대댓글 작성한 투표의 이미지 + ); + } public boolean isSameCommenter() { - return commentOwnerId.equals(commenterId); + return commentOwnerId.equals(replyerId); } } diff --git a/src/main/java/com/salmalteam/salmal/comment/entity/CommentRepository.java b/src/main/java/com/salmalteam/salmal/comment/entity/CommentRepository.java index 4631f81..01ec2ed 100644 --- a/src/main/java/com/salmalteam/salmal/comment/entity/CommentRepository.java +++ b/src/main/java/com/salmalteam/salmal/comment/entity/CommentRepository.java @@ -11,7 +11,8 @@ public interface CommentRepository extends Repository, CommentRepositoryCustom { Comment save(Comment comment); void delete(Comment comment); - Optional findById(Long id); + @Query("select c from Comment c join fetch c.commenter join fetch c.vote where c.id =:id") + Optional findById(@Param("id") Long id); boolean existsById(Long id); List findAllByCommenter_Id(Long commenterId); List findALlByCommenter_idAndCommentType(Long commenterId, CommentType commentType); diff --git a/src/main/java/com/salmalteam/salmal/comment/entity/Content.java b/src/main/java/com/salmalteam/salmal/comment/entity/Content.java index fa4ff88..588ebc5 100644 --- a/src/main/java/com/salmalteam/salmal/comment/entity/Content.java +++ b/src/main/java/com/salmalteam/salmal/comment/entity/Content.java @@ -1,15 +1,18 @@ package com.salmalteam.salmal.comment.entity; +import javax.persistence.Column; +import javax.persistence.Embeddable; + import com.salmalteam.salmal.comment.exception.CommentException; import com.salmalteam.salmal.comment.exception.CommentExceptionType; + import lombok.AccessLevel; +import lombok.Getter; import lombok.NoArgsConstructor; -import javax.persistence.Column; -import javax.persistence.Embeddable; - @Embeddable @NoArgsConstructor(access = AccessLevel.PROTECTED) +@Getter public class Content { private static final int MAX_LENGTH = 100; diff --git a/src/main/java/com/salmalteam/salmal/member/application/MemberService.java b/src/main/java/com/salmalteam/salmal/member/application/MemberService.java index e892af2..4a43999 100644 --- a/src/main/java/com/salmalteam/salmal/member/application/MemberService.java +++ b/src/main/java/com/salmalteam/salmal/member/application/MemberService.java @@ -179,7 +179,7 @@ public void deleteImage(final MemberPayLoad memberPayLoad, final Long memberId) validateUpdateAuthority(member, targetMember); - member.updateImage(MemberImage.getMemberImageUrl()); + member.updateImage(MemberImage.getDefaultMemberImageUrl()); memberRepository.save(member); } diff --git a/src/main/java/com/salmalteam/salmal/member/entity/MemberImage.java b/src/main/java/com/salmalteam/salmal/member/entity/MemberImage.java index 34adca3..10918b6 100644 --- a/src/main/java/com/salmalteam/salmal/member/entity/MemberImage.java +++ b/src/main/java/com/salmalteam/salmal/member/entity/MemberImage.java @@ -1,11 +1,11 @@ package com.salmalteam.salmal.member.entity; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - import javax.persistence.Column; import javax.persistence.Embeddable; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + @Embeddable @NoArgsConstructor(access = AccessLevel.PROTECTED) public class MemberImage { @@ -25,8 +25,11 @@ public static MemberImage initMemberImage(){ return new MemberImage(MEMBER_IMAGE_URL); } - public static String getMemberImageUrl(){ + public static String getDefaultMemberImageUrl(){ return MEMBER_IMAGE_URL; } + public String getImageUrl(){ + return imageUrl; + } } diff --git a/src/main/java/com/salmalteam/salmal/notification/dto/response/NotificationDto.java b/src/main/java/com/salmalteam/salmal/notification/dto/response/NotificationDto.java index 8037cbd..5d4dbe7 100644 --- a/src/main/java/com/salmalteam/salmal/notification/dto/response/NotificationDto.java +++ b/src/main/java/com/salmalteam/salmal/notification/dto/response/NotificationDto.java @@ -16,11 +16,14 @@ public class NotificationDto { private final Long markId; private final Type type; private final String message; - @JsonFormat(pattern = "yy-MM-ddTHH:mm") + private final boolean isRead; + @JsonFormat(pattern = "yy-MM-dd'T'HH:mm:ss") private final LocalDateTime createAt; + private final String memberImageUrl; + private final String imageUrl; public static NotificationDto create(Notification notification) { return new NotificationDto(notification.getUuid(), notification.getMarkId(), notification.getType(), - notification.getMessage(), notification.getCreatedAt()); + notification.getMessage(), notification.isRead(), notification.getCreatedAt(), notification.getMemberImageUrl(), notification.getMarkContentImageUrl()); } } diff --git a/src/main/java/com/salmalteam/salmal/notification/entity/Notification.java b/src/main/java/com/salmalteam/salmal/notification/entity/Notification.java index 4c06f41..5fb0f9b 100644 --- a/src/main/java/com/salmalteam/salmal/notification/entity/Notification.java +++ b/src/main/java/com/salmalteam/salmal/notification/entity/Notification.java @@ -32,9 +32,13 @@ public class Notification extends BaseCreatedTimeEntity { @Enumerated(value = EnumType.STRING) private Type type; private boolean isRead; + private String memberImageUrl; + private String markContentImageUrl; - public static Notification createNewReplyType(Long memberId, Long markId, UUID uuid, String message) { - return new Notification(null, memberId, uuid.toString(), message, markId, Type.REPLY, false); + public static Notification createNewReplyType(Long memberId, Long markId, UUID uuid, String message, + String memberImageUrl, String markContentImageUrl) { + return new Notification(null, memberId, uuid.toString(), message, markId, Type.REPLY, false, memberImageUrl, + markContentImageUrl); } public void read() { diff --git a/src/main/java/com/salmalteam/salmal/notification/service/NotificationService.java b/src/main/java/com/salmalteam/salmal/notification/service/NotificationService.java index efc9930..4b986d2 100644 --- a/src/main/java/com/salmalteam/salmal/notification/service/NotificationService.java +++ b/src/main/java/com/salmalteam/salmal/notification/service/NotificationService.java @@ -54,7 +54,8 @@ private void validateMember(Long memberId) { } @Transactional - public MessageSpec save(Long targetId, Long issuedContentId, String nickName, String content, Long memberId) { + public MessageSpec save(Long targetId, Long issuedContentId, String nickName, String content, Long memberId, + String memberImageUrl, String contentImageUrl) { String message = String.format("%s님의 답댓글:%s", nickName, content); @@ -63,7 +64,8 @@ public MessageSpec save(Long targetId, Long issuedContentId, String nickName, St .orElse("token"); Notification notification = notificationRepository.save( - Notification.createNewReplyType(memberId, issuedContentId, uuidGenerator.generate(), message)); + Notification.createNewReplyType(memberId, issuedContentId, uuidGenerator.generate(), message, + memberImageUrl, contentImageUrl)); HashMap data = new HashMap<>(); diff --git a/src/main/java/com/salmalteam/salmal/presentation/http/comment/CommentController.java b/src/main/java/com/salmalteam/salmal/presentation/http/comment/CommentController.java index 124fbe7..f02ef87 100644 --- a/src/main/java/com/salmalteam/salmal/presentation/http/comment/CommentController.java +++ b/src/main/java/com/salmalteam/salmal/presentation/http/comment/CommentController.java @@ -94,7 +94,8 @@ public void replyComment(@LoginMember final MemberPayLoad memberPayLoad, } MessageSpec messageSpec = notificationService.save( replayComment.getCommentOwnerId(), replayComment.getCommentId(), - replayComment.getNickName(),replayComment.getContent(), replayComment.getCommenterId()); + replayComment.getNickName(), replayComment.getContent(), replayComment.getReplyerId(), + replayComment.getReplyerImageUrl(), replayComment.getVoteImageUrl()); notificationPublisher.pub(messageSpec); } diff --git a/src/main/java/com/salmalteam/salmal/vote/entity/VoteImage.java b/src/main/java/com/salmalteam/salmal/vote/entity/VoteImage.java index 0045368..752d172 100644 --- a/src/main/java/com/salmalteam/salmal/vote/entity/VoteImage.java +++ b/src/main/java/com/salmalteam/salmal/vote/entity/VoteImage.java @@ -1,13 +1,15 @@ package com.salmalteam.salmal.vote.entity; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - import javax.persistence.Column; import javax.persistence.Embeddable; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + @Embeddable @NoArgsConstructor(access = AccessLevel.PROTECTED) +@Getter public class VoteImage { @Column(name = "image_url") diff --git a/src/test/java/com/salmalteam/salmal/presentation/comment/CommentControllerTest.java b/src/test/java/com/salmalteam/salmal/presentation/comment/CommentControllerTest.java index 43bf20e..eee9c63 100644 --- a/src/test/java/com/salmalteam/salmal/presentation/comment/CommentControllerTest.java +++ b/src/test/java/com/salmalteam/salmal/presentation/comment/CommentControllerTest.java @@ -249,7 +249,7 @@ class 대댓글_생성_테스트{ final Long commentId = 1L; final String content = "이 댓글에 동의합니다!"; final CommentReplyCreateRequest commentReplyCreateRequest = new CommentReplyCreateRequest(content); - ReplayCommentDto replayCommentDto = new ReplayCommentDto(100L, 20L, 556L, "kim", "content"); + ReplayCommentDto replayCommentDto = new ReplayCommentDto(100L, 20L, 556L, "kim", "content","url","url"); given(commentService.replyComment(any(),anyLong(),any())) .willReturn(replayCommentDto); mockingForAuthorization(); @@ -276,7 +276,8 @@ class 대댓글_생성_테스트{ )); verify(commentService, times(1)).replyComment(any(), any(), any()); - verify(notificationService, times(1)).save(anyLong(),anyLong(),anyString(),anyString(),anyLong()); + verify(notificationService, times(1)).save(anyLong(),anyLong(),anyString(),anyString(),anyLong(), + anyString(), anyString()); verify(fcmClient, times(1)).pub(any()); }