mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-25 15:40:49 +08:00
Update milk tea redeem dialog and notifications
This commit is contained in:
@@ -39,10 +39,7 @@ public class ActivityService {
|
||||
|
||||
public void redeem(Activity activity, User user, String contact) {
|
||||
String content = user.getUsername() + " contact: " + contact;
|
||||
for (User admin : userRepository.findByRole(Role.ADMIN)) {
|
||||
notificationService.createNotification(admin, NotificationType.ACTIVITY_REDEEM,
|
||||
null, null, null, user, null, content);
|
||||
}
|
||||
notificationService.createActivityRedeemNotifications(user, content);
|
||||
activity.getParticipants().add(user);
|
||||
activityRepository.save(activity);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,19 @@ public class NotificationService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create notifications for all admins when a user redeems an activity.
|
||||
* Old redeem notifications from the same user are removed first.
|
||||
*/
|
||||
@org.springframework.transaction.annotation.Transactional
|
||||
public void createActivityRedeemNotifications(User user, String content) {
|
||||
notificationRepository.deleteByTypeAndFromUser(NotificationType.ACTIVITY_REDEEM, user);
|
||||
for (User admin : userRepository.findByRole(Role.ADMIN)) {
|
||||
createNotification(admin, NotificationType.ACTIVITY_REDEEM, null, null,
|
||||
null, user, null, content);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Notification> listNotifications(String username, Boolean read) {
|
||||
User user = userRepository.findByUsername(username)
|
||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
||||
|
||||
@@ -96,4 +96,23 @@ class NotificationServiceTest {
|
||||
verify(nRepo).deleteByTypeAndFromUser(NotificationType.REGISTER_REQUEST, applicant);
|
||||
verify(nRepo).save(any(Notification.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createActivityRedeemNotificationsDeletesOldOnes() {
|
||||
NotificationRepository nRepo = mock(NotificationRepository.class);
|
||||
UserRepository uRepo = mock(UserRepository.class);
|
||||
NotificationService service = new NotificationService(nRepo, uRepo);
|
||||
|
||||
User admin = new User();
|
||||
admin.setId(10L);
|
||||
User user = new User();
|
||||
user.setId(20L);
|
||||
|
||||
when(uRepo.findByRole(Role.ADMIN)).thenReturn(List.of(admin));
|
||||
|
||||
service.createActivityRedeemNotifications(user, "contact");
|
||||
|
||||
verify(nRepo).deleteByTypeAndFromUser(NotificationType.ACTIVITY_REDEEM, user);
|
||||
verify(nRepo).save(any(Notification.class));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user