Files
PF3-fork/PyroFetes/Endpoints/Staff/GetStaffEndpoint.cs
2025-11-13 15:11:12 +01:00

38 lines
1002 B
C#

using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Staff.Request;
using PyroFetes.DTO.Staff.Response;
namespace PyroFetes.Endpoints.Staff;
public class GetStaffEndpoint(PyroFetesDbContext pf3DbContext) : Endpoint<IdStaffDto, ReadStaffDto>
{
public override void Configure()
{
Get("/api/staff/{Id}");
AllowAnonymous();
}
public override async Task HandleAsync(IdStaffDto req, CancellationToken ct)
{
var staff = await pf3DbContext.Staffs
.Where(s => s.Id == req.Id)
.Select(s => new ReadStaffDto
{
Id = s.Id,
FirstName = s.FirstName,
LastName = s.LastName,
Profession = s.Profession,
Email = s.Email
})
.FirstOrDefaultAsync(ct);
if (staff is null)
{
await Send.NotFoundAsync(ct);
return;
}
await Send.OkAsync(staff, ct);
}
}