37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using YD_TrainingCompetition_Api.Competition;
|
|
|
|
namespace YD_TrainingCompetition_Api.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public sealed class RosterController : ControllerBase
|
|
{
|
|
private readonly IRosterService _roster;
|
|
private readonly IParticipantDirectory _directory;
|
|
|
|
public RosterController(IRosterService roster, IParticipantDirectory directory)
|
|
{
|
|
_roster = roster;
|
|
_directory = directory;
|
|
}
|
|
|
|
[HttpGet("templates")]
|
|
public IActionResult Templates() => Ok(_roster.GetTemplates());
|
|
|
|
[HttpGet("load")]
|
|
public async Task<IActionResult> Load([FromQuery] string file, CancellationToken cancellationToken)
|
|
{
|
|
var rows = await _roster.LoadAsync(file, cancellationToken);
|
|
return Ok(rows);
|
|
}
|
|
|
|
[HttpPost("apply")]
|
|
public async Task<IActionResult> Apply([FromQuery] string file, CancellationToken cancellationToken)
|
|
{
|
|
var rows = await _roster.LoadAsync(file, cancellationToken);
|
|
_directory.ApplyRoster(rows);
|
|
return Ok(new { message = "applied", count = rows.Count, file });
|
|
}
|
|
}
|