provider added
This commit is contained in:
34
PyroFetes/Endpoints/Provider/CreateProviderEndpoint.cs
Normal file
34
PyroFetes/Endpoints/Provider/CreateProviderEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using FastEndpoints;
|
||||
using PyroFetes.DTO.Provider.Request;
|
||||
using PyroFetes.DTO.Provider.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Provider;
|
||||
|
||||
public class CreateProviderEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateProviderDto, GetProviderDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/providers");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
public override async Task HandleAsync(CreateProviderDto req, CancellationToken ct)
|
||||
{
|
||||
var provider = new Models.ServiceProvider()
|
||||
{
|
||||
Price = req.Price
|
||||
};
|
||||
pyroFetesDbContext.Add(provider);
|
||||
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||
|
||||
GetProviderDto response = new GetProviderDto()
|
||||
{
|
||||
Id = provider.Id,
|
||||
Price = provider.Price
|
||||
};
|
||||
|
||||
await Send.OkAsync(response, ct);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user