From 7619f438e01cfe8793d4dacfe05c1532bd5b237b Mon Sep 17 00:00:00 2001 From: hansol Date: Wed, 14 Feb 2024 01:12:43 +0900 Subject: [PATCH 1/2] ADD: add new conditions for query for scheduled event alarm --- .../noti/NotificationController.java | 1 - .../noti/NotificationTargetRepository.java | 23 +++++++++++++++---- .../service/noti/NotificationMainService.java | 7 ++++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/peer/backend/controller/noti/NotificationController.java b/src/main/java/peer/backend/controller/noti/NotificationController.java index aea44e36..e5218014 100644 --- a/src/main/java/peer/backend/controller/noti/NotificationController.java +++ b/src/main/java/peer/backend/controller/noti/NotificationController.java @@ -31,7 +31,6 @@ public class NotificationController { private final UserRepository userRepository; - ///api/v1/noti/spring?type=${}&pgIdx=${number}&pgSize={number} @GetMapping("/spring") public ResponseEntity getAlarmList(Authentication auth, @Param("type") NotificationType type, diff --git a/src/main/java/peer/backend/repository/noti/NotificationTargetRepository.java b/src/main/java/peer/backend/repository/noti/NotificationTargetRepository.java index afb5389e..4d8fb08b 100644 --- a/src/main/java/peer/backend/repository/noti/NotificationTargetRepository.java +++ b/src/main/java/peer/backend/repository/noti/NotificationTargetRepository.java @@ -7,6 +7,7 @@ import peer.backend.entity.noti.Notification; import peer.backend.entity.noti.NotificationTarget; +import java.time.LocalDateTime; import java.util.List; import java.util.Optional; @@ -16,14 +17,26 @@ public interface NotificationTargetRepository extends JpaRepository findUserListById(@Param("eventId") Long eventId); - @Query("SELECT m.specificEvent FROM NotificationTarget m WHERE m.columnIndex = :columnIndex AND m.userList LIKE %:userId% AND m.messageType = :type ORDER BY m.createdAt DESC") + @Query("SELECT m.specificEvent FROM NotificationTarget m " + + "WHERE (" + + "(m.columnIndex = :columnIndex AND m.userList LIKE %:userId% AND m.messageType = :type AND m.specificEvent.priority != 'SCHEDULED')" + + "OR " + + "(m.columnIndex = :columnIndex AND m.userList LIKE %:userId% AND m.messageType = :type AND m.specificEvent.priority = 'SCHEDULED' AND m.specificEvent.scheduledTime < :stadardDate)" + + ") ORDER BY m.createdAt DESC") List getAllEventsByColumnIndexAndUserIdAndMessageType(@Param("columnIndex") Long columnIndex, @Param("userId") String userId, - @Param("type") NotificationType type); - - @Query("SELECT m.specificEvent FROM NotificationTarget m WHERE m.columnIndex = :columnIndex AND m.userList LIKE %:userId% ORDER BY m.createdAt DESC") + @Param("type") NotificationType type, + @Param("standardDate") LocalDateTime standardDate); + + @Query("SELECT m.specificEvent FROM NotificationTarget m " + + "WHERE (" + + "(m.columnIndex = :columnIndex AND m.userList LIKE %:userId% AND m.specificEvent.priority != 'SCHEDULED') " + + "OR " + + "(m.columnIndex = :columnIndex AND m.userList LIKE %:userId% AND m.specificEvent.priority = 'SCHEDULED' AND m.specificEvent.scheduledTime < :standardDate)" + + ") ORDER BY m.createdAt DESC") List getAllEventsByColumnIndexAndUserId(@Param("columnIndex") Long columnIndex, - @Param("userId") String userId); + @Param("userId") String userId, + @Param("standardDate") LocalDateTime standardDate); @Query("SELECT m FROM NotificationTarget m WHERE m.columnIndex = :columnIndex AND m.userList LIKE %:userId% ORDER BY m.createdAt DESC") List findAllByColumnIndexAndUserId(@Param("columnIndex") Long columnIndex, diff --git a/src/main/java/peer/backend/service/noti/NotificationMainService.java b/src/main/java/peer/backend/service/noti/NotificationMainService.java index c9d9e472..9222b6a4 100644 --- a/src/main/java/peer/backend/service/noti/NotificationMainService.java +++ b/src/main/java/peer/backend/service/noti/NotificationMainService.java @@ -15,6 +15,7 @@ import peer.backend.repository.user.UserRepository; import javax.transaction.Transactional; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -72,14 +73,16 @@ public List getNotificationList(User user, { specificEventList = this.notificationTargetRepository.getAllEventsByColumnIndexAndUserId( user.getId() / 100, - user.getId().toString() + user.getId().toString(), + LocalDateTime.now() ); } else { specificEventList = this.notificationTargetRepository .getAllEventsByColumnIndexAndUserIdAndMessageType(user.getId() / 100, user.getId().toString(), - type); + type, + LocalDateTime.now()); } int start = (int) (pgIndex * size - size); int end = (int) (start + size - 1); From 5242b239bb97385adc778e6f3b8404f27622baa3 Mon Sep 17 00:00:00 2001 From: hansol Date: Wed, 14 Feb 2024 01:18:08 +0900 Subject: [PATCH 2/2] FIX: misspelling --- .../backend/repository/noti/NotificationTargetRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/peer/backend/repository/noti/NotificationTargetRepository.java b/src/main/java/peer/backend/repository/noti/NotificationTargetRepository.java index 4d8fb08b..b8762933 100644 --- a/src/main/java/peer/backend/repository/noti/NotificationTargetRepository.java +++ b/src/main/java/peer/backend/repository/noti/NotificationTargetRepository.java @@ -21,7 +21,7 @@ public interface NotificationTargetRepository extends JpaRepository getAllEventsByColumnIndexAndUserIdAndMessageType(@Param("columnIndex") Long columnIndex, @Param("userId") String userId,