diff --git a/src/main/java/foregg/foreggserver/converter/NotificationConverter.java b/src/main/java/foregg/foreggserver/converter/NotificationConverter.java index 7c8e86d..70809b3 100644 --- a/src/main/java/foregg/foreggserver/converter/NotificationConverter.java +++ b/src/main/java/foregg/foreggserver/converter/NotificationConverter.java @@ -3,7 +3,6 @@ import foregg.foreggserver.domain.Notification; import foregg.foreggserver.domain.Reply; import foregg.foreggserver.domain.enums.NotificationType; -import foregg.foreggserver.dto.notificationDTO.NotificationResponseDTO; import foregg.foreggserver.dto.notificationDTO.NotificationResponseDTO.NotificationDTO; import foregg.foreggserver.util.DateUtil; @@ -33,9 +32,9 @@ public static List toNotificationResponse(List no for (Notification notification : notificationList) { NotificationDTO dto = NotificationDTO.builder() .id(notification.getId()) - .targetKey(notification.getChallengeId().toString()) + .targetKey(notification.getTargetId().toString()) .notificationType(notification.getNotificationType()) - .sender(notification.getSender().getNickname()) + .sender(notification.getSender()) .elapsedTime(DateUtil.getElapsedTime(notification.getCreatedAt())) .createdAt(notification.getCreatedAt().toString()) .build(); diff --git a/src/main/java/foregg/foreggserver/domain/Notification.java b/src/main/java/foregg/foreggserver/domain/Notification.java index 8eb3eb4..3e3d995 100644 --- a/src/main/java/foregg/foreggserver/domain/Notification.java +++ b/src/main/java/foregg/foreggserver/domain/Notification.java @@ -19,9 +19,8 @@ public class Notification extends BaseEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "sender_id") - private User sender; + @Column(nullable = false) + private String sender; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "receiver_id") @@ -34,6 +33,6 @@ public class Notification extends BaseEntity { private NotificationType notificationType; @Column(nullable = false) - private Long challengeId; + private Long targetId; } diff --git a/src/main/java/foregg/foreggserver/repository/NotificationRepository.java b/src/main/java/foregg/foreggserver/repository/NotificationRepository.java index 010c467..3981596 100644 --- a/src/main/java/foregg/foreggserver/repository/NotificationRepository.java +++ b/src/main/java/foregg/foreggserver/repository/NotificationRepository.java @@ -11,9 +11,10 @@ public interface NotificationRepository extends JpaRepository findBySenderAndReceiverAndDate(User sender, User receiver, String date); - Notification findBySenderAndReceiverAndDateAndNotificationType(User sender, User receiver, String date, NotificationType notificationType); + Notification findBySenderAndReceiverAndDateAndNotificationType(String senderNickname, User receiver, String date, NotificationType notificationType); - List findBySenderAndDateAndNotificationType(User sender, String date, NotificationType notificationType); + List findBySenderAndDateAndNotificationType(String senderNickname, String date, NotificationType notificationType); List findByReceiver(User receiver); + } diff --git a/src/main/java/foregg/foreggserver/service/challengeService/ChallengeQueryService.java b/src/main/java/foregg/foreggserver/service/challengeService/ChallengeQueryService.java index 75c9195..bcd05eb 100644 --- a/src/main/java/foregg/foreggserver/service/challengeService/ChallengeQueryService.java +++ b/src/main/java/foregg/foreggserver/service/challengeService/ChallengeQueryService.java @@ -99,9 +99,9 @@ public List getParticipants(Long challengeId, boolean for (ChallengeParticipation cp : challengeParticipations) { Notification notification; if (isSuccess) { - notification = notificationRepository.findBySenderAndReceiverAndDateAndNotificationType(currentUser, cp.getUser(), LocalDate.now().toString(), NotificationType.CLAP); + notification = notificationRepository.findBySenderAndReceiverAndDateAndNotificationType(currentUser.getChallengeName(), cp.getUser(), LocalDate.now().toString(), NotificationType.CLAP); } else { - notification = notificationRepository.findBySenderAndReceiverAndDateAndNotificationType(currentUser, cp.getUser(), LocalDate.now().toString(), NotificationType.SUPPORT); + notification = notificationRepository.findBySenderAndReceiverAndDateAndNotificationType(currentUser.getChallengeName(), cp.getUser(), LocalDate.now().toString(), NotificationType.SUPPORT); } if (notification == null) { result.add(ChallengeConverter.toChallengeParticipantDTO(cp, false)); diff --git a/src/main/java/foregg/foreggserver/service/challengeService/ChallengeService.java b/src/main/java/foregg/foreggserver/service/challengeService/ChallengeService.java index 64e2e83..3d4c797 100644 --- a/src/main/java/foregg/foreggserver/service/challengeService/ChallengeService.java +++ b/src/main/java/foregg/foreggserver/service/challengeService/ChallengeService.java @@ -173,16 +173,16 @@ public void cheer(Long receiverId, NotificationType type, Long challengeId) { catchCheerException(challengeParticipation, type); - List notificationList = notificationRepository.findBySenderAndDateAndNotificationType(sender, LocalDate.now().toString(), type); + List notificationList = notificationRepository.findBySenderAndDateAndNotificationType(sender.getChallengeName(), LocalDate.now().toString(), type); if (notificationList.size() >= 3) { throw new ChallengeHandler(NO_MORE_THAN_THIRD_TIME); } - if (notificationRepository.findBySenderAndReceiverAndDateAndNotificationType(sender, receiver, LocalDate.now().toString(), type) != null) { + if (notificationRepository.findBySenderAndReceiverAndDateAndNotificationType(sender.getChallengeName(), receiver, LocalDate.now().toString(), type) != null) { throw new ChallengeHandler(ALREADY_SEND_CHEER); } - Notification notification = notificationService.createNotification(type, receiver, sender, challengeId); + Notification notification = notificationService.createNotification(type, receiver, sender.getChallengeName(), challengeId); notificationRepository.save(notification); } diff --git a/src/main/java/foregg/foreggserver/service/dailyService/DailyService.java b/src/main/java/foregg/foreggserver/service/dailyService/DailyService.java index 582e065..aefc961 100644 --- a/src/main/java/foregg/foreggserver/service/dailyService/DailyService.java +++ b/src/main/java/foregg/foreggserver/service/dailyService/DailyService.java @@ -6,16 +6,19 @@ import foregg.foreggserver.converter.DailyConverter; import foregg.foreggserver.domain.*; import foregg.foreggserver.domain.Record; +import foregg.foreggserver.domain.enums.NotificationType; import foregg.foreggserver.dto.dailyDTO.DailyRequestDTO; import foregg.foreggserver.dto.dailyDTO.DailyRequestDTO.DailyReplyRequestDTO; import foregg.foreggserver.dto.dailyDTO.SideEffectRequestDTO; import foregg.foreggserver.dto.dailyDTO.SideEffectResponseDTO; import foregg.foreggserver.jwt.SecurityUtil; import foregg.foreggserver.repository.DailyRepository; +import foregg.foreggserver.repository.NotificationRepository; import foregg.foreggserver.repository.ReplyRepository; import foregg.foreggserver.repository.SideEffectRepository; import foregg.foreggserver.service.fcmService.FcmService; import foregg.foreggserver.service.myPageService.MyPageQueryService; +import foregg.foreggserver.service.notificationService.NotificationService; import foregg.foreggserver.service.recordService.RecordQueryService; import foregg.foreggserver.service.s3Service.S3Service; import foregg.foreggserver.service.userService.UserQueryService; @@ -48,6 +51,8 @@ public class DailyService { private final MyPageQueryService myPageQueryService; private final S3Service s3Service; private final ReplyRepository replyRepository; + private final NotificationService notificationService; + private final NotificationRepository notificationRepository; public void writeDaily(DailyRequestDTO dto, String imageUrl) { User user = userQueryService.getUser(); @@ -94,6 +99,8 @@ public void reply(DailyReplyRequestDTO dto) { .build(); replyRepository.save(reply); daily.setReply(reply); + Notification notification = notificationService.createNotification(NotificationType.REPLY, wife, userQueryService.getUser().getNickname(), daily.getId()); + notificationRepository.save(notification); } public void writeSideEffect(SideEffectRequestDTO dto) { diff --git a/src/main/java/foregg/foreggserver/service/notificationService/NotificationService.java b/src/main/java/foregg/foreggserver/service/notificationService/NotificationService.java index d1f2bb5..8b10625 100644 --- a/src/main/java/foregg/foreggserver/service/notificationService/NotificationService.java +++ b/src/main/java/foregg/foreggserver/service/notificationService/NotificationService.java @@ -182,13 +182,13 @@ public void cancelScheduledTasks(Long recordId) { } //알림 만드는 로직 - public Notification createNotification(NotificationType notificationType, User receiver, User sender, Long challengeId) { + public Notification createNotification(NotificationType notificationType, User receiver, String sender, Long targetId) { return Notification.builder() .notificationType(notificationType) .receiver(receiver) .sender(sender) .date(LocalDate.now().toString()) - .challengeId(challengeId) + .targetId(targetId) .build(); }