Staff DTO / Request Finished 09/10
This commit is contained in:
30
PyroFetes/Endpoints/Staff/DeleteStaffEndpoint.cs
Normal file
30
PyroFetes/Endpoints/Staff/DeleteStaffEndpoint.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user