.NET 8 backend with Zitadel JWT auth, TheMealDB integration, weekly meal plan generation, shopping list aggregation. Vue 3 + Tailwind 4 frontend with dark emerald theme, manual OIDC PKCE auth, all views implemented. Multi-stage Dockerfile with nginx reverse proxy. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using MealPlanner.Services;
|
|
|
|
namespace MealPlanner.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/shoppinglist")]
|
|
[Authorize]
|
|
public class ShoppingListController(ShoppingListService shoppingListService) : ControllerBase
|
|
{
|
|
private string UserId => User.FindFirst("sub")?.Value ?? throw new UnauthorizedAccessException();
|
|
|
|
[HttpGet("{mealPlanId:guid}")]
|
|
public async Task<IActionResult> GetList(Guid mealPlanId)
|
|
{
|
|
try
|
|
{
|
|
var items = await shoppingListService.GetShoppingListAsync(mealPlanId, UserId);
|
|
return Ok(items);
|
|
}
|
|
catch (UnauthorizedAccessException)
|
|
{
|
|
return Forbid();
|
|
}
|
|
}
|
|
|
|
[HttpPut("{mealPlanId:guid}/check/{itemName}")]
|
|
public async Task<IActionResult> ToggleCheck(Guid mealPlanId, string itemName)
|
|
{
|
|
try
|
|
{
|
|
var result = await shoppingListService.ToggleCheckAsync(mealPlanId, itemName, UserId);
|
|
return Ok(result);
|
|
}
|
|
catch (KeyNotFoundException ex)
|
|
{
|
|
return NotFound(ex.Message);
|
|
}
|
|
catch (UnauthorizedAccessException)
|
|
{
|
|
return Forbid();
|
|
}
|
|
}
|
|
}
|