diff options
Diffstat (limited to 'Controllers/RafflesController.cs')
-rw-r--r-- | Controllers/RafflesController.cs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/Controllers/RafflesController.cs b/Controllers/RafflesController.cs index 82e05a4..c649b70 100644 --- a/Controllers/RafflesController.cs +++ b/Controllers/RafflesController.cs @@ -82,14 +82,30 @@ namespace BackendPIA.Controllers { [Authorize(Roles = "Administrator")] [HttpPost("{id:int}/play")] - public async Task<ActionResult<IEnumerable<RaffleWinner>>> Play(long id) { + public async Task<ActionResult<IEnumerable<WinnerDTO>>> Play(long id) { RafflePlayLogic logic = new RafflePlayLogic(_game_service, _service, id); bool result = await logic.Call(); if(!result) return BadRequest(new { ErrorMessage = logic.ErrorMessage }); - return Ok(logic.Winners); + return Ok(_mapper.Map<IEnumerable<WinnerDTO>>(logic.Winners)); + } + + [Authorize] + [HttpGet("{id:int}/winners")] + public async Task<ActionResult<IEnumerable<WinnerDTO>>> GetWinners(long id) { + var raffle = await _service.GetRaffle(id); + + if(raffle == null) + return NotFound(new NotFoundError(404, $"The raffle with id {id} doesn't exist.")); + + if(!raffle.IsClosed) + return NotFound(new NotFoundError(404, $"The raffle with id {id} doesn't have any winners yet.")); + + var result = await _service.GetRaffleWinners(id); + + return Ok(_mapper.Map<IEnumerable<WinnerDTO>>(result)); } } }
\ No newline at end of file |