From 2e648564a92d8dfce97d4db3721c2db3b87b3e6e Mon Sep 17 00:00:00 2001 From: EnesBaserr Date: Tue, 14 May 2024 20:34:31 +0300 Subject: [PATCH] Format GET /users/{userI}/followers response --- .../group1/cuisines/controllers/UserController.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/com/group1/cuisines/controllers/UserController.java b/backend/src/main/java/com/group1/cuisines/controllers/UserController.java index 6eedc554..35c9f5f5 100644 --- a/backend/src/main/java/com/group1/cuisines/controllers/UserController.java +++ b/backend/src/main/java/com/group1/cuisines/controllers/UserController.java @@ -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 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 followingDto = followers.stream() .map(user -> UserDto.builder() @@ -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")