feat: Implement customer profile and referral queries
- Add GetCustomerProfileResponseDto for retrieving customer profile information. - Create GetCustomerReferralsQuery and GetCustomerReferralsQueryHandler to fetch customer referrals with pagination and filtering options. - Introduce GetCustomerReferralsResponseDto to structure the response for customer referrals. - Implement GetCustomerSettingsQuery and GetCustomerSettingsQueryHandler to retrieve user settings. - Add GetCustomerOrder and GetCustomerOrderQueryHandler for fetching specific customer orders. - Create GetCustomerOrderHistoryQuery and GetCustomerOrderHistoryQueryHandler to retrieve order history with filtering options. - Implement GetCustomerOrdersQuery and GetCustomerOrdersQueryHandler for fetching multiple customer orders with filters. - Add GetCustomerWalletChangeLogQuery and GetCustomerWalletChangeLogQueryHandler for retrieving wallet change logs. - Implement GetCustomerWithdrawalSettingsQuery and GetCustomerWithdrawalSettingsQueryHandler for fetching withdrawal settings. - Create GetCustomerWithdrawalsQuery and GetCustomerWithdrawalsQueryHandler to retrieve customer withdrawal requests.
This commit is contained in:
@@ -1,13 +1,25 @@
|
||||
using CMSMicroservice.Protobuf.Protos.UserOrder;
|
||||
using CMSMicroservice.Application.UserOrderCQ.Queries.GetCustomerOrders;
|
||||
using CMSMicroservice.Application.UserOrderCQ.Queries.GetCustomerOrder;
|
||||
using CMSMicroservice.Application.UserOrderCQ.Queries.GetCustomerOrderHistory;
|
||||
using AppModels = CMSMicroservice.Application.Common.Models;
|
||||
using Grpc.Core;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using System.Collections.Generic;
|
||||
using CMSMicroservice.Protobuf.Protos;
|
||||
using MediatR;
|
||||
using Mapster;
|
||||
|
||||
namespace CMSMicroservice.WebApi.Services;
|
||||
|
||||
public class UserOrderService : UserOrderContract.UserOrderContractBase
|
||||
{
|
||||
private readonly ISender _sender;
|
||||
|
||||
public UserOrderService(ISender sender)
|
||||
{
|
||||
_sender = sender;
|
||||
}
|
||||
public override async Task<CreateNewUserOrderResponse> CreateNewUserOrder(CreateNewUserOrderRequest request, ServerCallContext context)
|
||||
{
|
||||
throw new RpcException(new Status(StatusCode.Unimplemented, "Method not implemented yet"));
|
||||
@@ -79,22 +91,135 @@ public class UserOrderService : UserOrderContract.UserOrderContractBase
|
||||
|
||||
public override async Task<GetAllUserOrderByFilterResponse> GetCustomerOrders(GetAllUserOrderByFilterRequest request, ServerCallContext context)
|
||||
{
|
||||
// For now, return empty response - will be implemented properly later
|
||||
return new GetAllUserOrderByFilterResponse();
|
||||
var query = new GetCustomerOrdersQuery
|
||||
{
|
||||
UserId = request.Filter?.UserId ?? 0,
|
||||
PaginationState = request.PaginationState?.Adapt<AppModels.PaginationState>(),
|
||||
PaymentStatusFilter = request.Filter?.PaymentStatus != null
|
||||
? (int?)request.Filter.PaymentStatus
|
||||
: null,
|
||||
DeliveryStatusFilter = request.Filter?.DeliveryStatus != null
|
||||
? (int?)request.Filter.DeliveryStatus
|
||||
: null,
|
||||
FromDate = request.Filter?.PaymentDate?.ToDateTime(),
|
||||
ToDate = null
|
||||
};
|
||||
|
||||
var result = await _sender.Send(query, context.CancellationToken);
|
||||
|
||||
var response = new GetAllUserOrderByFilterResponse
|
||||
{
|
||||
MetaData = result.MetaData.Adapt<MetaData>()
|
||||
};
|
||||
|
||||
foreach (var model in result.Models)
|
||||
{
|
||||
var orderModel = new GetAllUserOrderByFilterResponseModel
|
||||
{
|
||||
Id = model.Id,
|
||||
Amount = model.Amount,
|
||||
PackageId = model.PackageId ?? 0,
|
||||
TransactionId = model.TransactionId,
|
||||
UserId = model.UserId,
|
||||
UserAddressId = model.UserAddressId,
|
||||
UserAddressText = model.UserAddressText,
|
||||
TrackingCode = model.TrackingCode,
|
||||
DeliveryDescription = model.DeliveryDescription,
|
||||
UserFullName = model.UserFullName,
|
||||
UserNationalCode = model.UserNationalCode,
|
||||
VatAmount = model.VatAmount,
|
||||
VatPercentage = model.VatPercentage
|
||||
};
|
||||
|
||||
orderModel.PaymentStatus = (PaymentStatus)model.PaymentStatus;
|
||||
if (model.PaymentDate.HasValue)
|
||||
orderModel.PaymentDate = Timestamp.FromDateTime(DateTime.SpecifyKind(model.PaymentDate.Value, DateTimeKind.Utc));
|
||||
|
||||
if (model.PaymentMethod.HasValue)
|
||||
orderModel.PaymentMethod = (PaymentMethod)model.PaymentMethod.Value;
|
||||
|
||||
orderModel.DeliveryStatus = (DeliveryStatus)model.DeliveryStatus;
|
||||
|
||||
foreach (var fd in model.FactorDetails)
|
||||
{
|
||||
orderModel.FactorDetails.Add(new GetAllUserOrderByFilterResponseModelFactorDetail
|
||||
{
|
||||
ProductId = fd.ProductId,
|
||||
ProductTitle = fd.ProductTitle,
|
||||
ProductThumbnailPath = fd.ProductThumbnailPath,
|
||||
UnitPrice = fd.UnitPrice,
|
||||
Count = fd.Count,
|
||||
UnitDiscountPrice = fd.UnitDiscountPrice
|
||||
});
|
||||
}
|
||||
|
||||
response.Models.Add(orderModel);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public override async Task<GetUserOrderResponse> GetCustomerOrder(GetUserOrderRequest request, ServerCallContext context)
|
||||
{
|
||||
// Mock Customer order details with correct property names
|
||||
return new GetUserOrderResponse
|
||||
var query = new GetCustomerOrderQuery
|
||||
{
|
||||
Id = request.Id,
|
||||
Amount = 250000,
|
||||
PackageId = 1,
|
||||
UserId = 1,
|
||||
PaymentStatus = PaymentStatus.Success,
|
||||
PaymentDate = Timestamp.FromDateTime(DateTime.UtcNow.AddDays(-2))
|
||||
OrderId = request.Id,
|
||||
UserId = 0 // از JWT دریافت میشود
|
||||
};
|
||||
|
||||
var result = await _sender.Send(query, context.CancellationToken);
|
||||
|
||||
var response = new GetUserOrderResponse
|
||||
{
|
||||
Id = result.Id,
|
||||
Amount = result.Amount,
|
||||
PackageId = result.PackageId ?? 0,
|
||||
TransactionId = result.TransactionId,
|
||||
UserId = result.UserId,
|
||||
UserAddressId = result.UserAddressId,
|
||||
UserAddressText = result.UserAddressText,
|
||||
TrackingCode = result.TrackingCode,
|
||||
DeliveryDescription = result.DeliveryDescription,
|
||||
UserFullName = result.UserFullName,
|
||||
UserNationalCode = result.UserNationalCode
|
||||
};
|
||||
|
||||
// VAT Info
|
||||
if (result.VatAmount > 0)
|
||||
{
|
||||
response.VatInfo = new OrderVATInfo
|
||||
{
|
||||
VatRate = result.VatPercentage / 100,
|
||||
BaseAmount = result.Amount - result.VatAmount,
|
||||
VatAmount = result.VatAmount,
|
||||
TotalAmount = result.Amount,
|
||||
IsPaid = result.PaymentStatus == Domain.Enums.PaymentStatus.Success
|
||||
};
|
||||
}
|
||||
|
||||
response.PaymentStatus = (PaymentStatus)result.PaymentStatus;
|
||||
if (result.PaymentDate.HasValue)
|
||||
response.PaymentDate = Timestamp.FromDateTime(DateTime.SpecifyKind(result.PaymentDate.Value, DateTimeKind.Utc));
|
||||
|
||||
if (result.PaymentMethod.HasValue)
|
||||
response.PaymentMethod = (PaymentMethod)result.PaymentMethod.Value;
|
||||
|
||||
response.DeliveryStatus = (DeliveryStatus)result.DeliveryStatus;
|
||||
|
||||
foreach (var fd in result.FactorDetails)
|
||||
{
|
||||
response.FactorDetails.Add(new GetUserOrderResponseFactorDetail
|
||||
{
|
||||
ProductId = fd.ProductId,
|
||||
ProductTitle = fd.ProductTitle,
|
||||
ProductThumbnailPath = fd.ProductThumbnailPath,
|
||||
UnitPrice = fd.UnitPrice,
|
||||
Count = fd.Count,
|
||||
UnitDiscountPrice = fd.UnitDiscountPrice
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
// ============= Customer-specific Method Implementations =============
|
||||
@@ -113,54 +238,46 @@ public class UserOrderService : UserOrderContract.UserOrderContractBase
|
||||
|
||||
public override async Task<GetCustomerOrderHistoryResponse> GetCustomerOrderHistory(GetCustomerOrderHistoryRequest request, ServerCallContext context)
|
||||
{
|
||||
// Mock Customer order history with realistic Persian data
|
||||
var orders = new List<CustomerOrderModel>
|
||||
var query = new GetCustomerOrderHistoryQuery
|
||||
{
|
||||
new CustomerOrderModel
|
||||
{
|
||||
Id = 1,
|
||||
Amount = 250000,
|
||||
PackageId = 1,
|
||||
PackageName = "پکیج اسپشیال",
|
||||
Status = OrderStatusEnum.OrderStatusDelivered,
|
||||
StatusMessage = "تحویل داده شد",
|
||||
OrderDate = Timestamp.FromDateTime(DateTime.UtcNow.AddDays(-10)),
|
||||
DeliveryDate = Timestamp.FromDateTime(DateTime.UtcNow.AddDays(-3)),
|
||||
TrackingCode = "TRK001",
|
||||
ItemsCount = 5,
|
||||
CanCancel = false,
|
||||
CanReorder = true
|
||||
},
|
||||
new CustomerOrderModel
|
||||
{
|
||||
Id = 2,
|
||||
Amount = 150000,
|
||||
PackageId = 2,
|
||||
PackageName = "پکیج عادی",
|
||||
Status = OrderStatusEnum.OrderStatusShipped,
|
||||
StatusMessage = "ارسال شده",
|
||||
OrderDate = Timestamp.FromDateTime(DateTime.UtcNow.AddDays(-3)),
|
||||
DeliveryDate = Timestamp.FromDateTime(DateTime.UtcNow.AddDays(2)),
|
||||
TrackingCode = "TRK002",
|
||||
ItemsCount = 3,
|
||||
CanCancel = true,
|
||||
CanReorder = true
|
||||
}
|
||||
UserId = request.UserId,
|
||||
PaginationState = request.PaginationState?.Adapt<AppModels.PaginationState>(),
|
||||
StatusFilter = request.StatusFilter != OrderStatusEnum.OrderStatusPending
|
||||
? (int?)request.StatusFilter
|
||||
: null,
|
||||
FromDate = request.FromDate?.ToDateTime(),
|
||||
ToDate = request.ToDate?.ToDateTime()
|
||||
};
|
||||
|
||||
return new GetCustomerOrderHistoryResponse
|
||||
|
||||
var result = await _sender.Send(query, context.CancellationToken);
|
||||
|
||||
var response = new GetCustomerOrderHistoryResponse
|
||||
{
|
||||
MetaData = new MetaData
|
||||
{
|
||||
CurrentPage = request.PaginationState?.PageNumber ?? 1,
|
||||
TotalPage = 1,
|
||||
PageSize = request.PaginationState?.PageSize ?? 10,
|
||||
TotalCount = orders.Count,
|
||||
HasPrevious = false,
|
||||
HasNext = false
|
||||
},
|
||||
Orders = { orders }
|
||||
MetaData = result.MetaData.Adapt<MetaData>()
|
||||
};
|
||||
|
||||
foreach (var order in result.Orders)
|
||||
{
|
||||
response.Orders.Add(new Protobuf.Protos.UserOrder.CustomerOrderModel
|
||||
{
|
||||
Id = order.Id,
|
||||
Amount = order.Amount,
|
||||
PackageId = order.PackageId ?? 0,
|
||||
PackageName = order.PackageName,
|
||||
Status = (OrderStatusEnum)order.Status,
|
||||
StatusMessage = order.StatusMessage,
|
||||
OrderDate = Timestamp.FromDateTime(DateTime.SpecifyKind(order.OrderDate, DateTimeKind.Utc)),
|
||||
DeliveryDate = order.DeliveryDate.HasValue
|
||||
? Timestamp.FromDateTime(DateTime.SpecifyKind(order.DeliveryDate.Value, DateTimeKind.Utc))
|
||||
: null,
|
||||
TrackingCode = order.TrackingCode,
|
||||
ItemsCount = order.ItemsCount,
|
||||
CanCancel = order.CanCancel,
|
||||
CanReorder = order.CanReorder
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public override async Task<CustomerTrackOrderResponse> CustomerTrackOrder(CustomerTrackOrderRequest request, ServerCallContext context)
|
||||
@@ -225,7 +342,7 @@ public class UserOrderService : UserOrderContract.UserOrderContractBase
|
||||
|
||||
return new CustomerTrackOrderResponse
|
||||
{
|
||||
Order = new CustomerOrderModel
|
||||
Order = new Protobuf.Protos.UserOrder.CustomerOrderModel
|
||||
{
|
||||
Id = request.OrderId,
|
||||
Amount = 180000,
|
||||
|
||||
Reference in New Issue
Block a user