Files
SVSimServer/SVSim.EmulatedEntrypoint/Controllers/ArenaTwoPickController.cs
gamer147 f272690a31 feat(http): ArenaTwoPickController (6 actions)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 11:15:53 -04:00

61 lines
2.1 KiB
C#

using Microsoft.AspNetCore.Mvc;
using SVSim.EmulatedEntrypoint.Models.Dtos.Requests.ArenaTwoPick;
using SVSim.EmulatedEntrypoint.Services;
namespace SVSim.EmulatedEntrypoint.Controllers;
[Route("arena_two_pick")]
public class ArenaTwoPickController : SVSimController
{
private readonly IArenaTwoPickService _svc;
public ArenaTwoPickController(IArenaTwoPickService svc) => _svc = svc;
[HttpPost("top")]
public async Task<IActionResult> Top([FromBody] TopRequest _)
{
if (!TryGetViewerId(out var vid)) return Unauthorized();
return Ok(await _svc.GetTopAsync(vid));
}
[HttpPost("entry")]
public async Task<IActionResult> Entry([FromBody] EntryRequest req)
{
if (!TryGetViewerId(out var vid)) return Unauthorized();
return await GuardAsync(() => _svc.EntryAsync(vid, req.ConsumeItemType));
}
[HttpPost("class_choose")]
public async Task<IActionResult> ClassChoose([FromBody] ClassChooseRequest req)
{
if (!TryGetViewerId(out var vid)) return Unauthorized();
return await GuardAsync(() => _svc.ChooseClassAsync(vid, req.ClassId));
}
[HttpPost("card_choose")]
public async Task<IActionResult> CardChoose([FromBody] CardChooseRequest req)
{
if (!TryGetViewerId(out var vid)) return Unauthorized();
return await GuardAsync(() => _svc.ChooseCardAsync(vid, req.SelectedId));
}
[HttpPost("retire")]
public async Task<IActionResult> Retire([FromBody] RetireRequest _)
{
if (!TryGetViewerId(out var vid)) return Unauthorized();
return await GuardAsync(() => _svc.RetireAsync(vid));
}
[HttpPost("finish")]
public async Task<IActionResult> Finish([FromBody] FinishRequest _)
{
if (!TryGetViewerId(out var vid)) return Unauthorized();
return await GuardAsync(() => _svc.FinishAsync(vid));
}
private async Task<IActionResult> GuardAsync<T>(Func<Task<T>> action)
{
try { return Ok(await action()); }
catch (ArenaTwoPickException ex) { return BadRequest(new { error_code = ex.ErrorCode }); }
}
}