save updated

This commit is contained in:
2026-03-19 02:35:49 +00:00
parent f6199855fb
commit 5f15d92903
3 changed files with 25 additions and 14 deletions

View File

@@ -67,7 +67,7 @@ public class RecipeController : ControllerBase
}
[HttpPut("update/{id}")]
public async Task<IActionResult> UpdateRecipe(int id, [FromBody] Recipe updatedRecipe)
public async Task<IActionResult> 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!" });

View File

@@ -0,0 +1,7 @@
public class RecipeUpdateDto
{
public string Title { get; set; } = string.Empty;
public List<string> Ingredients { get; set; } = new();
public List<string> Instructions { get; set; } = new();
public string? ImageUrl { get; set; }
}