Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Use Ticket API endpoint #152

Merged
merged 1 commit into from
May 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions coffeecard/CoffeeCard.WebApi/Controllers/TicketsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
using System.Threading.Tasks;
using CoffeeCard.Common.Errors;
using CoffeeCard.Library.Services;
using CoffeeCard.Library.Utils;
using CoffeeCard.Models.DataTransferObjects.Ticket;
using CoffeeCard.Models.DataTransferObjects.v2.Ticket;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -21,14 +23,18 @@ public class TicketsController : ControllerBase
{
private readonly IMapperService _mapperService;
private readonly ITicketService _ticketService;
private readonly Library.Services.v2.ITicketService _ticketServiceV2;
private readonly ClaimsUtilities _claimsUtilities;

/// <summary>
/// Initializes a new instance of the <see cref="TicketsController"/> class.
/// </summary>
public TicketsController(ITicketService ticketService, IMapperService mapperService)
public TicketsController(ITicketService ticketService, IMapperService mapperService, Library.Services.v2.ITicketService ticketServiceV2, ClaimsUtilities claimsUtilities)
{
_ticketService = ticketService;
_mapperService = mapperService;
_ticketServiceV2 = ticketServiceV2;
_claimsUtilities = claimsUtilities;
}

/// <summary>
Expand Down Expand Up @@ -73,14 +79,15 @@ public async Task<ActionResult<List<TicketDto>>> UseMultipleTickets([FromBody] U
/// <response code="200">Successful request</response>
/// <response code="400">Bad Request, not enough tickets. See explanation</response>
/// <response code="401">Invalid credentials</response>
[ProducesResponseType(typeof(TicketDto), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(UsedTicketResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiException), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
[HttpPost("use")]
public async Task<ActionResult<TicketDto>> Use([FromBody] UseTicketDTO dto)
public async Task<ActionResult<UsedTicketResponse>> Use([FromBody] UseTicketDTO dto)
{
var usedTicket = await _ticketService.UseTicket(User.Claims, dto.ProductId);
return Ok(_mapperService.Map(usedTicket));
var user = await _claimsUtilities.ValidateAndReturnUserFromClaimAsync(User.Claims);

return await _ticketServiceV2.UseTicketAsync(user, dto.ProductId);
}
}
}