Remove duplicate register request notifications

This commit is contained in:
Tim
2025-07-15 12:50:11 +08:00
parent 5b886420c5
commit 4036bd25a5
4 changed files with 38 additions and 12 deletions

View File

@@ -33,6 +33,18 @@ public class NotificationService {
return notificationRepository.save(n);
}
/**
* Create notifications for all admins when a user submits a register request.
* Old register request notifications from the same applicant are removed first.
*/
public void createRegisterRequestNotifications(User applicant, String reason) {
notificationRepository.deleteByTypeAndFromUser(NotificationType.REGISTER_REQUEST, applicant);
for (User admin : userRepository.findByRole(Role.ADMIN)) {
createNotification(admin, NotificationType.REGISTER_REQUEST, null, null,
null, applicant, null, reason);
}
}
public List<Notification> listNotifications(String username, Boolean read) {
User user = userRepository.findByUsername(username)
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));