Skip to content

Commit

Permalink
feat: 알림센터 Message추가와 클릭 시 대상으로 이동할 수 있도록 자원 ID와 추가 (#410)
Browse files Browse the repository at this point in the history
* feat: 알림센터 Message추가와 클릭 시 대상으로 이동할 수 있도록 자원 ID와 추가

* style: spotless
  • Loading branch information
kdomo authored Jun 17, 2024
1 parent 4ad8b81 commit dcbe752
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ public void createFollow(FollowCreateRequest request) {
String.format(PUSH_SERVICE_CONTENT, currentMember.getProfile().getNickname()));
Notification notification =
Notification.createNotification(
NotificationType.FOLLOW, currentMember, targetMember);
NotificationType.FOLLOW,
currentMember,
targetMember,
currentMember.getId());
notificationRepository.save(notification);
memberRelationRepository.save(memberRelation);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public void sendUrgingPush(PushUrgingSendRequest request) {
mission.getName()));
Notification notification =
Notification.createNotification(
NotificationType.MISSION_URGING, currentMember, targetMember);
NotificationType.MISSION_URGING,
currentMember,
targetMember,
mission.getId());
notificationRepository.save(notification);
}

Expand All @@ -79,7 +82,13 @@ public List<NotificationFindAllResponse> findAllNotification() {
.map(
notification ->
NotificationFindAllResponse.of(
notification.getId(),
notification.getNotificationType(),
notification.getResourceId(),
getNotificationMessage(
notification.getNotificationType(),
notification.getSourceMember(),
notification.getTargetMember()),
notification.getCreatedAt()))
.collect(Collectors.toList());
}
Expand All @@ -101,4 +110,19 @@ private void validateSelfSending(Long currentMemberId, Long targetMemberId) {
throw new CustomException(ErrorCode.SELF_SENDING_NOT_ALLOWED);
}
}

private String getNotificationMessage(
NotificationType notificationType, Member sourceMember, Member targetMember) {
switch (notificationType) {
case FOLLOW:
return String.format(PUSH_SERVICE_CONTENT, sourceMember.getProfile().getNickname());
case MISSION_URGING:
return String.format(
PUSH_URGING_CONTENT,
sourceMember.getProfile().getNickname(),
targetMember.getProfile().getNickname());
default:
throw new CustomException(ErrorCode.NOTIFICATION_TYPE_NOT_FOUND);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,30 @@ public class Notification extends BaseTimeEntity {
@JoinColumn(name = "target_id")
private Member targetMember;

private Long resourceId;

@Builder(access = AccessLevel.PRIVATE)
private Notification(
NotificationType notificationType, Member sourceMember, Member targetMember) {
NotificationType notificationType,
Member sourceMember,
Member targetMember,
Long resourceId) {
this.notificationType = notificationType;
this.sourceMember = sourceMember;
this.targetMember = targetMember;
this.resourceId = resourceId;
}

public static Notification createNotification(
NotificationType notificationType, Member currentMember, Member targetMember) {
NotificationType notificationType,
Member currentMember,
Member targetMember,
Long resourceId) {
return Notification.builder()
.notificationType(notificationType)
.sourceMember(currentMember)
.targetMember(targetMember)
.resourceId(resourceId)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@
import java.time.LocalDateTime;

public record NotificationFindAllResponse(
@Schema(description = "알림 ID") Long notificationId,
@Schema(description = "알림 타입") NotificationType notificationType,
@Schema(description = "자원 ID") Long resourceId,
@Schema(description = "알림 메시지") String message,
@Schema(description = "알림 날짜") LocalDateTime createdAt) {

public static NotificationFindAllResponse of(
NotificationType notificationType, LocalDateTime createdAt) {
return new NotificationFindAllResponse(notificationType, createdAt);
Long notificationId,
NotificationType notificationType,
Long resourceId,
String message,
LocalDateTime createdAt) {
return new NotificationFindAllResponse(
notificationId, notificationType, resourceId, message, createdAt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public enum ErrorCode {
TODAY_COMPLETED_MISSION_SENDING_NOT_ALLOWED(
HttpStatus.BAD_REQUEST, "오늘 미션을 완료한 미션에는 메세지를 전송할 수 없습니다."),
FINISHED_MISSION_URGING_NOT_ALLOWED(HttpStatus.BAD_REQUEST, "종료된 미션에는 재촉하기를 할 수 없습니다."),
NOTIFICATION_TYPE_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 알림 타입을 찾을 수 없습니다."),

// Reaction
REACTION_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 리액션을 찾을 수 없습니다."),
Expand Down

0 comments on commit dcbe752

Please sign in to comment.