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

@@ -104,14 +104,14 @@ public class UserService {
public User updateAvatar(String username, String avatarUrl) {
User user = userRepository.findByUsername(username)
.orElseThrow(() -> new IllegalArgumentException("User not found"));
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
user.setAvatar(avatarUrl);
return userRepository.save(user);
}
public User updateProfile(String currentUsername, String newUsername, String introduction) {
User user = userRepository.findByUsername(currentUsername)
.orElseThrow(() -> new IllegalArgumentException("User not found"));
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
if (newUsername != null && !newUsername.equals(currentUsername)) {
usernameValidator.validate(newUsername);
userRepository.findByUsername(newUsername).ifPresent(u -> {