Refactor all code
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.PurchaseOrder.Request;
|
||||
using PyroFetes.DTO.PurchaseOrder.Response;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.PurchaseOrders;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseOrders;
|
||||
|
||||
public class PatchPurchaseOrderPurchaseConditionsEndpoint(
|
||||
PurchaseOrdersRepository purchaseOrdersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchPurchaseOrderPurchaseConditionsDto, GetPurchaseOrderDto>
|
||||
public class PatchPurchaseOrderPurchaseConditionsEndpoint(PurchaseOrdersRepository purchaseOrdersRepository, AutoMapper.IMapper mapper)
|
||||
: Endpoint<PatchPurchaseOrderPurchaseConditionsDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
@@ -21,16 +18,16 @@ public class PatchPurchaseOrderPurchaseConditionsEndpoint(
|
||||
|
||||
public override async Task HandleAsync(PatchPurchaseOrderPurchaseConditionsDto req, CancellationToken ct)
|
||||
{
|
||||
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct);
|
||||
if (purchaseOrder == null)
|
||||
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.SingleOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct);
|
||||
if (purchaseOrder is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
purchaseOrder.PurchaseConditions = req.PurchaseConditions;
|
||||
await purchaseOrdersRepository.UpdateAsync(purchaseOrder, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetPurchaseOrderDto>(purchaseOrder), ct);
|
||||
mapper.Map(req, purchaseOrder);
|
||||
|
||||
await purchaseOrdersRepository.UpdateAsync(purchaseOrder, ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user