From 17f4b8bba4143b845d7bd37c5a4c4a8706335a16 Mon Sep 17 00:00:00 2001
From: Steven Liu
Date: Sat, 22 Nov 2025 01:24:04 +0100
Subject: [PATCH] fix: correct deletion method implementation
reference: https://stackoverflow.com/questions/75912878/could-not-write-json-failed-to-lazily-initialize-a-collection-when-returning-an
---
server/src/main/java/server/api/RecipeController.java | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/server/src/main/java/server/api/RecipeController.java b/server/src/main/java/server/api/RecipeController.java
index 9b1753e..a1d79fe 100644
--- a/server/src/main/java/server/api/RecipeController.java
+++ b/server/src/main/java/server/api/RecipeController.java
@@ -115,17 +115,16 @@ public class RecipeController {
* Deletes a recipe identified by its id.
*
* @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 deleteRecipe(@PathVariable Long id) {
+ public ResponseEntity 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);
}
}