provider added
This commit is contained in:
38
PyroFetes/Endpoints/Provider/UpdateProviderEndpoint.cs
Normal file
38
PyroFetes/Endpoints/Provider/UpdateProviderEndpoint.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Provider.Request;
|
||||
using PyroFetes.DTO.Provider.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Provider;
|
||||
|
||||
public class UpdateProviderEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <UpdateProviderDto, GetProviderDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put ("/api/providers/{@Id}", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateProviderDto 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;
|
||||
}
|
||||
else
|
||||
{
|
||||
databaseProvider.Price = req.Price;
|
||||
}
|
||||
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||
|
||||
GetProviderDto dto = new()
|
||||
{
|
||||
Id = databaseProvider.Id,
|
||||
};
|
||||
|
||||
await Send.OkAsync(dto, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user