forked from sanchezvem/PyroFetes
Created all endpoints for Quotation and QuotationProduct
This commit is contained in:
59
PyroFetes/Endpoints/Quotation/GetQuotationEndpoint.cs
Normal file
59
PyroFetes/Endpoints/Quotation/GetQuotationEndpoint.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Quotation.Response;
|
||||
using PyroFetes.DTO.QuotationProduct.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Quotation;
|
||||
|
||||
public class GetQuotationRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetQuotationEndpoint(PyroFetesDbContext database) : Endpoint<GetQuotationRequest, GetQuotationDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/quotations/{@Id}", x => new {x.Id});
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetQuotationRequest req, CancellationToken ct)
|
||||
{
|
||||
var quotation = await database.Quotations
|
||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||
|
||||
if (quotation == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
GetQuotationDto responseDto = new()
|
||||
{
|
||||
Id = quotation.Id,
|
||||
Message = quotation.Message,
|
||||
ConditionsSale = quotation.ConditionsSale,
|
||||
GetQuotationProductDto = quotation.QuotationProducts
|
||||
.Select(qp => new GetQuotationProductDto
|
||||
{
|
||||
Quantity = qp.Quantity,
|
||||
QuotationId = quotation.Id,
|
||||
QuotationMessage = quotation.Message,
|
||||
QuotationConditionsSale = quotation.ConditionsSale,
|
||||
ProductId = qp.ProductId,
|
||||
ProductReferences = qp.Product.Reference,
|
||||
ProductName = qp.Product.Name,
|
||||
ProductDuration = qp.Product.Duration,
|
||||
ProductCaliber = qp.Product.Caliber,
|
||||
ProductApprovalNumber = qp.Product.ApprovalNumber,
|
||||
ProductWeight = qp.Product.Weight,
|
||||
ProductNec = qp.Product.Nec,
|
||||
ProductImage = qp.Product.Image,
|
||||
ProductLink = qp.Product.Link,
|
||||
ProductMinimalQuantity = qp.Product.MinimalQuantity,
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user