Endopoint presque fini
This commit is contained in:
30
PF3/Endpoints/Staff/GetAllStaffEndpoint.cs
Normal file
30
PF3/Endpoints/Staff/GetAllStaffEndpoint.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PF3.DTO.Staff.Response;
|
||||
|
||||
namespace PF3.Endpoints.Staff;
|
||||
|
||||
public class GetAllStaffEndpoint(PF3DbContext pf3DbContext) : EndpointWithoutRequest<List<ReadStaffDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/staff");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
var staffs = await pf3DbContext.Staffs.ToListAsync(ct);
|
||||
|
||||
var result = staffs.Select(s => new ReadStaffDto
|
||||
{
|
||||
Id = s.Id,
|
||||
FirstName = s.FirstName,
|
||||
LastName = s.LastName,
|
||||
Profession = s.Profession,
|
||||
Email = s.Email
|
||||
}).ToList();
|
||||
|
||||
await Send.OkAsync(result, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user