Skip to content

Commit

Permalink
Refactoring:알림조회 변경 (#154)
Browse files Browse the repository at this point in the history
* refactor: 멤버 image url 반환메서드 분리

* refactor: getter 추가

* refactor: ReplayCommentDto 생성메서드 구현, dto 필드변경(회원 이미지와 투표이미지 추가를 위한 파라미터 변경), 대댓글주인 replyer 로 네이밍 변경

* refactor: 대댓글주인 replyer 로 네이밍 변경

* refactor: Notification 회원 이미지 url, 컨탠츠 이미지 url 컬럼(필드) 추가, 알림저장 메서드 이미지 url 파라미터 추가

* refactor: 알림 조회시 읽음상태, 회원 이미지 url, 컨텐츠(투표) 이미지 url 응답 추가

* fix: NotificationDto createAt format 문법오류 수정

* fix: 댓글 조회시 패치조인으로 가져오게 변경

* fix: dto 이미지 파라미터 잘못된값 주는거 수정

* fix: 알림 응답 시간 초 추가
  • Loading branch information
kimJH47 authored Jan 31, 2024
1 parent 4a15ef1 commit fa74588
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@
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;
import com.salmalteam.salmal.comment.entity.like.CommentLike;
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;

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
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;

@AllArgsConstructor
@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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
public interface CommentRepository extends Repository<Comment, Long>, CommentRepositoryCustom {
Comment save(Comment comment);
void delete(Comment comment);
Optional<Comment> findById(Long id);
@Query("select c from Comment c join fetch c.commenter join fetch c.vote where c.id =:id")
Optional<Comment> findById(@Param("id") Long id);
boolean existsById(Long id);
List<Comment> findAllByCommenter_Id(Long commenterId);
List<Comment> findALlByCommenter_idAndCommentType(Long commenterId, CommentType commentType);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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<String, String> data = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());

}
Expand Down

0 comments on commit fa74588

Please sign in to comment.