diff --git a/src/main/java/com/depromeet/domain/follow/application/FollowService.java b/src/main/java/com/depromeet/domain/follow/application/FollowService.java index f02e83666..c23ac9b5f 100644 --- a/src/main/java/com/depromeet/domain/follow/application/FollowService.java +++ b/src/main/java/com/depromeet/domain/follow/application/FollowService.java @@ -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); } diff --git a/src/main/java/com/depromeet/domain/notification/application/NotificationService.java b/src/main/java/com/depromeet/domain/notification/application/NotificationService.java index f73ad4b53..a516903cf 100644 --- a/src/main/java/com/depromeet/domain/notification/application/NotificationService.java +++ b/src/main/java/com/depromeet/domain/notification/application/NotificationService.java @@ -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); } @@ -79,7 +82,13 @@ public List findAllNotification() { .map( notification -> NotificationFindAllResponse.of( + notification.getId(), notification.getNotificationType(), + notification.getResourceId(), + getNotificationMessage( + notification.getNotificationType(), + notification.getSourceMember(), + notification.getTargetMember()), notification.getCreatedAt())) .collect(Collectors.toList()); } @@ -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); + } + } } diff --git a/src/main/java/com/depromeet/domain/notification/domain/Notification.java b/src/main/java/com/depromeet/domain/notification/domain/Notification.java index e5b92f27a..2be70a185 100644 --- a/src/main/java/com/depromeet/domain/notification/domain/Notification.java +++ b/src/main/java/com/depromeet/domain/notification/domain/Notification.java @@ -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(); } } diff --git a/src/main/java/com/depromeet/domain/notification/dto/NotificationFindAllResponse.java b/src/main/java/com/depromeet/domain/notification/dto/NotificationFindAllResponse.java index ffac7c406..1a550239f 100644 --- a/src/main/java/com/depromeet/domain/notification/dto/NotificationFindAllResponse.java +++ b/src/main/java/com/depromeet/domain/notification/dto/NotificationFindAllResponse.java @@ -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); } } diff --git a/src/main/java/com/depromeet/global/error/exception/ErrorCode.java b/src/main/java/com/depromeet/global/error/exception/ErrorCode.java index 96100e812..a2060febc 100644 --- a/src/main/java/com/depromeet/global/error/exception/ErrorCode.java +++ b/src/main/java/com/depromeet/global/error/exception/ErrorCode.java @@ -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, "해당 리액션을 찾을 수 없습니다."),