63 lines
2.4 KiB
C#
63 lines
2.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using AutoMapper;
|
|
using LaDOSE.Business.Interface;
|
|
using LaDOSE.DTO;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace LaDOSE.Api.Controllers
|
|
{
|
|
[Authorize]
|
|
[Produces("application/json")]
|
|
[Route("api/[controller]")]
|
|
public class StatisticsController : Controller
|
|
{
|
|
private readonly IStatisticsService _service;
|
|
private readonly IMapper _mapper;
|
|
|
|
public StatisticsController(IMapper mapper, IStatisticsService service)
|
|
{
|
|
_mapper = mapper;
|
|
_service = service;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Match statistics for the given Event ids. Body is a bare JSON array of ids,
|
|
/// like TournamentController.GetResults.
|
|
/// A null or empty array returns a zeroed, empty MatchStatsDTO rather than an error.
|
|
/// Read Coverage before trusting the numbers: many brackets have no set rows at all.
|
|
/// </summary>
|
|
[HttpPost("Matches")]
|
|
public async Task<MatchStatsDTO> GetMatchStats([FromBody] List<int> ids)
|
|
{
|
|
var stats = await _service.GetMatchStats(ids);
|
|
return _mapper.Map<MatchStatsDTO>(stats);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The players a versus lookup can report on: everyone with at least one set in a
|
|
/// bracket whose game is known, by display name. Not the application users —
|
|
/// these are tournament players, the entities set rows point at.
|
|
/// </summary>
|
|
[HttpGet("Players")]
|
|
public async Task<List<PlayerOptionDTO>> GetVersusPlayers()
|
|
{
|
|
var players = await _service.GetVersusPlayers();
|
|
return _mapper.Map<List<PlayerOptionDTO>>(players);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Every recorded meeting between two players, across all events, split per game.
|
|
/// Sets played in a bracket with no game attached are excluded and only counted in
|
|
/// UnknownGameSets. Two identical or unknown ids return an empty breakdown, not an error.
|
|
/// </summary>
|
|
[HttpGet("Versus/{playerAId}/{playerBId}")]
|
|
public async Task<PlayerVersusDTO> GetVersus(int playerAId, int playerBId)
|
|
{
|
|
var versus = await _service.GetVersus(playerAId, playerBId);
|
|
return _mapper.Map<PlayerVersusDTO>(versus);
|
|
}
|
|
}
|
|
}
|