27 lines
1013 B
C#
27 lines
1013 B
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using PlotLine.Data;
|
|
using PlotLine.Services;
|
|
namespace PlotLine.Controllers;
|
|
|
|
[Authorize]
|
|
public sealed class AppearanceController(ICurrentUserService user, IAppearanceRepository preferences) : Controller
|
|
{
|
|
[HttpPost, ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Theme(string themeKey, bool onlyIfUnset = false)
|
|
{
|
|
if (user.UserId is not int id) return Unauthorized();
|
|
if (!ModelState.IsValid || !ApplicationAppearance.IsValid(themeKey)) return BadRequest();
|
|
await preferences.SaveThemeAsync(id, themeKey, onlyIfUnset);
|
|
return Json(await preferences.GetAsync(id));
|
|
}
|
|
[HttpPost, ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Ribbon(bool collapsed)
|
|
{
|
|
if (user.UserId is not int id) return Unauthorized();
|
|
if (!ModelState.IsValid) return BadRequest();
|
|
await preferences.SaveRibbonAsync(id, collapsed);
|
|
return Ok();
|
|
}
|
|
}
|