From 5f15d9290303c368d266d47554f41876cf961238 Mon Sep 17 00:00:00 2001 From: chloe Date: Thu, 19 Mar 2026 02:35:49 +0000 Subject: [PATCH] save updated --- .../Controllers/RecipeController.cs | 7 ++++-- Seasoned.Backend/DTOs/RecipeUpdateDto.cs | 7 ++++++ Seasoned.Frontend/app/pages/gallery.vue | 25 ++++++++++--------- 3 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 Seasoned.Backend/DTOs/RecipeUpdateDto.cs diff --git a/Seasoned.Backend/Controllers/RecipeController.cs b/Seasoned.Backend/Controllers/RecipeController.cs index f6b1cda..c38319a 100644 --- a/Seasoned.Backend/Controllers/RecipeController.cs +++ b/Seasoned.Backend/Controllers/RecipeController.cs @@ -67,7 +67,7 @@ public class RecipeController : ControllerBase } [HttpPut("update/{id}")] - public async Task UpdateRecipe(int id, [FromBody] Recipe updatedRecipe) + public async Task UpdateRecipe(int id, [FromBody] RecipeUpdateDto updatedRecipe) { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); @@ -76,7 +76,7 @@ public class RecipeController : ControllerBase if (existingRecipe == null) { - return NotFound("Recipe not found or you do not have permission to edit it."); + return NotFound("Recipe not found or permission denied."); } existingRecipe.Title = updatedRecipe.Title; @@ -88,6 +88,9 @@ public class RecipeController : ControllerBase existingRecipe.ImageUrl = updatedRecipe.ImageUrl; } + var fullText = $"{updatedRecipe.Title} {string.Join(" ", updatedRecipe.Ingredients)} {string.Join(" ", updatedRecipe.Instructions)}"; + existingRecipe.Embedding = await _recipeService.GetEmbeddingAsync(fullText); + await _context.SaveChangesAsync(); return Ok(new { message = "Recipe updated successfully!" }); diff --git a/Seasoned.Backend/DTOs/RecipeUpdateDto.cs b/Seasoned.Backend/DTOs/RecipeUpdateDto.cs new file mode 100644 index 0000000..1629101 --- /dev/null +++ b/Seasoned.Backend/DTOs/RecipeUpdateDto.cs @@ -0,0 +1,7 @@ +public class RecipeUpdateDto +{ + public string Title { get; set; } = string.Empty; + public List Ingredients { get; set; } = new(); + public List Instructions { get; set; } = new(); + public string? ImageUrl { get; set; } +} \ No newline at end of file diff --git a/Seasoned.Frontend/app/pages/gallery.vue b/Seasoned.Frontend/app/pages/gallery.vue index 9c1c470..6c65b23 100644 --- a/Seasoned.Frontend/app/pages/gallery.vue +++ b/Seasoned.Frontend/app/pages/gallery.vue @@ -390,27 +390,28 @@ const closeDetails = () => { const saveChanges = async () => { try { - const { embedding, ...recipeData } = selectedRecipe.value; + const { embedding, user, ...recipeData } = selectedRecipe.value; + const payload = { - ...selectedRecipe.value, - createdAt: selectedRecipe.value.createdAt || new Date().toISOString(), - ingredients: typeof selectedRecipe.value.ingredients === 'string' - ? selectedRecipe.value.ingredients.split('\n').filter(i => i.trim()) - : selectedRecipe.value.ingredients, - instructions: typeof selectedRecipe.value.instructions === 'string' - ? selectedRecipe.value.instructions.split('\n').filter(i => i.trim()) - : selectedRecipe.value.instructions + title: recipeData.title, + imageUrl: recipeData.imageUrl, + ingredients: typeof recipeData.ingredients === 'string' + ? recipeData.ingredients.split('\n').filter(i => i.trim()) + : recipeData.ingredients, + instructions: typeof recipeData.instructions === 'string' + ? recipeData.instructions.split('\n').filter(i => i.trim()) + : recipeData.instructions }; - await $fetch(`${config.public.apiBase}api/recipe/update/${payload.id}`, { + await $fetch(`${config.public.apiBase}api/recipe/update/${selectedRecipe.value.id}`, { method: 'PUT', body: payload, credentials: 'include' }); - const index = recipes.value.findIndex(r => r.id === payload.id); + const index = recipes.value.findIndex(r => r.id === selectedRecipe.value.id); if (index !== -1) { - recipes.value[index] = { ...payload }; + recipes.value[index] = { ...recipes.value[index], ...payload }; } closeDetails();