Files
Projet4/PyroFetes/Endpoints/HistoryOfApproval/GetHistoryOfApprovalEndpoint.cs
2025-10-09 17:12:17 +02:00

35 lines
1.2 KiB
C#

using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.HistoryOfApproval.Request;
using PyroFetes.DTO.HistoryOfApproval.Response;
namespace PyroFetes.Endpoints.HistoryOfApproval;
public class GetHistoryOfApprovalEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetHistoryOfApprovalRequest, GetHistoryOfApprovalDto>
{
public override void Configure()
{
Get ("/api/HistoryOfApprovals/{@Id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(GetHistoryOfApprovalRequest 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;
}
GetHistoryOfApprovalDto dto = new()
{
Id = databaseHistoryOfApproval.Id,
DeliveryDate = databaseHistoryOfApproval.DeliveryDate,
ExpirationDate = databaseHistoryOfApproval.ExpirationDate
};
await Send.OkAsync(dto, ct);
}
}