Skip to content

Commit

Permalink
Merge pull request #224 from bounswe/backend/feature/223-format-/user…
Browse files Browse the repository at this point in the history
…s/userId/following-response

Format GET /users/{userId}/following response
  • Loading branch information
EnesBaserr authored May 14, 2024
2 parents 72e577f + 3646bf7 commit feec97f
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 feec97f

Please sign in to comment.