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:
+4
-4
@@ -1,13 +1,13 @@
|
||||
namespace BackOffice.BFF.Application.DiscountOrderCQ.Commands.CompleteOrderPayment;
|
||||
|
||||
public record CompleteOrderPaymentCommand : IRequest
|
||||
public record CompleteOrderPaymentCommand : IRequest<CompleteOrderPaymentResponseDto>
|
||||
{
|
||||
/// <summary>شناسه سفارش</summary>
|
||||
public long OrderId { get; init; }
|
||||
|
||||
/// <summary>کد تراکنش پرداخت</summary>
|
||||
public string PaymentTransactionCode { get; init; }
|
||||
public string? PaymentTransactionCode { get; init; }
|
||||
|
||||
/// <summary>مبلغ پرداخت شده</summary>
|
||||
public long PaidAmount { get; init; }
|
||||
/// <summary>وضعیت موفقیت پرداخت</summary>
|
||||
public bool PaymentSuccess { get; init; }
|
||||
}
|
||||
|
||||
+9
-13
@@ -1,8 +1,9 @@
|
||||
using CMSMicroservice.Protobuf.Protos.DiscountOrder;
|
||||
using BackOffice.BFF.DiscountOrder.Protobuf.Protos.DiscountOrder;
|
||||
using Mapster;
|
||||
|
||||
namespace BackOffice.BFF.Application.DiscountOrderCQ.Commands.CompleteOrderPayment;
|
||||
|
||||
public class CompleteOrderPaymentCommandHandler : IRequestHandler<CompleteOrderPaymentCommand>
|
||||
public class CompleteOrderPaymentCommandHandler : IRequestHandler<CompleteOrderPaymentCommand, CompleteOrderPaymentResponseDto>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
@@ -11,17 +12,12 @@ public class CompleteOrderPaymentCommandHandler : IRequestHandler<CompleteOrderP
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(CompleteOrderPaymentCommand request, CancellationToken cancellationToken)
|
||||
public async Task<CompleteOrderPaymentResponseDto> Handle(CompleteOrderPaymentCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
await _context.DiscountOrders.CompleteOrderPaymentAsync(
|
||||
new CompleteOrderPaymentRequest
|
||||
{
|
||||
OrderId = request.OrderId,
|
||||
PaymentTransactionCode = request.PaymentTransactionCode,
|
||||
PaidAmount = request.PaidAmount
|
||||
},
|
||||
cancellationToken: cancellationToken);
|
||||
|
||||
return Unit.Value;
|
||||
var grpcRequest = TypeAdapter.Adapt(request, request.GetType(), typeof(CompleteOrderPaymentRequest)) as CompleteOrderPaymentRequest;
|
||||
|
||||
var response = await _context.DiscountOrders.CompleteOrderPaymentAsync(grpcRequest, cancellationToken: cancellationToken);
|
||||
|
||||
return TypeAdapter.Adapt(response, response.GetType(), typeof(CompleteOrderPaymentResponseDto)) as CompleteOrderPaymentResponseDto;
|
||||
}
|
||||
}
|
||||
|
||||
-3
@@ -9,8 +9,5 @@ public class CompleteOrderPaymentCommandValidator : AbstractValidator<CompleteOr
|
||||
|
||||
RuleFor(x => x.PaymentTransactionCode)
|
||||
.NotEmpty().WithMessage("کد تراکنش پرداخت الزامی است");
|
||||
|
||||
RuleFor(x => x.PaidAmount)
|
||||
.GreaterThan(0).WithMessage("مبلغ پرداخت شده باید بیشتر از صفر باشد");
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
namespace BackOffice.BFF.Application.DiscountOrderCQ.Commands.CompleteOrderPayment;
|
||||
|
||||
public class CompleteOrderPaymentResponseDto
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string Message { get; set; } = string.Empty;
|
||||
}
|
||||
+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("مجموع مبالغ پرداخت باید بیشتر از صفر باشد");
|
||||
}
|
||||
}
|
||||
|
||||
+6
-3
@@ -1,13 +1,16 @@
|
||||
namespace BackOffice.BFF.Application.DiscountOrderCQ.Commands.UpdateOrderStatus;
|
||||
|
||||
public record UpdateOrderStatusCommand : IRequest
|
||||
public record UpdateOrderStatusCommand : IRequest<UpdateOrderStatusResponseDto>
|
||||
{
|
||||
/// <summary>شناسه سفارش</summary>
|
||||
public long OrderId { get; init; }
|
||||
|
||||
/// <summary>وضعیت جدید</summary>
|
||||
/// <summary>وضعیت جدید (DeliveryStatus enum)</summary>
|
||||
public int NewStatus { get; init; }
|
||||
|
||||
/// <summary>کد رهگیری (اختیاری)</summary>
|
||||
public string? TrackingCode { get; init; }
|
||||
|
||||
/// <summary>یادداشت مدیر (اختیاری)</summary>
|
||||
public string AdminNote { get; init; }
|
||||
public string? AdminNote { get; init; }
|
||||
}
|
||||
|
||||
+9
-13
@@ -1,8 +1,9 @@
|
||||
using CMSMicroservice.Protobuf.Protos.DiscountOrder;
|
||||
using BackOffice.BFF.DiscountOrder.Protobuf.Protos.DiscountOrder;
|
||||
using Mapster;
|
||||
|
||||
namespace BackOffice.BFF.Application.DiscountOrderCQ.Commands.UpdateOrderStatus;
|
||||
|
||||
public class UpdateOrderStatusCommandHandler : IRequestHandler<UpdateOrderStatusCommand>
|
||||
public class UpdateOrderStatusCommandHandler : IRequestHandler<UpdateOrderStatusCommand, UpdateOrderStatusResponseDto>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
@@ -11,17 +12,12 @@ public class UpdateOrderStatusCommandHandler : IRequestHandler<UpdateOrderStatus
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(UpdateOrderStatusCommand request, CancellationToken cancellationToken)
|
||||
public async Task<UpdateOrderStatusResponseDto> Handle(UpdateOrderStatusCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
await _context.DiscountOrders.UpdateOrderStatusAsync(
|
||||
new UpdateOrderStatusRequest
|
||||
{
|
||||
OrderId = request.OrderId,
|
||||
NewStatus = request.NewStatus,
|
||||
AdminNote = request.AdminNote ?? string.Empty
|
||||
},
|
||||
cancellationToken: cancellationToken);
|
||||
|
||||
return Unit.Value;
|
||||
var grpcRequest = TypeAdapter.Adapt(request, request.GetType(), typeof(UpdateOrderStatusRequest)) as UpdateOrderStatusRequest;
|
||||
|
||||
var response = await _context.DiscountOrders.UpdateOrderStatusAsync(grpcRequest, cancellationToken: cancellationToken);
|
||||
|
||||
return TypeAdapter.Adapt(response, response.GetType(), typeof(UpdateOrderStatusResponseDto)) as UpdateOrderStatusResponseDto;
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
namespace BackOffice.BFF.Application.DiscountOrderCQ.Commands.UpdateOrderStatus;
|
||||
|
||||
public class UpdateOrderStatusResponseDto
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public string Message { get; set; } = string.Empty;
|
||||
}
|
||||
Reference in New Issue
Block a user