Renommage d'un endpoint
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Staff.Request;
|
||||
using PyroFetes.DTO.Staff.Response;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace PyroFetes.Endpoints.Staff;
|
||||
|
||||
public class UpdateStaffEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <UpdateStaffDto, GetStaffDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put ("/staffs/{@Id}", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateStaffDto 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;
|
||||
}
|
||||
else
|
||||
{
|
||||
databaseStaff.F4T2NumberApproval = req.F4T2NumberApproval;
|
||||
databaseStaff.F4T2ExpirationDate = req.F4T2ExpirationDate;
|
||||
}
|
||||
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||
|
||||
GetStaffDto dto = new()
|
||||
{
|
||||
Id = databaseStaff.Id,
|
||||
FirstName = databaseStaff.FirstName,
|
||||
LastName = databaseStaff.LastName,
|
||||
Profession = databaseStaff.Profession,
|
||||
Email = databaseStaff.Email,
|
||||
F4T2NumberApproval = req.F4T2NumberApproval,
|
||||
F4T2ExpirationDate = req.F4T2ExpirationDate,
|
||||
};
|
||||
|
||||
await Send.OkAsync(dto, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user