Skip to content

Commit 3b441fc

Browse files
authored
Merge pull request #7 from PoolC/dev
merge notification all
2 parents b35edb9 + 9bebd58 commit 3b441fc

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/main/java/org/poolc/api/notification/controller/NotificationController.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
import org.springframework.web.bind.annotation.PostMapping;
1616
import org.springframework.web.bind.annotation.RequestMapping;
1717

18-
import java.util.List;
19-
import java.util.stream.Collectors;
20-
2118
@Controller
2219
@RequestMapping("/notification")
2320
@RequiredArgsConstructor
@@ -30,6 +27,12 @@ public ResponseEntity<NotificationResponse> viewNotification(@AuthenticationPrin
3027
return ResponseEntity.status(HttpStatus.OK).body(response);
3128
}
3229

30+
@PostMapping("/all")
31+
public ResponseEntity<Void> viewAllNotifications(@AuthenticationPrincipal Member member) {
32+
notificationService.readAllNotifications(member);
33+
return ResponseEntity.status(HttpStatus.OK).build();
34+
}
35+
3336
@GetMapping("/unread")
3437
public ResponseEntity<NotificationSummaryResponse> getUnreadNotifications(@AuthenticationPrincipal Member member) {
3538
NotificationSummaryResponse summaryResponse = notificationService.getUnreadNotificationsForMember(member);

src/main/java/org/poolc/api/notification/repository/NotificationRepository.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66
import org.springframework.data.jpa.repository.Query;
77

88
import java.util.List;
9+
import org.springframework.data.repository.query.Param;
10+
import org.springframework.security.core.parameters.P;
911

1012
public interface NotificationRepository extends JpaRepository<Notification, Long> {
1113

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);
1316

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);
1519

1620
@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);
1822
}

src/main/java/org/poolc/api/notification/service/NotificationService.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,20 @@ public NotificationSummaryResponse getUnreadNotificationsForMember(Member member
3737
public NotificationSummaryResponse getAllNotificationsForMember(Member member) {
3838
List<NotificationResponse> responses = notificationRepository.findAllByReceiverId(member.getLoginID())
3939
.stream()
40-
//.peek(Notification::memberReads) // Apply the memberReads method
40+
//.peek(Notification::memberReads)
4141
.sorted(Comparator.comparing(Notification::getCreatedAt).reversed())
4242
.map(NotificationResponse::of)
4343
.collect(Collectors.toList());
4444
long unreadCount = notificationRepository.countByReceiverIdAndReadIsFalse(member.getLoginID());
4545
return NotificationSummaryResponse.of(unreadCount, responses);
4646
}
47+
48+
@Transactional
49+
public void readAllNotifications(Member member) {
50+
List<Notification> notifications = notificationRepository.findAllByReceiverId(member.getLoginID());
51+
notifications.forEach(Notification::memberReads);
52+
}
53+
4754
@Transactional
4855
public void createBadgeNotification(Member receiver) {
4956
Notification notification = new Notification(receiver.getLoginID(), NotificationType.BADGE);

0 commit comments

Comments
 (0)