First Commit 09/10
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using FastEndpoints;
|
||||
using PyroFetes.DTO.Availability.Request;
|
||||
using PyroFetes.DTO.Availability.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Availability;
|
||||
|
||||
public class CreateAvailabilityEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateAvailabilityDto, GetAvailabilityDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/api/availabilities");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
|
||||
public override async Task HandleAsync(CreateAvailabilityDto req, CancellationToken ct)
|
||||
{
|
||||
Models.Availability availability = new()
|
||||
{
|
||||
AvailabilityDate = req.AvailabilityDate,
|
||||
DeliveryDate = req.DeliveryDate,
|
||||
ExpirationDate = req.ExpirationDate,
|
||||
RenewallDate = req.RenewalDate,
|
||||
};
|
||||
pyroFetesDbContext.Add(availability);
|
||||
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||
|
||||
GetAvailabilityDto response = new()
|
||||
{
|
||||
AvailabilityDate = availability.AvailabilityDate,
|
||||
DeliveryDate = availability.DeliveryDate,
|
||||
ExpirationDate = availability.ExpirationDate,
|
||||
RenewalDate = availability.RenewallDate
|
||||
};
|
||||
|
||||
await Send.OkAsync(response, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user