using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Show.Request; namespace PyroFetes.Endpoints.Show; public class DeleteShowEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint { public override void Configure() { Delete("/api/shows/{Id}"); AllowAnonymous(); } public override async Task HandleAsync(IdShowDto req, CancellationToken ct) { if (!req.Id.HasValue) { await Send.NotFoundAsync(ct); return; } var show = await pyroFetesDbContext.Shows .FirstOrDefaultAsync(s => s.Id == req.Id.Value, ct); if (show is null) { await Send.NotFoundAsync(ct); return; } pyroFetesDbContext.Shows.Remove(show); await pyroFetesDbContext.SaveChangesAsync(ct); await Send.OkAsync(ct); } }