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:
masoodafar-web
2026-02-05 23:01:50 +03:30
parent b41342dcad
commit b2d676b555
96 changed files with 4822 additions and 589 deletions
@@ -13,17 +13,26 @@ using CMSMicroservice.Application.UserCQ.Commands.RefreshToken;
using CMSMicroservice.Application.UserCQ.Commands.CreateNewOtpToken;
using CMSMicroservice.Application.UserCQ.Commands.VerifyOtpToken;
using CMSMicroservice.Application.UserCQ.Commands.AcceptContract;
using CMSMicroservice.Application.UserCQ.Queries.GetCustomerProfile;
using CMSMicroservice.Application.UserCQ.Queries.GetCustomerReferrals;
using CMSMicroservice.Application.UserCQ.Queries.GetCustomerSettings;
using Google.Protobuf.WellKnownTypes;
using System.Collections.Generic;
using System.Linq;
using MediatR;
using Mapster;
using AppModels = CMSMicroservice.Application.Common.Models;
namespace CMSMicroservice.WebApi.Services;
public class UserService : UserContract.UserContractBase
{
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
private readonly ISender _sender;
public UserService(IDispatchRequestToCQRS dispatchRequestToCQRS)
public UserService(IDispatchRequestToCQRS dispatchRequestToCQRS, ISender sender)
{
_dispatchRequestToCQRS = dispatchRequestToCQRS;
_sender = sender;
}
public override async Task<CreateNewUserResponse> CreateNewUser(CreateNewUserRequest request, ServerCallContext context)
{
@@ -113,28 +122,32 @@ public class UserService : UserContract.UserContractBase
public override async Task<GetCustomerProfileResponse> GetCustomerProfile(GetCustomerProfileRequest request, ServerCallContext context)
{
// Mock implementation for Get Customer Profile
await Task.Delay(10);
var query = new GetCustomerProfileQuery { UserId = 0 };
var result = await _sender.Send(query, context.CancellationToken);
return new GetCustomerProfileResponse
{
Id = 123,
FirstName = "احمد",
LastName = "محمدی",
Mobile = "09123456789",
Email = "ahmad.mohammadi@example.com",
NationalCode = "1234567890",
AvatarPath = "/avatars/user_123.jpg",
ParentId = 100,
ReferralCode = "REF123456",
IsMobileVerified = true,
MobileVerifiedAt = Timestamp.FromDateTime(DateTime.SpecifyKind(new DateTime(2024, 1, 15), DateTimeKind.Utc)),
EmailNotifications = true,
SmsNotifications = true,
PushNotifications = false,
BirthDate = Timestamp.FromDateTime(DateTime.SpecifyKind(new DateTime(1990, 5, 20), DateTimeKind.Utc)),
FullName = "احمد محمدی",
ProfileCompletionPercentage = 85
Id = result.Id,
FirstName = result.FirstName,
LastName = result.LastName,
Mobile = result.Mobile,
Email = result.Email,
NationalCode = result.NationalCode,
AvatarPath = result.AvatarPath,
ParentId = result.ParentId,
ReferralCode = result.ReferralCode,
IsMobileVerified = result.IsMobileVerified,
MobileVerifiedAt = result.MobileVerifiedAt.HasValue
? Timestamp.FromDateTime(DateTime.SpecifyKind(result.MobileVerifiedAt.Value, DateTimeKind.Utc))
: null,
EmailNotifications = result.EmailNotifications,
SmsNotifications = result.SmsNotifications,
PushNotifications = result.PushNotifications,
BirthDate = result.BirthDate.HasValue
? Timestamp.FromDateTime(DateTime.SpecifyKind(result.BirthDate.Value, DateTimeKind.Utc))
: null,
FullName = result.FullName,
ProfileCompletionPercentage = result.ProfileCompletionPercentage
};
}
@@ -170,69 +183,52 @@ public class UserService : UserContract.UserContractBase
public override async Task<GetCustomerReferralsResponse> GetCustomerReferrals(GetCustomerReferralsRequest request, ServerCallContext context)
{
// Mock implementation for Get Customer Referrals
await Task.Delay(10);
var referrals = new List<CustomerReferralModel>
var query = new GetCustomerReferralsQuery
{
new CustomerReferralModel
{
Id = 1,
FirstName = "علی",
LastName = "احمدی",
Mobile = "09121234567",
JoinDate = Timestamp.FromDateTime(DateTime.SpecifyKind(new DateTime(2025, 12, 1), DateTimeKind.Utc)),
IsActive = true,
StatusMessage = "فعال",
Level = 1,
TotalCommission = 2500000
},
new CustomerReferralModel
{
Id = 2,
FirstName = "فاطمه",
LastName = "کریمی",
Mobile = "09122345678",
JoinDate = Timestamp.FromDateTime(DateTime.SpecifyKind(new DateTime(2025, 11, 15), DateTimeKind.Utc)),
IsActive = true,
StatusMessage = "فعال",
Level = 1,
TotalCommission = 1800000
},
new CustomerReferralModel
{
Id = 3,
FirstName = "محسن",
LastName = "رضایی",
Mobile = "09123456789",
JoinDate = Timestamp.FromDateTime(DateTime.SpecifyKind(new DateTime(2025, 10, 20), DateTimeKind.Utc)),
IsActive = false,
StatusMessage = "غیرفعال",
Level = 1,
TotalCommission = 950000
}
UserId = 0,
PaginationState = request.PaginationState?.Adapt<AppModels.PaginationState>(),
StatusFilter = request.StatusFilter
};
var result = await _sender.Send(query, context.CancellationToken);
return new GetCustomerReferralsResponse
var response = new GetCustomerReferralsResponse
{
MetaData = new MetaData
{
CurrentPage = 1,
TotalPage = 1,
PageSize = 10,
TotalCount = 3,
HasPrevious = false,
HasNext = false
CurrentPage = result.MetaData.CurrentPage,
TotalPage = result.MetaData.TotalPage,
PageSize = result.MetaData.PageSize,
TotalCount = result.MetaData.TotalCount,
HasPrevious = result.MetaData.HasPrevious,
HasNext = result.MetaData.HasNext
},
Referrals = { referrals },
Stats = new CustomerReferralStats
Stats = new CMSMicroservice.Protobuf.Protos.User.CustomerReferralStats
{
TotalReferrals = 3,
ActiveReferrals = 2,
TotalCommissionEarned = 5250000,
ThisMonthCommission = 850000
TotalReferrals = result.Stats.TotalReferrals,
ActiveReferrals = result.Stats.ActiveReferrals,
TotalCommissionEarned = result.Stats.TotalCommissionEarned,
ThisMonthCommission = result.Stats.ThisMonthCommission
}
};
foreach (var referral in result.Referrals)
{
response.Referrals.Add(new CMSMicroservice.Protobuf.Protos.User.CustomerReferralModel
{
Id = referral.Id,
FirstName = referral.FirstName,
LastName = referral.LastName,
Mobile = referral.Mobile,
JoinDate = Timestamp.FromDateTime(DateTime.SpecifyKind(referral.JoinDate, DateTimeKind.Utc)),
IsActive = referral.IsActive,
StatusMessage = referral.StatusMessage,
Level = referral.Level,
TotalCommission = referral.TotalCommission
});
}
return response;
}
public override async Task<UploadCustomerAvatarResponse> UploadCustomerAvatar(UploadCustomerAvatarRequest request, ServerCallContext context)
@@ -282,18 +278,18 @@ public class UserService : UserContract.UserContractBase
public override async Task<GetCustomerSettingsResponse> GetCustomerSettings(GetCustomerSettingsRequest request, ServerCallContext context)
{
// Mock implementation for Get Customer Settings
await Task.Delay(10);
var query = new GetCustomerSettingsQuery { UserId = 0 };
var result = await _sender.Send(query, context.CancellationToken);
return new GetCustomerSettingsResponse
{
EmailNotifications = true,
SmsNotifications = true,
PushNotifications = false,
MarketingNotifications = true,
PreferredLanguage = "fa-IR",
TimeZone = "Asia/Tehran",
TwoFactorAuthEnabled = false
EmailNotifications = result.EmailNotifications,
SmsNotifications = result.SmsNotifications,
PushNotifications = result.PushNotifications,
MarketingNotifications = result.MarketingNotifications,
PreferredLanguage = result.PreferredLanguage,
TimeZone = result.TimeZone,
TwoFactorAuthEnabled = result.TwoFactorAuthEnabled
};
}