6c1330e570
- Register FastEndpoints, SwaggerDocument, DbContext in Program.cs - Add DbContextOptions constructor to PyroFetesDbContext - Add CityId to Show DTOs and endpoints (NOT NULL in DB) - Add F4T2NumberApproval/F4T2ExpirationDate to Staff DTOs and endpoints - Simplify DeleteShow to rely on DB cascade instead of manual includes - Default NOT NULL string fields to empty string on create Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
38 lines
903 B
C#
38 lines
903 B
C#
using FastEndpoints;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using PyroFetes.DTO.Show.Request;
|
|
|
|
namespace PyroFetes.Endpoints.Show;
|
|
|
|
public class DeleteShowEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<IdShowDto>
|
|
{
|
|
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);
|
|
}
|
|
}
|