Skip to content

Commit

Permalink
Format GET /users/{userId}/following response
Browse files Browse the repository at this point in the history
  • Loading branch information
EnesBaserr committed May 14, 2024
1 parent 72e577f commit 3646bf7
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,16 @@ public ResponseEntity<?> followUser(@PathVariable Integer userId) {
public ResponseEntity<?> getUserFollowing(@PathVariable Integer userId) {
// Validate the provided user ID
if (userId == null) {
return ResponseEntity.badRequest().body("Invalid user ID provided");

return ResponseEntity.ok(new ErrorResponse(204,"Invalid user ID provided") );
}
if(userRepository.findById(userId).isEmpty()){
return ResponseEntity.ok(new ErrorResponse(204,"User not found") );
}

Set<User> following = userService.getUserFollowing(userId);
if (following.isEmpty()) {
return ResponseEntity.ok().body("User is not following anyone");
return ResponseEntity.ok(new ErrorResponse(204,"User is not following anyone"));
} else {
Set<UserDto> followingDto = following.stream()
.map(user -> UserDto.builder()
Expand All @@ -102,7 +106,7 @@ public ResponseEntity<?> getUserFollowing(@PathVariable Integer userId) {
.recipeCount(user.getRecipeCount())
.build())
.collect(Collectors.toSet());
return ResponseEntity.ok().body(followingDto);
return ResponseEntity.ok(new SuccessResponse<>(200,followingDto, "User following fetched successfully"));
}
}
@GetMapping("/{userId}/followers")
Expand Down

0 comments on commit 3646bf7

Please sign in to comment.