feat: add Mapster profiles and enable DiscountOrder handlers
Build and Deploy / build (push) Successful in 2m14s
Build and Deploy / build (push) Successful in 2m14s
This commit is contained in:
+2
-2
@@ -11,6 +11,6 @@ public record PlaceOrderCommand : IRequest<PlaceOrderResponseDto>
|
||||
/// <summary>مبلغ پرداخت از موجودی تخفیف</summary>
|
||||
public long DiscountBalanceAmount { get; init; }
|
||||
|
||||
/// <summary>مبلغ پرداخت از درگاه</summary>
|
||||
public long GatewayAmount { get; init; }
|
||||
/// <summary>یادداشت سفارش (اختیاری)</summary>
|
||||
public string? Notes { get; init; }
|
||||
}
|
||||
|
||||
+6
-17
@@ -1,4 +1,5 @@
|
||||
using CMSMicroservice.Protobuf.Protos.DiscountOrder;
|
||||
using BackOffice.BFF.DiscountOrder.Protobuf.Protos.DiscountOrder;
|
||||
using Mapster;
|
||||
|
||||
namespace BackOffice.BFF.Application.DiscountOrderCQ.Commands.PlaceOrder;
|
||||
|
||||
@@ -13,22 +14,10 @@ public class PlaceOrderCommandHandler : IRequestHandler<PlaceOrderCommand, Place
|
||||
|
||||
public async Task<PlaceOrderResponseDto> Handle(PlaceOrderCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = await _context.DiscountOrders.PlaceOrderAsync(
|
||||
new PlaceOrderRequest
|
||||
{
|
||||
UserId = request.UserId,
|
||||
AddressId = request.AddressId,
|
||||
DiscountBalanceAmount = request.DiscountBalanceAmount,
|
||||
GatewayAmount = request.GatewayAmount
|
||||
},
|
||||
cancellationToken: cancellationToken);
|
||||
var grpcRequest = TypeAdapter.Adapt(request, request.GetType(), typeof(PlaceOrderRequest)) as PlaceOrderRequest;
|
||||
|
||||
return new PlaceOrderResponseDto
|
||||
{
|
||||
OrderId = response.OrderId,
|
||||
TrackingCode = response.TrackingCode,
|
||||
RequiresGatewayPayment = response.RequiresGatewayPayment,
|
||||
GatewayPayableAmount = response.GatewayPayableAmount
|
||||
};
|
||||
var response = await _context.DiscountOrders.PlaceOrderAsync(grpcRequest, cancellationToken: cancellationToken);
|
||||
|
||||
return TypeAdapter.Adapt(response, response.GetType(), typeof(PlaceOrderResponseDto)) as PlaceOrderResponseDto;
|
||||
}
|
||||
}
|
||||
|
||||
-7
@@ -12,12 +12,5 @@ public class PlaceOrderCommandValidator : AbstractValidator<PlaceOrderCommand>
|
||||
|
||||
RuleFor(x => x.DiscountBalanceAmount)
|
||||
.GreaterThanOrEqualTo(0).WithMessage("مبلغ موجودی تخفیف نمیتواند منفی باشد");
|
||||
|
||||
RuleFor(x => x.GatewayAmount)
|
||||
.GreaterThanOrEqualTo(0).WithMessage("مبلغ درگاه نمیتواند منفی باشد");
|
||||
|
||||
RuleFor(x => x)
|
||||
.Must(x => x.DiscountBalanceAmount + x.GatewayAmount > 0)
|
||||
.WithMessage("مجموع مبالغ پرداخت باید بیشتر از صفر باشد");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user