diff --git a/PyroFetes/DTO/Quotation/Request/UpdateQuotationDto.cs b/PyroFetes/DTO/Quotation/Request/UpdateQuotationDto.cs new file mode 100644 index 00000000..dbc08985 --- /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 a21f60d4..e8287f16 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 00000000..d59df4d2 --- /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