Skip to content

Commit

Permalink
refactor: Added error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-merlin committed Apr 8, 2024
1 parent 3b9e45b commit fb4a272
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.sitblueprint.admin.service.users.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand All @@ -20,9 +21,14 @@ public List<User> getAllUsers() {
return userService.getAllUsers();
}

@GetMapping
public User getUser(@Param("userId") String userId) {
return userService.getUserById(Long.parseLong(userId));
@GetMapping("/{userId}")
public ResponseEntity<?> getUser(@PathVariable("userId") Long userId) {
try {
User user = userService.getUserById(userId);
return ResponseEntity.ok(user);
} catch (NumberFormatException e) {
return ResponseEntity.badRequest().body("Invalid user id format");
}
}

@PostMapping
Expand Down

0 comments on commit fb4a272

Please sign in to comment.