34 lines
1014 B
C#
34 lines
1014 B
C#
using FastEndpoints;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using PyroFetes.DTO.Provider.Request;
|
|
using PyroFetes.DTO.Provider.Response;
|
|
|
|
namespace PyroFetes.Endpoints.Provider;
|
|
|
|
public class GetProviderEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetProviderRequest, GetProviderDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Get ("/api/providers/{@Id}", x => new { x.Id });
|
|
AllowAnonymous();
|
|
}
|
|
|
|
public override async Task HandleAsync(GetProviderRequest req, CancellationToken ct)
|
|
{
|
|
Models.ServiceProvider? databaseProvider = await pyroFetesDbContext.Providers.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
|
|
|
if (databaseProvider == null)
|
|
{
|
|
await Send.NotFoundAsync(ct);
|
|
return;
|
|
}
|
|
|
|
GetProviderDto dto = new()
|
|
{
|
|
Id = databaseProvider.Id,
|
|
Price = databaseProvider.Price,
|
|
};
|
|
|
|
await Send.OkAsync(dto, ct);
|
|
}
|
|
} |