Files
Projet4/PyroFetes/Endpoints/HistoryOfApproval/UpdateHistoryOfApprovalEndpoint.cs
carteronm 4e64112a31 First Commit 09/10
# Conflicts:
#	PyroFetes/PyroFetes.csproj
2025-10-16 17:34:55 +02:00

41 lines
1.4 KiB
C#

using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.HistoryOfApproval.Request;
using PyroFetes.DTO.HistoryOfApproval.Response;
namespace PyroFetes.Endpoints.HistoryOfApproval;
public class UpdateHistoryOfApprovalEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <UpdateHistoryOfApprovalDto, GetHistoryOfApprovalDto>
{
public override void Configure()
{
Put ("/api/HistoryOfApprovals/{@Id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(UpdateHistoryOfApprovalDto req, CancellationToken ct)
{
Models.HistoryOfApproval? databaseHistoryOfApproval = await pyroFetesDbContext.HistoryOfApprovals.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (databaseHistoryOfApproval == null)
{
await Send.NotFoundAsync(ct);
return;
}
else
{
databaseHistoryOfApproval.DeliveryDate = req.DeliveryDate;
databaseHistoryOfApproval.ExpirationDate = req.ExpirationDate;
}
await pyroFetesDbContext.SaveChangesAsync(ct);
GetHistoryOfApprovalDto dto = new()
{
Id = databaseHistoryOfApproval.Id,
DeliveryDate = req.DeliveryDate,
ExpirationDate = req.ExpirationDate
};
await Send.OkAsync(dto, ct);
}
}