File tree 3 files changed +21
-7
lines changed
src/main/java/org/poolc/api/notification
3 files changed +21
-7
lines changed Original file line number Diff line number Diff line change 15
15
import org .springframework .web .bind .annotation .PostMapping ;
16
16
import org .springframework .web .bind .annotation .RequestMapping ;
17
17
18
- import java .util .List ;
19
- import java .util .stream .Collectors ;
20
-
21
18
@ Controller
22
19
@ RequestMapping ("/notification" )
23
20
@ RequiredArgsConstructor
@@ -30,6 +27,12 @@ public ResponseEntity<NotificationResponse> viewNotification(@AuthenticationPrin
30
27
return ResponseEntity .status (HttpStatus .OK ).body (response );
31
28
}
32
29
30
+ @ PostMapping ("/all" )
31
+ public ResponseEntity <Void > viewAllNotifications (@ AuthenticationPrincipal Member member ) {
32
+ notificationService .readAllNotifications (member );
33
+ return ResponseEntity .status (HttpStatus .OK ).build ();
34
+ }
35
+
33
36
@ GetMapping ("/unread" )
34
37
public ResponseEntity <NotificationSummaryResponse > getUnreadNotifications (@ AuthenticationPrincipal Member member ) {
35
38
NotificationSummaryResponse summaryResponse = notificationService .getUnreadNotificationsForMember (member );
Original file line number Diff line number Diff line change 6
6
import org .springframework .data .jpa .repository .Query ;
7
7
8
8
import java .util .List ;
9
+ import org .springframework .data .repository .query .Param ;
10
+ import org .springframework .security .core .parameters .P ;
9
11
10
12
public interface NotificationRepository extends JpaRepository <Notification , Long > {
11
13
12
- List <Notification > findByReceiverIdAndReadStatus (String receiverId , Boolean readStatus );
14
+ @ Query ("SELECT n FROM Notification n WHERE n.receiverId = :receiverId AND n.readStatus = :readStatus" )
15
+ List <Notification > findByReceiverIdAndReadStatus (@ Param ("receiverId" ) String receiverId , @ Param ("readStatus" ) Boolean readStatus );
13
16
14
- List <Notification > findAllByReceiverId (String receiverId );
17
+ @ Query ("SELECT n FROM Notification n WHERE n.receiverId = :receiverId ORDER BY n.createdAt DESC" )
18
+ List <Notification > findAllByReceiverId (@ Param ("receiverId" ) String receiverId );
15
19
16
20
@ Query ("SELECT COUNT(n) FROM Notification n WHERE n.receiverId = :receiverId AND n.readStatus = false" )
17
- Long countByReceiverIdAndReadIsFalse (String receiverId );
21
+ Long countByReceiverIdAndReadIsFalse (@ Param ( "receiverId" ) String receiverId );
18
22
}
Original file line number Diff line number Diff line change @@ -37,13 +37,20 @@ public NotificationSummaryResponse getUnreadNotificationsForMember(Member member
37
37
public NotificationSummaryResponse getAllNotificationsForMember (Member member ) {
38
38
List <NotificationResponse > responses = notificationRepository .findAllByReceiverId (member .getLoginID ())
39
39
.stream ()
40
- //.peek(Notification::memberReads) // Apply the memberReads method
40
+ //.peek(Notification::memberReads)
41
41
.sorted (Comparator .comparing (Notification ::getCreatedAt ).reversed ())
42
42
.map (NotificationResponse ::of )
43
43
.collect (Collectors .toList ());
44
44
long unreadCount = notificationRepository .countByReceiverIdAndReadIsFalse (member .getLoginID ());
45
45
return NotificationSummaryResponse .of (unreadCount , responses );
46
46
}
47
+
48
+ @ Transactional
49
+ public void readAllNotifications (Member member ) {
50
+ List <Notification > notifications = notificationRepository .findAllByReceiverId (member .getLoginID ());
51
+ notifications .forEach (Notification ::memberReads );
52
+ }
53
+
47
54
@ Transactional
48
55
public void createBadgeNotification (Member receiver ) {
49
56
Notification notification = new Notification (receiver .getLoginID (), NotificationType .BADGE );
You can’t perform that action at this time.
0 commit comments