Staff DTO / Request Finished 09/10
This commit is contained in:
34
PyroFetes/Endpoints/Staff/CreateStaffEndpoint.cs
Normal file
34
PyroFetes/Endpoints/Staff/CreateStaffEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
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/availabilities");
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user