Skip to content

Commit

Permalink
Merge pull request #858 from peer-42seoul/hotfix-alarm-list-get-api
Browse files Browse the repository at this point in the history
Hotfix alarm list get api
  • Loading branch information
Paul2021-R authored Feb 14, 2024
2 parents 1d24aa8 + 5242b23 commit 669ac73
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -16,14 +17,26 @@ public interface NotificationTargetRepository extends JpaRepository<Notification
List<String> 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<Notification> 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<Notification> 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<NotificationTarget> findAllByColumnIndexAndUserId(@Param("columnIndex") Long columnIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,14 +73,16 @@ public List<NotificationDTO> 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);
Expand Down

0 comments on commit 669ac73

Please sign in to comment.