36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using FastEndpoints;
|
|
using PyroFetes.DTO.HistoryOfApproval.Request;
|
|
using PyroFetes.DTO.HistoryOfApproval.Response;
|
|
|
|
namespace PyroFetes.Endpoints.HistoryOfApproval;
|
|
|
|
public class CreateHistoryOfApprovalEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateHistoryOfApprovalDto, GetHistoryOfApprovalDto>
|
|
{
|
|
public override void Configure()
|
|
{
|
|
Post("/api/HistoryOfApprovals");
|
|
AllowAnonymous();
|
|
}
|
|
|
|
|
|
public override async Task HandleAsync(CreateHistoryOfApprovalDto req, CancellationToken ct)
|
|
{
|
|
Models.HistoryOfApproval historyOfApproval = new()
|
|
{
|
|
DeliveryDate = req.DeliveryDate,
|
|
ExpirationDate = req.ExpirationDate
|
|
};
|
|
pyroFetesDbContext.Add(historyOfApproval);
|
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
|
|
|
GetHistoryOfApprovalDto response = new()
|
|
{
|
|
Id = historyOfApproval.Id,
|
|
DeliveryDate = historyOfApproval.DeliveryDate,
|
|
ExpirationDate = historyOfApproval.ExpirationDate
|
|
};
|
|
|
|
await Send.OkAsync(response, ct);
|
|
|
|
}
|
|
} |