From 2fa74ccba8bbedc88cd76dee43779b08d27dd727 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Fri, 12 Dec 2025 21:18:13 +0100 Subject: [PATCH] added UpdateQuotationDto.cs --- .../Quotation/Request/UpdateQuotationDto.cs | 8 +++++ .../PatchQuotationConditionsSaleEndpoint.cs | 2 -- .../Quotations/UpdateQuotationEndpoint.cs | 36 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 PyroFetes/DTO/Quotation/Request/UpdateQuotationDto.cs create mode 100644 PyroFetes/Endpoints/Quotations/UpdateQuotationEndpoint.cs diff --git a/PyroFetes/DTO/Quotation/Request/UpdateQuotationDto.cs b/PyroFetes/DTO/Quotation/Request/UpdateQuotationDto.cs new file mode 100644 index 0000000..dbc0898 --- /dev/null +++ b/PyroFetes/DTO/Quotation/Request/UpdateQuotationDto.cs @@ -0,0 +1,8 @@ +namespace PyroFetes.DTO.Quotation.Request; + +public class UpdateQuotationDto +{ + public int Id { get; set; } + public string? Message { get; set; } + public string? ConditionsSale { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Quotations/PatchQuotationConditionsSaleEndpoint.cs b/PyroFetes/Endpoints/Quotations/PatchQuotationConditionsSaleEndpoint.cs index a21f60d..e8287f1 100644 --- a/PyroFetes/Endpoints/Quotations/PatchQuotationConditionsSaleEndpoint.cs +++ b/PyroFetes/Endpoints/Quotations/PatchQuotationConditionsSaleEndpoint.cs @@ -1,8 +1,6 @@ using FastEndpoints; -using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Quotation.Request; using PyroFetes.DTO.Quotation.Response; -using PyroFetes.DTO.QuotationProduct.Response; using PyroFetes.Models; using PyroFetes.Repositories; using PyroFetes.Specifications.Quotations; diff --git a/PyroFetes/Endpoints/Quotations/UpdateQuotationEndpoint.cs b/PyroFetes/Endpoints/Quotations/UpdateQuotationEndpoint.cs new file mode 100644 index 0000000..d59df4d --- /dev/null +++ b/PyroFetes/Endpoints/Quotations/UpdateQuotationEndpoint.cs @@ -0,0 +1,36 @@ +using FastEndpoints; +using PyroFetes.DTO.Quotation.Request; +using PyroFetes.DTO.Quotation.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Quotations; + +namespace PyroFetes.Endpoints.Quotations; + +public class UpdateQuotationEndpoint( + QuotationsRepository quotationsRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Put("/quotations/{@Id}", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(UpdateQuotationDto req, CancellationToken ct) + { + Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct); + + if (quotation == null) + { + await Send.NotFoundAsync(ct); + return; + } + + quotation.ConditionsSale = req.ConditionsSale; + quotation.Message = req.Message; + await quotationsRepository.UpdateAsync(quotation, ct); + + await Send.OkAsync(mapper.Map(quotation), ct); + } +} \ No newline at end of file