Finalisation endpoints

This commit is contained in:
2025-11-13 15:11:34 +01:00
parent 5c12a45ae6
commit 3a09bfc8ad
20 changed files with 922 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Sound.Request;
namespace PyroFetes.Endpoints.Sound;
public class DeleteSoundEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<IdSoundto>
{
public override void Configure()
{
Delete("/api/sounds/{Id}");
AllowAnonymous();
}
public override async Task HandleAsync(IdSoundto req, CancellationToken ct)
{
if (!req.Id.HasValue)
{
await Send.NotFoundAsync(ct);
return;
}
var sound = await pyroFetesDbContext.Sounds
.Include(s => s.SoundTimecodes)
.FirstOrDefaultAsync(s => s.Id == req.Id.Value, ct);
if (sound is null)
{
await Send.NotFoundAsync(ct);
return;
}
// Supprimer les relations SoundTimecode associées si nécessaire
if (sound.SoundTimecodes != null && sound.SoundTimecodes.Any())
{
pyroFetesDbContext.SoundTimecodes.RemoveRange(sound.SoundTimecodes);
}
pyroFetesDbContext.Sounds.Remove(sound);
await pyroFetesDbContext.SaveChangesAsync(ct);
await Send.OkAsync(ct);
}
}