Endopoint presque fini
This commit is contained in:
38
PF3/Endpoints/Staff/GetStaffEndpoint.cs
Normal file
38
PF3/Endpoints/Staff/GetStaffEndpoint.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user