diff options
author | HombreLaser <sebastian-440@live.com> | 2022-11-26 15:55:40 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2022-11-26 15:55:40 -0600 |
commit | 45eb6bcac6eaa57efba955dd45aad46f988aaf35 (patch) | |
tree | 1d87dfdc4e962a35b76e9db9e554c090938e5fc7 /Controllers/RafflesController.cs | |
parent | 9fa6c5512cf229bd84ba131577f4a8d2b1efb770 (diff) |
Corregido error de mappeo.
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 |