Refactored Quotation

This commit is contained in:
Cristiano
2025-11-20 14:34:09 +01:00
parent f6383265ba
commit ee9b4675dd
5 changed files with 29 additions and 96 deletions

View File

@@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Quotation.Response;
using PyroFetes.DTO.QuotationProduct.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Quotations;
namespace PyroFetes.Endpoints.Quotations;
@@ -11,7 +13,9 @@ public class GetQuotationRequest
public int Id { get; set; }
}
public class GetQuotationEndpoint(PyroFetesDbContext database) : Endpoint<GetQuotationRequest, GetQuotationDto>
public class GetQuotationEndpoint(
QuotationsRepository quotationsRepository,
AutoMapper.IMapper mapper) : Endpoint<GetQuotationRequest, GetQuotationDto>
{
public override void Configure()
{
@@ -21,8 +25,7 @@ public class GetQuotationEndpoint(PyroFetesDbContext database) : Endpoint<GetQuo
public override async Task HandleAsync(GetQuotationRequest req, CancellationToken ct)
{
Quotation? quotation = await database.Quotations
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
if (quotation == null)
{
@@ -30,32 +33,6 @@ public class GetQuotationEndpoint(PyroFetesDbContext database) : Endpoint<GetQuo
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);
await Send.OkAsync(mapper.Map<GetQuotationDto>(quotation), ct);
}
}