Staff DTO / Request Finished 09/10
This commit is contained in:
35
PyroFetes/Endpoints/Staff/GetStaffEndpoint.cs
Normal file
35
PyroFetes/Endpoints/Staff/GetStaffEndpoint.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Staff.Request;
|
||||
using PyroFetes.DTO.Staff.Response;
|
||||
using FastEndpoints;
|
||||
|
||||
namespace PyroFetes.Endpoints.Staff;
|
||||
|
||||
public class GetStaffEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetStaffRequest, GetStaffDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get ("/api/Staffs/{@Id}", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetStaffRequest database, CancellationToken ct)
|
||||
{
|
||||
Models.Staff? databaseStaff = await pyroFetesDbContext.Staffs.SingleOrDefaultAsync(x => x.Id == database.Id, cancellationToken: ct);
|
||||
|
||||
if (databaseStaff == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
GetStaffDto dto = new()
|
||||
{
|
||||
Id = databaseStaff.Id,
|
||||
F4T2NumberApproval = databaseStaff.F4T2NumberApproval,
|
||||
F4T2ExpirationDate = databaseStaff.F4T2ExpirationDate,
|
||||
};
|
||||
|
||||
await Send.OkAsync(dto, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user