Staff DTO / Request Finished 09/10

This commit is contained in:
2025-10-09 17:48:07 +02:00
parent df81c7b12d
commit 5cbbfa1434
9 changed files with 172 additions and 3 deletions

View File

@@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Staff.Request;
using PyroFetes.DTO.Staff.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Staff;
public class DeleteStaffEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetStaffRequest, GetStaffDto>
{
public override void Configure()
{
Delete ("/api/staff/{@Id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(GetStaffRequest req, CancellationToken ct)
{
Models.Staff? databaseStaff = await pyroFetesDbContext.Staffs.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (databaseStaff == null)
{
await Send.NotFoundAsync(ct);
return;
}
pyroFetesDbContext.Staffs.Remove(databaseStaff);
await pyroFetesDbContext.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}