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>
This commit is contained in:
2026-04-16 06:49:41 +00:00
parent f58782774b
commit 1885abee64
10 changed files with 64 additions and 75 deletions

View File

@@ -5,7 +5,7 @@ using MealPlanner.Services;
namespace MealPlanner.Controllers;
[ApiController]
[Route("api/mealplan")]
[Route("api/mealplans")]
[Authorize]
public class MealPlanController(MealPlanService mealPlanService) : ControllerBase
{
@@ -49,21 +49,12 @@ public class MealPlanController(MealPlanService mealPlanService) : ControllerBas
return Ok(plan);
}
[HttpPut("{id:guid}/entry/{date}")]
public async Task<IActionResult> SwapEntry(Guid id, string date, [FromBody] SwapRequest body)
[HttpPut("entries/{entryId:guid}/swap")]
public async Task<IActionResult> SwapEntry(Guid entryId, [FromBody] SwapRequest body)
{
if (!DateOnly.TryParse(date, out var parsedDate)) return BadRequest("Invalid date format.");
// Find entry by plan id + date
var plan = await mealPlanService.GetPlanAsync(UserId, MealPlanService.GetWeekStart(parsedDate));
if (plan is null || plan.Id != id) return NotFound();
var entry = plan.Entries.FirstOrDefault(e => e.Date == parsedDate);
if (entry is null) return NotFound();
try
{
var updated = await mealPlanService.SwapEntryAsync(entry.Id, body.RecipeId, UserId);
var updated = await mealPlanService.SwapEntryAsync(entryId, body.RecipeId, UserId);
if (updated is null) return NotFound();
return Ok(updated);
}
@@ -73,20 +64,12 @@ public class MealPlanController(MealPlanService mealPlanService) : ControllerBas
}
}
[HttpPost("{id:guid}/entry/{date}/reroll")]
public async Task<IActionResult> RerollEntry(Guid id, string date)
[HttpPost("entries/{entryId:guid}/reroll")]
public async Task<IActionResult> RerollEntry(Guid entryId)
{
if (!DateOnly.TryParse(date, out var parsedDate)) return BadRequest("Invalid date format.");
var plan = await mealPlanService.GetPlanAsync(UserId, MealPlanService.GetWeekStart(parsedDate));
if (plan is null || plan.Id != id) return NotFound();
var entry = plan.Entries.FirstOrDefault(e => e.Date == parsedDate);
if (entry is null) return NotFound();
try
{
var updated = await mealPlanService.RerollEntryAsync(entry.Id, UserId);
var updated = await mealPlanService.RerollEntryAsync(entryId, UserId);
if (updated is null) return StatusCode(503, "Could not fetch a new recipe. Try again.");
return Ok(updated);
}

View File

@@ -5,7 +5,7 @@ using MealPlanner.Services;
namespace MealPlanner.Controllers;
[ApiController]
[Route("api/shoppinglist")]
[Route("api/shopping")]
[Authorize]
public class ShoppingListController(ShoppingListService shoppingListService) : ControllerBase
{