Files
Projet4/PyroFetes/Endpoints/Provider/GetAllProvidersEndpoint.cs
T

27 lines
835 B
C#

using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Provider.Response;
namespace PyroFetes.Endpoints.Provider;
public class GetAllProvidersEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetProviderDto>>
{
public override void Configure()
{
Get ("/serviceproviders");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetProviderDto> provider= await pyroFetesDbContext.ServiceProviders.Include(x => x.ProviderType).Select(x => new GetProviderDto()
{
Id = x.Id,
Price = x.Price,
ProviderTypeId = x.ProviderTypeId,
ProviderType = x.ProviderType.Label,
}).ToListAsync(ct);
await Send.OkAsync(provider, ct);
}
}