added UpdateQuotationDto.cs
This commit is contained in:
8
PyroFetes/DTO/Quotation/Request/UpdateQuotationDto.cs
Normal file
8
PyroFetes/DTO/Quotation/Request/UpdateQuotationDto.cs
Normal file
@@ -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; }
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
36
PyroFetes/Endpoints/Quotations/UpdateQuotationEndpoint.cs
Normal file
36
PyroFetes/Endpoints/Quotations/UpdateQuotationEndpoint.cs
Normal file
@@ -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<UpdateQuotationDto, GetQuotationDto>
|
||||
{
|
||||
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<GetQuotationDto>(quotation), ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user