42 lines
1.2 KiB
C#
42 lines
1.2 KiB
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("/staffs");
|
|
AllowAnonymous();
|
|
}
|
|
|
|
|
|
public override async Task HandleAsync(CreateStaffDto req, CancellationToken ct)
|
|
{
|
|
Models.Staff staff = new()
|
|
{
|
|
FirstName = req.FirstName,
|
|
LastName = req.LastName,
|
|
Profession = req.Profession,
|
|
Email = req.Email,
|
|
F4T2NumberApproval = req.F4T2NumberApproval,
|
|
F4T2ExpirationDate = req.F4T2ExpirationDate,
|
|
};
|
|
pyroFetesDbContext.Add(staff);
|
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
|
|
|
GetStaffDto response = new()
|
|
{
|
|
FirstName = staff.FirstName,
|
|
LastName = staff.LastName,
|
|
Profession = staff.Profession,
|
|
Email = staff.Email,
|
|
F4T2NumberApproval = staff.F4T2NumberApproval,
|
|
F4T2ExpirationDate = staff.F4T2ExpirationDate,
|
|
};
|
|
|
|
await Send.OkAsync(response, ct);
|
|
}
|
|
} |