feat(config): persist is_foil_preferred + is_prize_preferred (stubs → real)

This commit is contained in:
gamer147
2026-06-13 09:54:51 -04:00
parent 911374106f
commit 13ca7d118e
8 changed files with 4783 additions and 13 deletions

View File

@@ -1,31 +1,42 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using SVSim.Database;
using SVSim.EmulatedEntrypoint.Models.Dtos.Common;
using SVSim.EmulatedEntrypoint.Models.Dtos.Requests;
namespace SVSim.EmulatedEntrypoint.Controllers;
/// <summary>
/// /config/* — viewer-scoped preference toggles. Fired by the client as fire-and-forget
/// after the deck-builder save flow (and from settings screens). Currently acknowledge-only:
/// UserConfig is stubbed in load/index + mypage/index until a viewer-config persistence
/// layer lands. Mirrors the set_deck_redis precedent (no-op accept).
/// /config/* — viewer-scoped preference toggles. Persists to ViewerInfo; reads back through
/// /load/index + /mypage/index user_config.
/// </summary>
public class ConfigController : SVSimController
{
private readonly SVSimDbContext _db;
public ConfigController(SVSimDbContext db) => _db = db;
[HttpPost("update_foil_preferred")]
public ActionResult<EmptyResponse> UpdateFoilPreferred(ConfigUpdateFoilPreferredRequest request)
public async Task<ActionResult<EmptyResponse>> UpdateFoilPreferred(
ConfigUpdateFoilPreferredRequest request, CancellationToken ct)
{
if (!TryGetViewerId(out long _)) return Unauthorized();
// TODO(viewer-config-persist): write request.IsFoilPreferred onto the viewer's config row
// and read it back in load/index + mypage/index instead of `new UserConfig()`.
if (!TryGetViewerId(out long viewerId)) return Unauthorized();
var viewer = await _db.Viewers.FirstOrDefaultAsync(v => v.Id == viewerId, ct);
if (viewer is null) return Unauthorized();
viewer.Info.IsFoilPreferred = request.IsFoilPreferred != 0;
await _db.SaveChangesAsync(ct);
return new EmptyResponse();
}
[HttpPost("update_prize_preferred")]
public ActionResult<EmptyResponse> UpdatePrizePreferred(ConfigUpdatePrizePreferredRequest request)
public async Task<ActionResult<EmptyResponse>> UpdatePrizePreferred(
ConfigUpdatePrizePreferredRequest request, CancellationToken ct)
{
if (!TryGetViewerId(out long _)) return Unauthorized();
// TODO(viewer-config-persist): see UpdateFoilPreferred.
if (!TryGetViewerId(out long viewerId)) return Unauthorized();
var viewer = await _db.Viewers.FirstOrDefaultAsync(v => v.Id == viewerId, ct);
if (viewer is null) return Unauthorized();
viewer.Info.IsPrizePreferred = request.IsPrizePreferred != 0;
await _db.SaveChangesAsync(ct);
return new EmptyResponse();
}
}