feat(emblem): /emblem/update_emblem sets viewer.SelectedEmblem (ownership-validated)

This commit is contained in:
gamer147
2026-06-13 08:16:19 -04:00
parent bc110e2274
commit 911374106f
3 changed files with 91 additions and 0 deletions

View File

@@ -47,4 +47,24 @@ public class EmblemController : SVSimController
// via the shared Wizard/FavoriteTask.cs Kind enum).
return new EmptyResponse();
}
[HttpPost("update_emblem")]
public async Task<ActionResult<EmptyResponse>> Update(EmblemUpdateRequest request, CancellationToken ct)
{
if (!TryGetViewerId(out long viewerId)) return Unauthorized();
var viewer = await _db.Viewers
.Include(v => v.Emblems)
.FirstOrDefaultAsync(v => v.Id == viewerId, ct);
if (viewer is null) return Unauthorized();
// EmblemEntry.Id is int; cast the wire long once at the boundary.
var owned = viewer.Emblems.FirstOrDefault(e => e.Id == (int)request.EmblemId);
if (owned is null)
return BadRequest(new { error = "emblem_not_owned" });
viewer.Info.SelectedEmblem = owned;
await _db.SaveChangesAsync(ct);
return new EmptyResponse();
}
}

View File

@@ -0,0 +1,13 @@
using MessagePack;
using System.Text.Json.Serialization;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Requests.Emblem;
[MessagePackObject]
public class EmblemUpdateRequest : BaseRequest
{
// Spec note: emblem_id is a long on the wire (UserInfo.SelectedEmblemId is also long).
[JsonPropertyName("emblem_id")]
[Key("emblem_id")]
public long EmblemId { get; set; }
}