Files
AP-WEB-PF3/PF3/Endpoints/Staff/GetStaffEndpoint.cs
2025-10-16 17:00:36 +02:00

38 lines
978 B
C#

using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PF3.DTO.Staff.Request;
using PF3.DTO.Staff.Response;
namespace PF3.Endpoints.Staff;
public class GetStaffEndpoint(PF3DbContext 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);
}
}