78 lines
2.1 KiB
C#
78 lines
2.1 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
|
|
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
|
|
|
namespace WebEMSim.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class TournamentController : ControllerBase
|
|
{
|
|
// GET: api/<TournamentController>
|
|
[HttpGet]
|
|
public IEnumerable<string> Get()
|
|
{
|
|
return Storage.Shared.ListTournaments();
|
|
}
|
|
|
|
// GET api/<TournamentController>/5
|
|
[HttpGet("{id}")]
|
|
public IActionResult Get(string id)
|
|
{
|
|
Tournament? tournament = Storage.Shared.GetTournament(id);
|
|
|
|
if(tournament == null)
|
|
return NotFound();
|
|
|
|
return Ok(tournament);
|
|
}
|
|
|
|
// POST api/<TournamentController>
|
|
[HttpPost]
|
|
public IActionResult Post(/*[FromBody] string value*/)
|
|
{
|
|
Tournament? newTournament = Storage.Shared.CreateTournament();
|
|
|
|
if(newTournament == null)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
}
|
|
|
|
newTournament.PlayoutTournament(); // TODO: Remove this
|
|
|
|
return Ok(newTournament);
|
|
}
|
|
|
|
// POST api/<TournamentController>/{id}/play
|
|
[HttpPost("{id}/play")]
|
|
public IActionResult Post(string id)
|
|
{
|
|
Tournament? tournament = Storage.Shared.GetTournament(id);
|
|
|
|
if (tournament == null)
|
|
return NotFound();
|
|
|
|
if (tournament.HasPlayed == true)
|
|
return BadRequest();
|
|
|
|
tournament.PlayoutTournament();
|
|
|
|
return Ok(tournament);
|
|
}
|
|
|
|
// DELETE api/<TournamentController>/5
|
|
[HttpDelete("{id}")]
|
|
public IActionResult Delete(string id)
|
|
{
|
|
bool? success = Storage.Shared.DeleteTournament(id);
|
|
|
|
if (success == null)
|
|
return NotFound();
|
|
|
|
if(success != true)
|
|
return StatusCode(StatusCodes.Status500InternalServerError);
|
|
|
|
return Ok();
|
|
}
|
|
}
|
|
}
|