feat: add point redeem notification

This commit is contained in:
Tim
2025-08-17 02:27:19 +08:00
parent 0b6d4f9709
commit 2c187cf2cd
6 changed files with 49 additions and 1 deletions

View File

@@ -32,6 +32,8 @@ public enum NotificationType {
REGISTER_REQUEST,
/** A user redeemed an activity reward */
ACTIVITY_REDEEM,
/** A user redeemed a point good */
POINT_REDEEM,
/** You won a lottery post */
LOTTERY_WIN,
/** Your lottery post was drawn */

View File

@@ -141,6 +141,19 @@ public class NotificationService {
}
}
/**
* Create notifications for all admins when a user redeems a point good.
* Old redeem notifications from the same user are removed first.
*/
@org.springframework.transaction.annotation.Transactional
public void createPointRedeemNotifications(User user, String content) {
notificationRepository.deleteByTypeAndFromUser(NotificationType.POINT_REDEEM, user);
for (User admin : userRepository.findByRole(Role.ADMIN)) {
createNotification(admin, NotificationType.POINT_REDEEM, null, null,
null, user, null, content);
}
}
public List<NotificationPreferenceDto> listPreferences(String username) {
User user = userRepository.findByUsername(username)
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));

View File

@@ -31,7 +31,7 @@ public class PointMallService {
}
user.setPoint(user.getPoint() - good.getCost());
userRepository.save(user);
notificationService.createActivityRedeemNotifications(user, good.getName() + ": " + contact);
notificationService.createPointRedeemNotifications(user, good.getName() + ": " + contact);
return user.getPoint();
}
}