Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format GET /users/{userI}/followers response #226

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,15 @@ public ResponseEntity<?> getUserFollowing(@PathVariable Integer userId) {
public ResponseEntity<?> getUserFollowers(@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> followers = userService.getUserFollower(userId);
if (followers.isEmpty()) {
return ResponseEntity.ok().body("User is not followed by anyone");
return ResponseEntity.ok(new ErrorResponse(204,"User is not followed by anyone"));
} else {
Set<UserDto> followingDto = followers.stream()
.map(user -> UserDto.builder()
Expand All @@ -130,7 +134,7 @@ public ResponseEntity<?> getUserFollowers(@PathVariable Integer userId) {
.recipeCount(user.getRecipeCount())
.build())
.collect(Collectors.toSet());
return ResponseEntity.ok().body(followingDto);
return ResponseEntity.ok(new SuccessResponse<>(200,followingDto, "User followers fetched successfully"));
}
}
@PostMapping("/{userId}/unfollow")
Expand Down
Loading