Implements POST /account/update_name — writes Viewer.DisplayName and returns an empty array per the prod capture. Includes TDD test covering the persist side-effect. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SVSim.Database;
|
|
using SVSim.EmulatedEntrypoint.Models.Dtos.Requests.Account;
|
|
|
|
namespace SVSim.EmulatedEntrypoint.Controllers;
|
|
|
|
/// <summary>
|
|
/// /account/* — viewer profile mutations that aren't tied to a specific subsystem.
|
|
/// </summary>
|
|
public class AccountController : SVSimController
|
|
{
|
|
private readonly SVSimDbContext _db;
|
|
|
|
public AccountController(SVSimDbContext db)
|
|
{
|
|
_db = db;
|
|
}
|
|
|
|
[HttpPost("update_name")]
|
|
public async Task<IActionResult> UpdateName([FromBody] AccountUpdateNameRequest request)
|
|
{
|
|
if (!TryGetViewerId(out long viewerId)) return Unauthorized();
|
|
|
|
var viewer = await _db.Viewers.FirstAsync(v => v.Id == viewerId);
|
|
viewer.DisplayName = request.Name;
|
|
await _db.SaveChangesAsync();
|
|
|
|
// Prod returns `data: []` — empty array, not empty object. Use an empty array literal
|
|
// so the translation middleware emits the right msgpack shape.
|
|
return Ok(Array.Empty<object>());
|
|
}
|
|
}
|