Skip to content

Commit

Permalink
[Refactor/#308] roll back notification response of follow & add notif…
Browse files Browse the repository at this point in the history
…ication type of reply
  • Loading branch information
Han-Jeong committed Jun 20, 2024
1 parent 082df60 commit 4ad4769
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.example.waggle.domain.notification.persistence.dao.NotificationRepository;
import com.example.waggle.domain.notification.persistence.entity.Notification;
import com.example.waggle.domain.notification.persistence.entity.NotificationType;
import com.example.waggle.domain.notification.presentation.dto.NotificationRequest.ReplyDto;
import com.example.waggle.exception.object.handler.CommentHandler;
import com.example.waggle.exception.object.handler.MemberHandler;
import com.example.waggle.exception.object.handler.ReplyHandler;
Expand Down Expand Up @@ -48,6 +49,8 @@ public Long createReply(Long commentId, ReplyRequest createReplyRequest, Member

//MENTION
List<Notification> notificationList = buildNotificationListByMention(reply, buildMentionDto(reply));
//REPLY
notificationList.add(buildNotificationByReply(reply, buildReplyDto(reply)));
notificationRepository.saveAll(notificationList);
return reply.getId();
}
Expand Down Expand Up @@ -94,6 +97,16 @@ private static Reply buildReply(Comment comment, ReplyRequest createReplyRequest
.build();
}

private Notification buildNotificationByReply(Reply reply, ReplyDto content) {
return Notification.builder()
.sender(reply.getMember())
.receiver(reply.getComment().getMember())
.isRead(false)
.type(NotificationType.REPLY)
.content(ObjectUtil.serialize(content))
.build();
}

private List<Notification> buildNotificationListByMention(Reply reply, MentionDto content) {
return ParseUtil.parsingUserUrl(reply)
.stream()
Expand All @@ -114,4 +127,11 @@ private MentionDto buildMentionDto(Reply reply) {
.conversationContent(reply.getContent())
.build();
}

private ReplyDto buildReplyDto(Reply reply) {
return ReplyDto.builder()
.commentContent(reply.getComment().getContent())
.replyContent(reply.getContent())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
import com.example.waggle.domain.notification.persistence.dao.NotificationRepository;
import com.example.waggle.domain.notification.persistence.entity.Notification;
import com.example.waggle.domain.notification.persistence.entity.NotificationType;
import com.example.waggle.domain.notification.presentation.dto.NotificationRequest.FollowDto;
import com.example.waggle.exception.object.handler.FollowHandler;
import com.example.waggle.exception.object.handler.MemberHandler;
import com.example.waggle.exception.payload.code.ErrorStatus;
import com.example.waggle.global.util.ObjectUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -33,9 +31,7 @@ public Long follow(Member from, String to) {
validateFollowing(from, followee);
Follow follow = buildFollow(from, followee);
followRepository.save(follow);
notificationRepository.save(buildNotification(
follow,
buildFollowDto(followee)));
notificationRepository.save(buildNotification(follow));
return follow.getId();
}

Expand Down Expand Up @@ -66,16 +62,12 @@ private static Follow buildFollow(Member member, Member followee) {
.build();
}

private static FollowDto buildFollowDto(Member followee) {
return FollowDto.builder().followeeNickname(followee.getNickname()).build();
}

private static Notification buildNotification(Follow follow, FollowDto content) {
private static Notification buildNotification(Follow follow) {
return Notification.builder()
.sender(follow.getFromMember())
.receiver(follow.getToMember())
.isRead(false)
.content(ObjectUtil.serialize(content))
.content(null)
.type(NotificationType.FOLLOWED)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


public enum NotificationType {
MENTIONED, FOLLOWED, PARTICIPATION_REQUEST, PARTICIPATION_APPROVE, COMMENT;
MENTIONED, FOLLOWED, PARTICIPATION_REQUEST, PARTICIPATION_APPROVE, COMMENT, REPLY
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ public static class CommentDto {
@Schema
@NoArgsConstructor
@AllArgsConstructor
public static class MentionDto {
private String conversationContent;
public static class ReplyDto {
private String commentContent;
private String replyContent;
}

@Data
@Builder
@Schema
@NoArgsConstructor
@AllArgsConstructor
public static class FollowDto {
private String followeeNickname;
public static class MentionDto {
private String conversationContent;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static Object deserializeNotificationContent(Notification notification) {
deserialize(notification.getContent(), NotificationRequest.ParticipationDto.class);
case COMMENT -> deserialize(notification.getContent(), NotificationRequest.CommentDto.class);
case MENTIONED -> deserialize(notification.getContent(), NotificationRequest.MentionDto.class);
case REPLY -> deserialize(notification.getContent(), NotificationRequest.ReplyDto.class);
case FOLLOWED -> null;
default -> throw new NotificationHandler(ErrorStatus.NOTIFICATION_TYPE_INVALID);
};
Expand Down

0 comments on commit 4ad4769

Please sign in to comment.