Finalisation endpoints
This commit is contained in:
53
PyroFetes/Endpoints/Show/DeleteShowEndpoint.cs
Normal file
53
PyroFetes/Endpoints/Show/DeleteShowEndpoint.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
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
|
||||
.Include(s => s.ShowTrucks)
|
||||
.Include(s => s.ShowStaffs)
|
||||
.Include(s => s.SoundTimecodes)
|
||||
.Include(s => s.ProductTimecodes)
|
||||
.Include(s => s.Contracts)
|
||||
.Include(s => s.ShowMaterials)
|
||||
.FirstOrDefaultAsync(s => s.Id == req.Id.Value, ct);
|
||||
|
||||
if (show is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
// Supprimer les relations associées
|
||||
if (show.ShowTrucks != null && show.ShowTrucks.Any())
|
||||
{
|
||||
pyroFetesDbContext.ShowTrucks.RemoveRange(show.ShowTrucks);
|
||||
}
|
||||
|
||||
// Note: Les autres relations (ShowStaffs, SoundTimecodes, etc.) devront aussi être gérées
|
||||
// en fonction de votre modèle de données et de vos règles métier
|
||||
// Pour l'instant, je laisse juste ShowTrucks comme exemple
|
||||
|
||||
pyroFetesDbContext.Shows.Remove(show);
|
||||
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||
|
||||
await Send.OkAsync(ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user