From 4ebb8199a75ca24986306a3b0146f2dbd24fa091 Mon Sep 17 00:00:00 2001 From: EnesBaserr Date: Tue, 14 May 2024 19:41:29 +0300 Subject: [PATCH 1/2] /cuisines/{cuisineId} response format reimplemented. --- .../com/group1/cuisines/controllers/CuisineController.java | 4 ++-- .../com/group1/cuisines/controllers/FeedController.java | 6 +++--- .../com/group1/cuisines/controllers/RecipeController.java | 2 +- .../com/group1/cuisines/controllers/UserController.java | 4 ++-- .../com/group1/cuisines/dao/response/ErrorResponse.java | 1 + .../com/group1/cuisines/dao/response/SuccessResponse.java | 1 + 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/com/group1/cuisines/controllers/CuisineController.java b/backend/src/main/java/com/group1/cuisines/controllers/CuisineController.java index bca83b3f..d902e924 100644 --- a/backend/src/main/java/com/group1/cuisines/controllers/CuisineController.java +++ b/backend/src/main/java/com/group1/cuisines/controllers/CuisineController.java @@ -29,9 +29,9 @@ public class CuisineController { public ResponseEntity getCuisineById(@PathVariable String cuisineId, @RequestParam(required = false) Boolean includeDishes) { try { CuisineDetailsDto cuisineDetails = cuisineService.getCuisineById(cuisineId, Boolean.TRUE.equals(includeDishes)); - return ResponseEntity.ok(new SuccessResponse<>(cuisineDetails, "Cuisine details fetched successfully")); + return ResponseEntity.ok(new SuccessResponse<>(200,cuisineDetails, "Cuisine details fetched successfully")); } catch (EntityNotFoundException e) { - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponse("Cuisine not found")); + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponse(204,"Cuisine not found")); } } } diff --git a/backend/src/main/java/com/group1/cuisines/controllers/FeedController.java b/backend/src/main/java/com/group1/cuisines/controllers/FeedController.java index ff3fd957..acea433c 100644 --- a/backend/src/main/java/com/group1/cuisines/controllers/FeedController.java +++ b/backend/src/main/java/com/group1/cuisines/controllers/FeedController.java @@ -30,16 +30,16 @@ public ResponseEntity getFeed(@RequestParam String type, Authentication authe if ("following".equals(type)) { if (authentication == null || !authentication.isAuthenticated()) { // Return an empty set and a message for unauthenticated users - return ResponseEntity.ok(new SuccessResponse<>(Collections.emptyList(), "No content available. Please log in and follow other users !.")); + return ResponseEntity.ok(new SuccessResponse<>(200,Collections.emptyList(), "No content available. Please log in and follow other users !.")); } // Fetch following users' recipes for authenticated users String username = authentication.getName(); List recipes = recipeService.getRecipesByType(type, username); - return ResponseEntity.ok(new SuccessResponse<>(recipes, "Recipes fetched successfully from followed users.")); + return ResponseEntity.ok(new SuccessResponse<>(200,recipes, "Recipes fetched successfully from followed users.")); } // For 'explore', accessible to everyone List recipes = recipeService.getRecipesByType(type, null); - return ResponseEntity.ok(new SuccessResponse<>(recipes, "Recipes fetched successfully.")); + return ResponseEntity.ok(new SuccessResponse<>(200,recipes, "Recipes fetched successfully.")); } } diff --git a/backend/src/main/java/com/group1/cuisines/controllers/RecipeController.java b/backend/src/main/java/com/group1/cuisines/controllers/RecipeController.java index 7f12b83b..814ec4d0 100644 --- a/backend/src/main/java/com/group1/cuisines/controllers/RecipeController.java +++ b/backend/src/main/java/com/group1/cuisines/controllers/RecipeController.java @@ -26,7 +26,7 @@ public class RecipeController { public ResponseEntity getRecipeById(@PathVariable Integer recipeId) { RecipeDetailsDto recipeDetails = recipeService.getRecipeById(recipeId); if (recipeDetails != null) { - return ResponseEntity.ok(new SuccessResponse<>(recipeDetails, "Recipe fetched successfully")); + return ResponseEntity.ok(new SuccessResponse<>(200,recipeDetails, "Recipe fetched successfully")); } else { return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Recipe not found"); } 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 50dd7478..de506bfc 100644 --- a/backend/src/main/java/com/group1/cuisines/controllers/UserController.java +++ b/backend/src/main/java/com/group1/cuisines/controllers/UserController.java @@ -36,9 +36,9 @@ public ResponseEntity getUserById(@PathVariable Integer userId, Authenticatio String currentUsername = authentication != null ? authentication.getName() : null; try { UserProfileDto userProfile = userService.getUserProfileById(userId, currentUsername); - return ResponseEntity.ok(new SuccessResponse<>(userProfile, "User profile fetched successfully")); + return ResponseEntity.ok(new SuccessResponse<>(200,userProfile, "User profile fetched successfully")); } catch (EntityNotFoundException e) { - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponse("User not found")); + return ResponseEntity.ok(new ErrorResponse(204,"User not found")); } } diff --git a/backend/src/main/java/com/group1/cuisines/dao/response/ErrorResponse.java b/backend/src/main/java/com/group1/cuisines/dao/response/ErrorResponse.java index 2450f365..df3e3fca 100644 --- a/backend/src/main/java/com/group1/cuisines/dao/response/ErrorResponse.java +++ b/backend/src/main/java/com/group1/cuisines/dao/response/ErrorResponse.java @@ -7,5 +7,6 @@ @Data @AllArgsConstructor public class ErrorResponse { + private int status; private String message; } diff --git a/backend/src/main/java/com/group1/cuisines/dao/response/SuccessResponse.java b/backend/src/main/java/com/group1/cuisines/dao/response/SuccessResponse.java index be965ff0..b4ab374e 100644 --- a/backend/src/main/java/com/group1/cuisines/dao/response/SuccessResponse.java +++ b/backend/src/main/java/com/group1/cuisines/dao/response/SuccessResponse.java @@ -3,6 +3,7 @@ @Data @AllArgsConstructor public class SuccessResponse { + private int status; private T data; private String message; From dee242453e6d8b224d2c58a59449f4d47c584eef Mon Sep 17 00:00:00 2001 From: EnesBaserr Date: Tue, 14 May 2024 19:43:30 +0300 Subject: [PATCH 2/2] /cuisines/{cuisineId} response format reimplemented. --- .../java/com/group1/cuisines/controllers/CuisineController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/group1/cuisines/controllers/CuisineController.java b/backend/src/main/java/com/group1/cuisines/controllers/CuisineController.java index d902e924..eadf6d76 100644 --- a/backend/src/main/java/com/group1/cuisines/controllers/CuisineController.java +++ b/backend/src/main/java/com/group1/cuisines/controllers/CuisineController.java @@ -31,7 +31,7 @@ public ResponseEntity getCuisineById(@PathVariable String cuisineId, @Request CuisineDetailsDto cuisineDetails = cuisineService.getCuisineById(cuisineId, Boolean.TRUE.equals(includeDishes)); return ResponseEntity.ok(new SuccessResponse<>(200,cuisineDetails, "Cuisine details fetched successfully")); } catch (EntityNotFoundException e) { - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ErrorResponse(204,"Cuisine not found")); + return ResponseEntity.ok(new ErrorResponse(204,"Cuisine not found")); } } }