Files
LaDOSE/LaDOSE.Src/LaDOSE.Api/Controllers/TournamentController.cs

59 lines
1.7 KiB
C#
Raw Normal View History

2019-05-29 02:15:31 +02:00
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
2020-09-13 22:50:52 +02:00
using AutoMapper;
2019-05-29 02:15:31 +02:00
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 TournamentController : Controller
{
private IEventService _service;
2020-09-13 22:50:52 +02:00
private IMapper _mapper;
2019-05-29 02:15:31 +02:00
// GET
public TournamentController(IMapper mapper, IEventService service)
2019-05-29 02:15:31 +02:00
{
2020-09-13 22:50:52 +02:00
_mapper = mapper;
2019-05-29 02:15:31 +02:00
_service = service;
}
//This may be a get , but i dont know what the RFC State for Get request with Body
//As i don't like to populate GET request with body this will be a post (and i think
//it will be easier to proxy.
[HttpPost("GetTournaments")]
public async Task<List<TournamentDTO>> GetChallonges([FromBody] TimeRangeDTO dto)
2019-05-29 02:15:31 +02:00
{
if (dto.To.HasValue | dto.From.HasValue)
{
var tournaments = await _service.GetTournaments(dto.From, dto.To);
2020-09-13 22:50:52 +02:00
return _mapper.Map<List<TournamentDTO>>(tournaments);
}
return null;
}
[HttpPost("GetResults")]
public async Task<TournamentsResultDTO> GetResults([FromBody] List<int> ids)
{
if (ids == null)
{
throw new Exception("Invalid arguments");
}
var tournamentsResult = await _service.GetTournamentsResult(ids);
2020-09-13 22:50:52 +02:00
return _mapper.Map<TournamentsResultDTO>(tournamentsResult);
2019-05-29 02:15:31 +02:00
}
2019-05-29 02:15:31 +02:00
}
}