.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>
43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using MealPlanner.Data;
|
|
using MealPlanner.Models;
|
|
|
|
namespace MealPlanner.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/settings")]
|
|
[Authorize]
|
|
public class SettingsController(AppDbContext db) : ControllerBase
|
|
{
|
|
private string UserId => User.FindFirst("sub")?.Value ?? throw new UnauthorizedAccessException();
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> Get()
|
|
{
|
|
var settings = await db.UserSettings.FindAsync(UserId);
|
|
if (settings is null)
|
|
{
|
|
settings = new UserSettings { UserId = UserId, HouseholdSize = 2 };
|
|
db.UserSettings.Add(settings);
|
|
await db.SaveChangesAsync();
|
|
}
|
|
return Ok(settings);
|
|
}
|
|
|
|
[HttpPut]
|
|
public async Task<IActionResult> Update([FromBody] UserSettings updated)
|
|
{
|
|
var settings = await db.UserSettings.FindAsync(UserId);
|
|
if (settings is null)
|
|
{
|
|
settings = new UserSettings { UserId = UserId };
|
|
db.UserSettings.Add(settings);
|
|
}
|
|
|
|
settings.HouseholdSize = updated.HouseholdSize;
|
|
await db.SaveChangesAsync();
|
|
return Ok(settings);
|
|
}
|
|
}
|