using FastEndpoints; using PyroFetes.DTO.Show.Request; using PyroFetes.DTO.Show.Response; namespace PyroFetes.Endpoints.Show; public class CreateShowEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint { public override void Configure() { Post("/api/shows"); AllowAnonymous(); } public override async Task HandleAsync(CreateShowDto req, CancellationToken ct) { var show = new PyroFetes.Models.Show { Name = req.Name, Place = req.Place, Description = req.Description, PyrotechnicImplementationPlan = req.PyrotechnicImplementationPlan, Date = req.Date.HasValue ? DateOnly.FromDateTime(req.Date.Value) : null }; pyroFetesDbContext.Shows.Add(show); await pyroFetesDbContext.SaveChangesAsync(ct); var result = new ReadShowDto { Id = show.Id, Name = show.Name, Place = show.Place, Description = show.Description, PyrotechnicImplementationPlan = show.PyrotechnicImplementationPlan, Date = show.Date.HasValue ? show.Date.Value.ToDateTime(TimeOnly.MinValue) : null }; await Send.OkAsync(result, ct); } }