provider added
This commit is contained in:
34
PyroFetes/Endpoints/Provider/GetProviderEndpoint.cs
Normal file
34
PyroFetes/Endpoints/Provider/GetProviderEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user