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 response /cuisines/{cuisine id} (Get cuisine details) #220

Merged
Show file tree
Hide file tree
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 @@ -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
Loading