diff options
Diffstat (limited to 'Controllers/RafflesController.cs')
-rw-r--r-- | Controllers/RafflesController.cs | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/Controllers/RafflesController.cs b/Controllers/RafflesController.cs index 4b25519..0da75d5 100644 --- a/Controllers/RafflesController.cs +++ b/Controllers/RafflesController.cs @@ -24,12 +24,12 @@ namespace BackendPIA.Controllers { [HttpGet] public async Task<ActionResult<IEnumerable<RaffleDTO>>> Index([FromQuery] string name = "") { var result = await _service.GetRaffles(name); - + return Ok(_mapper.Map<IEnumerable<RaffleDTO>>(result)); } [HttpGet("{id:int}")] - public async Task<ActionResult<RaffleDTO>> Show(long id) { + public async Task<ActionResult<RaffleDTO>> Show(long id) { var raffle = await _service.GetRaffle(id); if(raffle == null) @@ -76,8 +76,11 @@ namespace BackendPIA.Controllers { IEnumerable<int> available_tickets = from number in Enumerable.Range(1, 54) select number; IEnumerable<int> taken_tickets = await _service.GetTakenTickets(id); + if(!_service.RaffleExists(id)) + return NotFound(new NotFoundError(404, $"The raffle with id {id} doesn't exist.")); + if(!taken_tickets.Any()) - return NotFound(new NotFoundError(404, $"The raffle with id {id} doesn't exist or doesn't have any tickets.")); + return Ok(new { Numbers = available_tickets }); return Ok(new { Numbers = available_tickets.Except(taken_tickets) }); } @@ -87,7 +90,7 @@ namespace BackendPIA.Controllers { 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 }); @@ -109,5 +112,17 @@ namespace BackendPIA.Controllers { return Ok(_mapper.Map<IEnumerable<WinnerDTO>>(result)); } + + [HttpGet("{id:int}/prizes")] + public async Task<ActionResult<IEnumerable<PrizeDTO>>> GetPrizes(long id) { + var raffle = await _service.GetRaffle(id); + + if(raffle == null) + return NotFound(new NotFoundError(404, $"The raffle with id {id} doesn't exist.")); + + var prizes = _service.GetRaffleTickets(id); + + return Ok(_mapper.Map<IEnumerable<PrizeDTO>>(prizes)); + } } }
\ No newline at end of file |