Endopoint presque fini
This commit is contained in:
29
PF3/Endpoints/Staff/DeleteStaffEndpoint.cs
Normal file
29
PF3/Endpoints/Staff/DeleteStaffEndpoint.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user