Return 404 when user or post not found

This commit is contained in:
Tim
2025-07-14 19:24:11 +08:00
parent f4cedc3a4f
commit aed3c87e4a
12 changed files with 53 additions and 37 deletions

View File

@@ -34,7 +34,7 @@ public class NotificationService {
public List<Notification> listNotifications(String username, Boolean read) {
User user = userRepository.findByUsername(username)
.orElseThrow(() -> new IllegalArgumentException("User not found"));
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
if (read == null) {
return notificationRepository.findByUserOrderByCreatedAtDesc(user);
}
@@ -43,7 +43,7 @@ public class NotificationService {
public void markRead(String username, List<Long> ids) {
User user = userRepository.findByUsername(username)
.orElseThrow(() -> new IllegalArgumentException("User not found"));
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
List<Notification> notifs = notificationRepository.findAllById(ids);
for (Notification n : notifs) {
if (n.getUser().getId().equals(user.getId())) {
@@ -55,7 +55,7 @@ public class NotificationService {
public long countUnread(String username) {
User user = userRepository.findByUsername(username)
.orElseThrow(() -> new IllegalArgumentException("User not found"));
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
return notificationRepository.countByUserAndRead(user, false);
}
}