fix: correct deletion method implementation
reference: https://stackoverflow.com/questions/75912878/could-not-write-json-failed-to-lazily-initialize-a-collection-when-returning-an
This commit is contained in:
parent
f62e836692
commit
17f4b8bba4
1 changed files with 4 additions and 5 deletions
|
|
@ -115,17 +115,16 @@ public class RecipeController {
|
|||
* Deletes a recipe identified by its <code>id</code>.
|
||||
* </p>
|
||||
* @param id The id of the recipe to be deleted.
|
||||
* @return 200 OK with the recipe that was deleted; or 400 Bad Request if the recipe doesn't exist.
|
||||
* @return 200 OK with true; or 400 Bad Request if the recipe doesn't exist.
|
||||
*/
|
||||
@DeleteMapping("/recipe/{id}")
|
||||
public ResponseEntity<Recipe> deleteRecipe(@PathVariable Long id) {
|
||||
public ResponseEntity<Boolean> deleteRecipe(@PathVariable Long id) {
|
||||
if (!recipeRepository.existsById(id)) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
Recipe removedRecipe = recipeRepository.findById(id).get();
|
||||
recipeRepository.delete(removedRecipe);
|
||||
recipeRepository.deleteById(id);
|
||||
|
||||
// TODO: Send WS update to propagate deletion
|
||||
return ResponseEntity.ok(removedRecipe);
|
||||
return ResponseEntity.ok(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue