ticket-system/source/ticketAPI/api/Controllers/TicketController.cs
Tara Wilson 3bb86da5c0 Adding Mongo Support
Building out UI
Building out API
Refactoring
Cleaning up
2024-11-29 14:48:17 -05:00

55 lines
1.3 KiB
C#

using api.Interfaces;
using Microsoft.AspNetCore.Mvc;
using models.Core;
using models.Request;
using models.Response;
namespace api.Controllers;
/// <summary>
/// Endpoints for Qr Code Generation
/// </summary>
/// <param name="qr">Injected QR Code Service</param>
/// <param name="ticketManager">Injected Ticket Manager Service</param>
[ApiController]
[Route("[controller]")]
public class TicketController(
IQrCodeGenerator qr,
ITicketManager ticketManager) : ControllerBase
{
/// <summary>
/// Generates a Base64 String Qr Code
/// </summary>
/// <returns>Base64 String Qr Code</returns>
[HttpPost("mint")]
public ActionResult<MintResponse> MintTicket([FromBody] MintTickets mintRequest)
{
//TODO: Protect Endpoint
//generate ticket id
var ticketId = Guid.NewGuid();
//generate the qr code
var qrCode = qr.GenerateQrCode(ticketId.ToString());
//build the ticket
var ticket = new Ticket
{
Id = Guid.NewGuid(),
QrCode = qrCode,
Type = mintRequest.Type,
};
//save the minted ticket
ticketManager.SaveMintedTicket(ticket);
//return
var response = new MintResponse
{
QrCode = ticket.QrCode,
Type = ticket.Type
};
return Ok(response);
}
}