b3612f5bec
- Strip /api prefix from all endpoint routes - Make Show.CityId nullable (no longer required FK) - Drop CityId FK constraint and alter column to NULL at startup via raw SQL - Add migration MakeCityIdNullable for schema consistency - Update Show DTOs to reflect nullable CityId Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
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("/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);
|
|
}
|
|
}
|