using api.Interfaces;
using Microsoft.AspNetCore.Mvc;
using models.Core;
using models.Request;
using models.Response;
namespace api.Controllers;
///
/// Endpoints for Qr Code Generation
///
/// Injected QR Code Service
/// Injected Ticket Manager Service
[ApiController]
[Route("[controller]")]
public class TicketController(
IQrCodeGenerator qr,
ITicketManager ticketManager) : ControllerBase
{
///
/// Generates a Base64 String Qr Code
///
/// Base64 String Qr Code
[HttpPost("mint")]
public ActionResult 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);
}
}