provider added

This commit is contained in:
2025-12-04 15:56:02 +01:00
parent 604dd77fed
commit fc736e8525
8 changed files with 164 additions and 3 deletions

View 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);
}
}