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;
|
||||
}
|
||||
+3
@@ -4,4 +4,7 @@ public record GetOrderByIdQuery : IRequest<GetOrderByIdResponseDto>
|
||||
{
|
||||
/// <summary>شناسه سفارش</summary>
|
||||
public long OrderId { get; init; }
|
||||
|
||||
/// <summary>شناسه کاربر (برای بررسی مجوز)</summary>
|
||||
public long UserId { get; init; }
|
||||
}
|
||||
|
||||
+10
-41
@@ -1,4 +1,5 @@
|
||||
using CMSMicroservice.Protobuf.Protos.DiscountOrder;
|
||||
using BackOffice.BFF.DiscountOrder.Protobuf.Protos.DiscountOrder;
|
||||
using Mapster;
|
||||
|
||||
namespace BackOffice.BFF.Application.DiscountOrderCQ.Queries.GetOrderById;
|
||||
|
||||
@@ -13,46 +14,14 @@ public class GetOrderByIdQueryHandler : IRequestHandler<GetOrderByIdQuery, GetOr
|
||||
|
||||
public async Task<GetOrderByIdResponseDto> Handle(GetOrderByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = await _context.DiscountOrders.GetOrderByIdAsync(
|
||||
new GetOrderByIdRequest { OrderId = request.OrderId },
|
||||
cancellationToken: cancellationToken);
|
||||
|
||||
return new GetOrderByIdResponseDto
|
||||
{
|
||||
Id = response.Id,
|
||||
UserId = response.UserId,
|
||||
TrackingCode = response.TrackingCode,
|
||||
Status = response.Status,
|
||||
StatusTitle = response.StatusTitle,
|
||||
TotalPrice = response.TotalPrice,
|
||||
DiscountBalanceUsed = response.DiscountBalanceUsed,
|
||||
GatewayPayment = response.GatewayPayment,
|
||||
FinalPrice = response.FinalPrice,
|
||||
PaymentTransactionCode = response.PaymentTransactionCode,
|
||||
AdminNote = response.AdminNote,
|
||||
CreatedAt = response.CreatedAt.ToDateTime(),
|
||||
PaidAt = response.HasPaidAt ? response.PaidAt.ToDateTime() : null,
|
||||
ShippingAddress = new AddressInfoDto
|
||||
{
|
||||
Id = response.ShippingAddress.Id,
|
||||
RecipientName = response.ShippingAddress.RecipientName,
|
||||
RecipientPhone = response.ShippingAddress.RecipientPhone,
|
||||
Province = response.ShippingAddress.Province,
|
||||
City = response.ShippingAddress.City,
|
||||
PostalCode = response.ShippingAddress.PostalCode,
|
||||
FullAddress = response.ShippingAddress.FullAddress
|
||||
},
|
||||
Items = response.Items.Select(item => new OrderItemDto
|
||||
{
|
||||
Id = item.Id,
|
||||
ProductId = item.ProductId,
|
||||
ProductTitle = item.ProductTitle,
|
||||
UnitPrice = item.UnitPrice,
|
||||
DiscountPercent = item.DiscountPercent,
|
||||
Quantity = item.Quantity,
|
||||
TotalPrice = item.TotalPrice,
|
||||
DiscountedPrice = item.DiscountedPrice
|
||||
}).ToList()
|
||||
var grpcRequest = new GetOrderByIdRequest
|
||||
{
|
||||
OrderId = request.OrderId,
|
||||
UserId = request.UserId
|
||||
};
|
||||
|
||||
var response = await _context.DiscountOrders.GetOrderByIdAsync(grpcRequest, cancellationToken: cancellationToken);
|
||||
|
||||
return TypeAdapter.Adapt(response, response.GetType(), typeof(GetOrderByIdResponseDto)) as GetOrderByIdResponseDto;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-27
@@ -1,6 +1,5 @@
|
||||
using BackOffice.BFF.Application.Common.Models;
|
||||
using CMSMicroservice.Protobuf.Protos.DiscountOrder;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using BackOffice.BFF.DiscountOrder.Protobuf.Protos.DiscountOrder;
|
||||
using Mapster;
|
||||
|
||||
namespace BackOffice.BFF.Application.DiscountOrderCQ.Queries.GetUserOrders;
|
||||
|
||||
@@ -23,32 +22,10 @@ public class GetUserOrdersQueryHandler : IRequestHandler<GetUserOrdersQuery, Get
|
||||
};
|
||||
|
||||
if (request.Status.HasValue)
|
||||
grpcRequest.Status = new Int32Value { Value = request.Status.Value };
|
||||
grpcRequest.DeliveryStatus = request.Status.Value;
|
||||
|
||||
var response = await _context.DiscountOrders.GetUserOrdersAsync(grpcRequest, cancellationToken: cancellationToken);
|
||||
|
||||
return new GetUserOrdersResponseDto
|
||||
{
|
||||
MetaData = new MetaData
|
||||
{
|
||||
CurrentPage = response.MetaData.CurrentPage,
|
||||
TotalPage = response.MetaData.TotalPages,
|
||||
PageSize = response.MetaData.PageSize,
|
||||
TotalCount = response.MetaData.TotalCount,
|
||||
HasPrevious = response.MetaData.HasPrevious,
|
||||
HasNext = response.MetaData.HasNext
|
||||
},
|
||||
Orders = response.Orders.Select(order => new UserOrderDto
|
||||
{
|
||||
Id = order.Id,
|
||||
TrackingCode = order.TrackingCode,
|
||||
Status = order.Status,
|
||||
StatusTitle = order.StatusTitle,
|
||||
TotalPrice = order.TotalPrice,
|
||||
FinalPrice = order.FinalPrice,
|
||||
ItemCount = order.ItemCount,
|
||||
CreatedAt = order.CreatedAt.ToDateTime()
|
||||
}).ToList()
|
||||
};
|
||||
return TypeAdapter.Adapt(response, response.GetType(), typeof(GetUserOrdersResponseDto)) as GetUserOrdersResponseDto;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user