feat(account): /account/update_region_code (accept-only)

This commit is contained in:
gamer147
2026-06-12 23:01:53 -04:00
parent 56ef994275
commit b4a87792dc
3 changed files with 47 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using SVSim.Database;
using SVSim.EmulatedEntrypoint.Models.Dtos.Common;
using SVSim.EmulatedEntrypoint.Models.Dtos.Requests.Account;
namespace SVSim.EmulatedEntrypoint.Controllers;
@@ -46,4 +47,14 @@ public class AccountController : SVSimController
// so the translation middleware emits the right msgpack shape.
return Ok(Array.Empty<object>());
}
[HttpPost("update_region_code")]
public ActionResult<EmptyResponse> UpdateRegionCode([FromBody] AccountUpdateRegionCodeRequest _)
{
if (!TryGetViewerId(out long __)) return Unauthorized();
// No-op: actual region value is sent in the REGION_CODE HTTP header, which we
// don't currently consume server-side. The body carries only initialize_flag,
// which is a first-set-vs-update signal we have no use for yet.
return new EmptyResponse();
}
}

View File

@@ -0,0 +1,12 @@
using MessagePack;
using System.Text.Json.Serialization;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Requests.Account;
[MessagePackObject]
public class AccountUpdateRegionCodeRequest : BaseRequest
{
[JsonPropertyName("initialize_flag")]
[Key("initialize_flag")]
public int InitializeFlag { get; set; }
}

View File

@@ -0,0 +1,24 @@
using System.Net;
using System.Text;
using NUnit.Framework;
using SVSim.UnitTests.Infrastructure;
namespace SVSim.UnitTests.Controllers;
public class AccountControllerUpdateRegionCodeTests
{
[TestCase(0)]
[TestCase(1)]
public async Task UpdateRegionCode_accepts(int initializeFlag)
{
using var factory = new SVSimTestFactory();
long viewerId = await factory.SeedViewerAsync(tutorialState: 0);
using var client = factory.CreateAuthenticatedClient(viewerId);
var requestJson = $$"""{"initialize_flag":{{initializeFlag}},"viewer_id":"0","steam_id":0,"steam_session_ticket":""}""";
var response = await client.PostAsync("/account/update_region_code",
new StringContent(requestJson, Encoding.UTF8, "application/json"));
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
}
}