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

@@ -17,7 +17,7 @@ public class UserVisitService {
public void recordVisit(String username) {
User user = userRepository.findByUsername(username)
.orElseThrow(() -> new IllegalArgumentException("User not found"));
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
LocalDate today = LocalDate.now();
userVisitRepository.findByUserAndVisitDate(user, today).orElseGet(() -> {
UserVisit visit = new UserVisit();
@@ -29,7 +29,7 @@ public class UserVisitService {
public long countVisits(String username) {
User user = userRepository.findByUsername(username)
.orElseThrow(() -> new IllegalArgumentException("User not found"));
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
return userVisitRepository.countByUser(user);
}
}