Skip to content

Commit

Permalink
Merge pull request #220 from bounswe/backend/feature/#219-formatting-…
Browse files Browse the repository at this point in the history
…response-/cuisines/{cuisineId}

Format response /cuisines/{cuisine id} (Get cuisine details)
  • Loading branch information
EnesBaserr authored May 14, 2024
2 parents 74b85b1 + dee2424 commit 90f76a6
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.ok(new ErrorResponse(204,"Cuisine not found"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<RecipeDetailsDto> 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<RecipeDetailsDto> recipes = recipeService.getRecipesByType(type, null);
return ResponseEntity.ok(new SuccessResponse<>(recipes, "Recipes fetched successfully."));
return ResponseEntity.ok(new SuccessResponse<>(200,recipes, "Recipes fetched successfully."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
@Data
@AllArgsConstructor
public class ErrorResponse {
private int status;
private String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@Data
@AllArgsConstructor
public class SuccessResponse <T>{
private int status;
private T data;
private String message;

Expand Down

0 comments on commit 90f76a6

Please sign in to comment.