feat(user-mypage): UserMyPageController + DTOs + persistence tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-09 16:46:49 -04:00
parent b447f5032d
commit 9ff6c70faf
4 changed files with 240 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using SVSim.Database;
using SVSim.Database.Models;
using SVSim.EmulatedEntrypoint.Models.Dtos.UserMyPage;
namespace SVSim.EmulatedEntrypoint.Controllers;
/// <summary>
/// /user_mypage/* — viewer-scoped MyPage configuration writes. Separate from the
/// <c>/mypage/*</c> family because the wire URL family is distinct.
/// </summary>
[Route("user_mypage")]
public sealed class UserMyPageController : SVSimController
{
private readonly SVSimDbContext _db;
public UserMyPageController(SVSimDbContext db) => _db = db;
[HttpPost("update")]
public async Task<ActionResult<UserMyPageUpdateResponse>> Update(
[FromBody] UserMyPageUpdateRequest request,
CancellationToken ct)
{
if (!TryGetViewerId(out var viewerId)) return Unauthorized();
var viewer = await _db.Viewers
.Include(v => v.MyPageBgRotation)
.FirstOrDefaultAsync(v => v.Id == viewerId, ct);
if (viewer is null) return NotFound();
viewer.MyPageBgSelectType = request.SelectType;
viewer.MyPageBgId = ParseIdOrZero(request.MyPageId);
viewer.MyPageBgRotation.Clear();
for (int slot = 0; slot < request.MyPageIdList.Count; slot++)
{
viewer.MyPageBgRotation.Add(new MyPageBgRotationEntry
{
Slot = slot,
BgId = ParseIdOrZero(request.MyPageIdList[slot]),
});
}
await _db.SaveChangesAsync(ct);
return new UserMyPageUpdateResponse();
}
private static int ParseIdOrZero(string s) =>
int.TryParse(s, out var n) ? n : 0;
}

View File

@@ -0,0 +1,28 @@
using System.Text.Json.Serialization;
using MessagePack;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.UserMyPage;
/// <summary>
/// Body of <c>POST /user_mypage/update</c>. Client task: <c>MyPageSettingUpdateTask</c>
/// (Shadowverse_Code_2026-05-23/Wizard/MyPageSettingUpdateTask.cs). Note that
/// <c>select_type</c> is the only int on the wire — id fields are strings.
/// </summary>
[MessagePackObject]
public sealed class UserMyPageUpdateRequest
{
/// <summary>BGType enum: 0=Deck, 1=CustomBG, 2=RandomBG. Client sends as an int.</summary>
[JsonPropertyName("select_type")]
[Key("select_type")]
public int SelectType { get; set; }
/// <summary>Chosen BG id when SelectType=CustomBG; empty or "0" otherwise.</summary>
[JsonPropertyName("mypage_id")]
[Key("mypage_id")]
public string MyPageId { get; set; } = "0";
/// <summary>Saved rotation pool, in slot order; client sends the full list on every call.</summary>
[JsonPropertyName("mypage_id_list")]
[Key("mypage_id_list")]
public List<string> MyPageIdList { get; set; } = new();
}

View File

@@ -0,0 +1,12 @@
using MessagePack;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.UserMyPage;
/// <summary>
/// Empty response payload. The client's <c>MyPageSettingUpdateTask.Parse()</c> is the default
/// pass-through; server just acknowledges.
/// </summary>
[MessagePackObject(true)]
public sealed class UserMyPageUpdateResponse
{
}