forked from sanchezvem/PyroFetes
38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using FastEndpoints;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace PyroFetes.Endpoints.Classification;
|
|
|
|
public class DeleteClassificationRequest
|
|
{
|
|
public int Id { get; set; }
|
|
}
|
|
|
|
public class DeleteClassificationEndpoint(PyroFetesDbContext libraryDbContext) : Endpoint<DeleteClassificationRequest>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Delete("/api/classifications/{@id}", x => new { x.Id });
|
|
AllowAnonymous();
|
|
}
|
|
|
|
public override async Task HandleAsync(DeleteClassificationRequest req, CancellationToken ct)
|
|
{
|
|
|
|
Models.Classification? classificationToDelete = await libraryDbContext
|
|
.Classifications
|
|
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
|
|
|
if (classificationToDelete == null)
|
|
{
|
|
Console.WriteLine($"Aucune classification avec l'ID {req.Id} trouvé.");
|
|
await Send.NotFoundAsync(ct);
|
|
return;
|
|
}
|
|
|
|
libraryDbContext.Classifications.Remove(classificationToDelete);
|
|
await libraryDbContext.SaveChangesAsync(ct);
|
|
|
|
await Send.NoContentAsync(ct);
|
|
}
|
|
} |