Files
mealplanner/backend/Controllers/ShoppingListController.cs
Claude 1885abee64 fix: align frontend API calls with backend routes and types
- Backend: rename routes /mealplan→/mealplans, /shoppinglist→/shopping
- Backend: simplify swap/reroll to entry-centric endpoints (by entryId)
- Frontend: fix all interfaces to use string GUIDs instead of numbers
- Frontend: fix field names (weekStart, date, totalAmount) to match backend JSON
- Frontend: shopping toggle by itemName instead of non-existent id
- Frontend: handle 204 No Content on DELETE responses
- Docker-compose: use env vars for DB credentials

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 06:49:41 +00:00

46 lines
1.2 KiB
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MealPlanner.Services;
namespace MealPlanner.Controllers;
[ApiController]
[Route("api/shopping")]
[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();
}
}
}