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..b8762933 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 < :standardDate)" + + ") 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 7d08ce5f..48650894 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);