Skip to content

Commit d16cee1

Browse files
jueunk617namgigun
authored andcommitted
Feat: 알림 관련 repository 기본 구현
1 parent 9a471cb commit d16cee1

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.back.domain.notification.repository;
2+
3+
import com.back.domain.notification.entity.NotificationRead;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
6+
import java.util.Optional;
7+
8+
public interface NotificationReadRepository extends JpaRepository<NotificationRead, Long> {
9+
10+
// 특정 유저가 특정 알림을 읽었는지 확인
11+
boolean existsByNotificationIdAndUserId(Long notificationId, Long userId);
12+
13+
// 특정 유저의 특정 알림 읽음 기록 조회
14+
Optional<NotificationRead> findByNotificationIdAndUserId(Long notificationId, Long userId);
15+
16+
// 특정 알림의 모든 읽음 기록 삭제
17+
void deleteByNotificationId(Long notificationId);
18+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.back.domain.notification.repository;
2+
3+
import com.back.domain.notification.entity.Notification;
4+
import com.back.domain.notification.entity.NotificationType;
5+
import org.springframework.data.domain.Page;
6+
import org.springframework.data.domain.Pageable;
7+
import org.springframework.data.jpa.repository.JpaRepository;
8+
import org.springframework.data.jpa.repository.Query;
9+
import org.springframework.data.repository.query.Param;
10+
11+
import java.util.List;
12+
13+
public interface NotificationRepository extends JpaRepository<Notification, Long> {
14+
15+
// 특정 유저의 알림 목록 조회 (개인 알림 + 시스템 알림)
16+
@Query("SELECT n FROM Notification n " +
17+
"WHERE n.user.id = :userId OR n.type = 'SYSTEM' " +
18+
"ORDER BY n.createdAt DESC")
19+
Page<Notification> findByUserIdOrSystemType(@Param("userId") Long userId, Pageable pageable);
20+
21+
// 특정 유저의 읽지 않은 알림 개수 조회
22+
@Query("SELECT COUNT(n) FROM Notification n " +
23+
"LEFT JOIN NotificationRead nr ON n.id = nr.notification.id AND nr.user.id = :userId " +
24+
"WHERE (n.user.id = :userId OR n.type = 'SYSTEM') " +
25+
"AND nr.id IS NULL")
26+
long countUnreadByUserId(@Param("userId") Long userId);
27+
28+
// 특정 유저의 읽지 않은 알림 목록 조회
29+
@Query("SELECT n FROM Notification n " +
30+
"LEFT JOIN NotificationRead nr ON n.id = nr.notification.id AND nr.user.id = :userId " +
31+
"WHERE (n.user.id = :userId OR n.type = 'SYSTEM') " +
32+
"AND nr.id IS NULL " +
33+
"ORDER BY n.createdAt DESC")
34+
Page<Notification> findUnreadByUserId(@Param("userId") Long userId, Pageable pageable);
35+
36+
// 특정 스터디룸의 알림 조회
37+
Page<Notification> findByRoomIdOrderByCreatedAtDesc(Long roomId, Pageable pageable);
38+
39+
// 특정 타입의 알림 조회
40+
List<Notification> findByType(NotificationType type);
41+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.back.domain.notification.repository;
2+
3+
import com.back.domain.notification.entity.NotificationSetting;
4+
import com.back.domain.notification.entity.NotificationSettingType;
5+
import org.springframework.data.jpa.repository.JpaRepository;
6+
7+
import java.util.List;
8+
import java.util.Optional;
9+
10+
public interface NotificationSettingRepository extends JpaRepository<NotificationSetting, Long> {
11+
12+
// 특정 유저의 모든 알림 설정 조회
13+
List<NotificationSetting> findByUserId(Long userId);
14+
15+
// 특정 유저의 특정 타입 알림 설정 조회
16+
Optional<NotificationSetting> findByUserIdAndType(Long userId, NotificationSettingType type);
17+
18+
// 특정 유저의 특정 타입 알림 설정 존재 여부
19+
boolean existsByUserIdAndType(Long userId, NotificationSettingType type);
20+
21+
// 특정 유저의 활성화된 알림 설정만 조회
22+
List<NotificationSetting> findByUserIdAndEnabledTrue(Long userId);
23+
}

0 commit comments

Comments
 (0)