Files
Projet4/PyroFetes/Endpoints/Staff/CreateStaffEndpoint.cs
2025-12-04 15:29:23 +01:00

34 lines
933 B
C#

using FastEndpoints;
using PyroFetes.DTO.Staff.Request;
using PyroFetes.DTO.Staff.Response;
namespace PyroFetes.Endpoints.Staff;
public class CreateStaffEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateStaffDto, GetStaffDto>
{
public override void Configure()
{
Post("/api/staffs");
AllowAnonymous();
}
public override async Task HandleAsync(CreateStaffDto req, CancellationToken ct)
{
Models.Staff staff = new()
{
F4T2NumberApproval = req.F4T2NumberApproval,
F4T2ExpirationDate = req.F4T2ExpirationDate,
};
pyroFetesDbContext.Add(staff);
await pyroFetesDbContext.SaveChangesAsync(ct);
GetStaffDto response = new()
{
F4T2NumberApproval = staff.F4T2NumberApproval,
F4T2ExpirationDate = staff.F4T2ExpirationDate,
};
await Send.OkAsync(response, ct);
}
}