Endopoint presque fini

This commit is contained in:
2025-10-16 17:00:36 +02:00
parent 8d0c2aa3f6
commit ec5149b6da
28 changed files with 551 additions and 31 deletions

View File

@@ -0,0 +1,29 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PF3.DTO.Staff.Request;
namespace PF3.Endpoints.Staff;
public class DeleteStaffEndpoint(PF3DbContext pf3DbContext) : Endpoint<IdStaffDto>
{
public override void Configure()
{
Delete("/api/staff/{Id}");
AllowAnonymous();
}
public override async Task HandleAsync(IdStaffDto req, CancellationToken ct)
{
var staff = await pf3DbContext.Staffs.FirstOrDefaultAsync(s => s.Id == req.Id, ct);
if (staff is null)
{
await Send.NotFoundAsync(ct);
return;
}
pf3DbContext.Staffs.Remove(staff);
await pf3DbContext.SaveChangesAsync(ct);
await Send.OkAsync(ct);
}
}