First Commit 09/10
# Conflicts: # PyroFetes/PyroFetes.csproj
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.HistoryOfApproval.Request;
|
||||
using PyroFetes.DTO.HistoryOfApproval.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.HistoryOfApproval;
|
||||
|
||||
public class DeleteHistoryOfApprovalEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint <GetHistoryOfApprovalRequest, GetHistoryOfApprovalDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete ("/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;
|
||||
}
|
||||
pyroFetesDbContext.HistoryOfApprovals.Remove(databaseHistoryOfApproval);
|
||||
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.HistoryOfApproval.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.HistoryOfApproval;
|
||||
|
||||
public class GetAllHistoryOfApprovalEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<GetHistoryOfApprovalDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get ("/api/HistoryOfApprovals");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
List<GetHistoryOfApprovalDto> historyOfApprovals= await pyroFetesDbContext.HistoryOfApprovals.Select(x => new GetHistoryOfApprovalDto()
|
||||
{
|
||||
Id = x.Id,
|
||||
DeliveryDate = x.DeliveryDate,
|
||||
ExpirationDate = x.ExpirationDate,
|
||||
}).ToListAsync(ct);
|
||||
|
||||
await Send.OkAsync(historyOfApprovals, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user