UI + backend update

This commit is contained in:
2026-03-11 05:04:48 +00:00
parent 27bff9535c
commit 01f42c22d6
7 changed files with 346 additions and 44 deletions

View File

@@ -5,7 +5,6 @@ using Seasoned.Backend.Data;
using System.Security.Claims;
using Seasoned.Backend.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
namespace Seasoned.Backend.Controllers;
@@ -49,7 +48,7 @@ public class RecipeController : ControllerBase
var recipe = new Recipe
{
Title = recipeDto.Title,
Description = recipeDto.Description,
Icon = recipeDto.Icon,
Ingredients = recipeDto.Ingredients,
Instructions = recipeDto.Instructions,
CreatedAt = DateTime.UtcNow,
@@ -62,6 +61,29 @@ public class RecipeController : ControllerBase
return Ok(new { message = "Recipe saved to your collection!" });
}
[Authorize]
[HttpPut("update/{id}")]
public async Task<IActionResult> UpdateRecipe(int id, [FromBody] Recipe updatedRecipe)
{
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
var existingRecipe = await _context.Recipes
.FirstOrDefaultAsync(r => r.Id == id && r.UserId == userId);
if (existingRecipe == null)
{
return NotFound("Recipe not found or you do not have permission to edit it.");
}
existingRecipe.Title = updatedRecipe.Title;
existingRecipe.Ingredients = updatedRecipe.Ingredients;
existingRecipe.Instructions = updatedRecipe.Instructions;
await _context.SaveChangesAsync();
return Ok(new { message = "Recipe updated successfully!" });
}
[Authorize]
[HttpGet("my-collection")]
public async Task<ActionResult<IEnumerable<Recipe>>> GetMyRecipes()
@@ -75,5 +97,4 @@ public class RecipeController : ControllerBase
return Ok(myRecipes);
}
}