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:
@@ -10,18 +10,27 @@ using CMSMicroservice.Application.PackageCQ.Commands.VerifyBasePackagePayment;
|
||||
using CMSMicroservice.Application.PackageCQ.Queries.GetPackage;
|
||||
using CMSMicroservice.Application.PackageCQ.Queries.GetAllPackageByFilter;
|
||||
using CMSMicroservice.Application.PackageCQ.Queries.GetUserPackageStatus;
|
||||
using CMSMicroservice.Application.PackageCQ.Queries.GetCustomerPackages;
|
||||
using CMSMicroservice.Application.PackageCQ.Queries.GetCustomerPackageDetails;
|
||||
using CMSMicroservice.Application.PackageCQ.Queries.GetCustomerPurchaseHistory;
|
||||
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 PackageService : PackageContract.PackageContractBase
|
||||
{
|
||||
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
|
||||
private readonly ISender _sender;
|
||||
|
||||
public PackageService(IDispatchRequestToCQRS dispatchRequestToCQRS)
|
||||
public PackageService(IDispatchRequestToCQRS dispatchRequestToCQRS, ISender sender)
|
||||
{
|
||||
_dispatchRequestToCQRS = dispatchRequestToCQRS;
|
||||
_sender = sender;
|
||||
}
|
||||
public override async Task<CreateNewPackageResponse> CreateNewPackage(CreateNewPackageRequest request, ServerCallContext context)
|
||||
{
|
||||
@@ -74,108 +83,61 @@ public class PackageService : PackageContract.PackageContractBase
|
||||
|
||||
public override async Task<GetCustomerPackagesResponse> GetCustomerPackages(GetCustomerPackagesRequest request, ServerCallContext context)
|
||||
{
|
||||
// Mock Customer packages with realistic Persian data
|
||||
var packages = new List<CustomerPackageModel>
|
||||
var query = new GetCustomerPackagesQuery
|
||||
{
|
||||
new CustomerPackageModel
|
||||
{
|
||||
Id = 1,
|
||||
Name = "پکیج طلایی",
|
||||
Title = "پکیج طلایی", // Populate alias field
|
||||
Description = "پکیج کامل با امکانات ویژه برای کاربران فعال",
|
||||
Price = 5600000,
|
||||
Currency = "IRR",
|
||||
PackageType = PackageTypeEnum.PackageTypeGolden,
|
||||
IsAvailable = true,
|
||||
ImageUrl = "/images/packages/golden.jpg",
|
||||
ImagePath = "/images/packages/golden.jpg", // Populate alias field
|
||||
ValidityDays = 365,
|
||||
IsPopular = true,
|
||||
ShortDescription = "بهترین انتخاب برای درآمد بیشتر"
|
||||
},
|
||||
new CustomerPackageModel
|
||||
{
|
||||
Id = 2,
|
||||
Name = "پکیج پریمیوم",
|
||||
Title = "پکیج پریمیوم", // Populate alias field
|
||||
Description = "پکیج پیشرفته با امکانات حرفهای",
|
||||
Price = 3200000,
|
||||
Currency = "IRR",
|
||||
PackageType = PackageTypeEnum.PackageTypePremium,
|
||||
IsAvailable = true,
|
||||
ImageUrl = "/images/packages/premium.jpg",
|
||||
ImagePath = "/images/packages/premium.jpg", // Populate alias field
|
||||
ValidityDays = 180,
|
||||
IsPopular = false,
|
||||
ShortDescription = "برای کسب و کارهای متوسط"
|
||||
},
|
||||
new CustomerPackageModel
|
||||
{
|
||||
Id = 3,
|
||||
Name = "پکیج ابتدایی",
|
||||
Title = "پکیج ابتدایی", // Populate alias field
|
||||
Description = "پکیج مقدماتی برای شروع کار",
|
||||
Price = 1500000,
|
||||
Currency = "IRR",
|
||||
PackageType = PackageTypeEnum.PackageTypeBasic,
|
||||
IsAvailable = true,
|
||||
ImageUrl = "/images/packages/basic.jpg",
|
||||
ImagePath = "/images/packages/basic.jpg", // Populate alias field
|
||||
ValidityDays = 90,
|
||||
IsPopular = false,
|
||||
ShortDescription = "مناسب برای شروع کنندهها"
|
||||
}
|
||||
};
|
||||
|
||||
return new GetCustomerPackagesResponse
|
||||
{
|
||||
Models = { packages }
|
||||
IncludeInactive = request.IncludeInactive,
|
||||
PackageTypeFilter = request.PackageTypeFilter != PackageTypeEnum.PackageTypeBasic
|
||||
? (int?)request.PackageTypeFilter
|
||||
: null
|
||||
};
|
||||
|
||||
var result = await _sender.Send(query, context.CancellationToken);
|
||||
|
||||
var response = new GetCustomerPackagesResponse();
|
||||
response.Models.AddRange(result.Adapt<List<CustomerPackageModel>>());
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public override async Task<GetCustomerPackageDetailsResponse> GetCustomerPackageDetails(GetCustomerPackageDetailsRequest request, ServerCallContext context)
|
||||
{
|
||||
// Mock Customer package details with comprehensive Persian information
|
||||
var packageFeatures = new List<PackageFeature>
|
||||
var query = new GetCustomerPackageDetailsQuery
|
||||
{
|
||||
new PackageFeature
|
||||
{
|
||||
Title = "درآمد کمیسیون",
|
||||
Description = "دریافت کمیسیون از فروش محصولات",
|
||||
Icon = "commission",
|
||||
IsHighlighted = true
|
||||
},
|
||||
new PackageFeature
|
||||
{
|
||||
Title = "پشتیبانی 24/7",
|
||||
Description = "دسترسی به پشتیبانی در تمام ساعات شبانه روز",
|
||||
Icon = "support",
|
||||
IsHighlighted = false
|
||||
},
|
||||
new PackageFeature
|
||||
{
|
||||
Title = "آموزشهای تخصصی",
|
||||
Description = "دسترسی به دورههای آموزشی و وبینارها",
|
||||
Icon = "education",
|
||||
IsHighlighted = true
|
||||
}
|
||||
PackageId = request.PackageId
|
||||
};
|
||||
|
||||
return new GetCustomerPackageDetailsResponse
|
||||
|
||||
var result = await _sender.Send(query, context.CancellationToken);
|
||||
|
||||
var response = new GetCustomerPackageDetailsResponse
|
||||
{
|
||||
Id = request.PackageId,
|
||||
Title = "پکیج طلایی",
|
||||
Description = "پکیج کامل با تمام امکانات برای کاربران حرفهای",
|
||||
Price = 5600000,
|
||||
ImagePath = "/images/packages/golden-detail.jpg",
|
||||
Features = { packageFeatures },
|
||||
Requirements = new PurchaseRequirements
|
||||
{
|
||||
RequiresMembership = false,
|
||||
MinimumWalletBalance = 560000,
|
||||
Restrictions = { "باید حداقل 18 سال سن داشته باشید", "تایید هویت الزامی است" }
|
||||
}
|
||||
Id = result.Id,
|
||||
Title = result.Title,
|
||||
Description = result.Description,
|
||||
Price = result.Price,
|
||||
ImagePath = result.ImagePath
|
||||
};
|
||||
|
||||
// Map Features
|
||||
foreach (var feature in result.Features)
|
||||
{
|
||||
response.Features.Add(new PackageFeature
|
||||
{
|
||||
Title = feature.Title,
|
||||
Description = feature.Description,
|
||||
Icon = feature.Icon,
|
||||
IsHighlighted = feature.IsHighlighted
|
||||
});
|
||||
}
|
||||
|
||||
// Map Requirements
|
||||
response.Requirements = new PurchaseRequirements
|
||||
{
|
||||
RequiresMembership = result.Requirements.RequiresMembership,
|
||||
MinimumWalletBalance = result.Requirements.MinimumWalletBalance
|
||||
};
|
||||
response.Requirements.Restrictions.AddRange(result.Requirements.Restrictions);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public override async Task<CustomerPurchasePackageResponse> CustomerPurchasePackage(CustomerPurchasePackageRequest request, ServerCallContext context)
|
||||
@@ -189,7 +151,7 @@ public class PackageService : PackageContract.PackageContractBase
|
||||
Success = true,
|
||||
Message = "درخواست خرید پکیج با موفقیت ثبت شد",
|
||||
OrderId = orderId,
|
||||
PaymentGatewayUrl = $"https://payment.gateway.com/payment?authority={authority}&amount={GetPackagePrice(request.PackageId)}",
|
||||
PaymentGatewayUrl = $"https://payment.gateway.com/payment?authority={authority}&amount=5600000",
|
||||
Authority = authority
|
||||
};
|
||||
}
|
||||
@@ -221,60 +183,43 @@ public class PackageService : PackageContract.PackageContractBase
|
||||
|
||||
public override async Task<GetCustomerPurchaseHistoryResponse> GetCustomerPurchaseHistory(GetCustomerPurchaseHistoryRequest request, ServerCallContext context)
|
||||
{
|
||||
// Mock Customer purchase history with realistic Persian data
|
||||
var purchases = new List<PackagePurchaseHistory>
|
||||
var query = new GetCustomerPurchaseHistoryQuery
|
||||
{
|
||||
new PackagePurchaseHistory
|
||||
{
|
||||
Id = 1,
|
||||
PackageId = 1,
|
||||
PackageName = "پکیج طلایی",
|
||||
Amount = 5600000,
|
||||
PackageType = PackageTypeEnum.PackageTypeGolden,
|
||||
PurchaseDate = Timestamp.FromDateTime(DateTime.UtcNow.AddDays(-30)),
|
||||
ExpiryDate = Timestamp.FromDateTime(DateTime.UtcNow.AddDays(335)),
|
||||
Status = PaymentStatusEnum.PaymentStatusSuccess,
|
||||
StatusMessage = "فعال",
|
||||
ReferenceCode = "REF123456789"
|
||||
},
|
||||
new PackagePurchaseHistory
|
||||
{
|
||||
Id = 2,
|
||||
PackageId = 2,
|
||||
PackageName = "پکیج پریمیوم",
|
||||
Amount = 3200000,
|
||||
PackageType = PackageTypeEnum.PackageTypePremium,
|
||||
PurchaseDate = Timestamp.FromDateTime(DateTime.UtcNow.AddDays(-180)),
|
||||
ExpiryDate = Timestamp.FromDateTime(DateTime.UtcNow.AddDays(-150)),
|
||||
Status = PaymentStatusEnum.PaymentStatusSuccess,
|
||||
StatusMessage = "منقضی شده",
|
||||
ReferenceCode = "REF987654321"
|
||||
}
|
||||
UserId = request.UserId,
|
||||
PaginationState = request.PaginationState?.Adapt<AppModels.PaginationState>(),
|
||||
PackageTypeFilter = request.PackageTypeFilter != PackageTypeEnum.PackageTypeBasic
|
||||
? (int?)request.PackageTypeFilter
|
||||
: null,
|
||||
FromDate = request.FromDate?.ToDateTime(),
|
||||
ToDate = request.ToDate?.ToDateTime()
|
||||
};
|
||||
|
||||
return new GetCustomerPurchaseHistoryResponse
|
||||
|
||||
var result = await _sender.Send(query, context.CancellationToken);
|
||||
|
||||
var response = new GetCustomerPurchaseHistoryResponse
|
||||
{
|
||||
MetaData = new MetaData
|
||||
{
|
||||
CurrentPage = request.PaginationState?.PageNumber ?? 1,
|
||||
TotalPage = 1,
|
||||
PageSize = request.PaginationState?.PageSize ?? 10,
|
||||
TotalCount = purchases.Count,
|
||||
HasPrevious = false,
|
||||
HasNext = false
|
||||
},
|
||||
Purchases = { purchases }
|
||||
MetaData = result.MetaData.Adapt<MetaData>()
|
||||
};
|
||||
}
|
||||
|
||||
private long GetPackagePrice(long packageId)
|
||||
{
|
||||
return packageId switch
|
||||
|
||||
foreach (var purchase in result.Purchases)
|
||||
{
|
||||
1 => 5600000, // Golden
|
||||
2 => 3200000, // Premium
|
||||
3 => 1500000, // Basic
|
||||
_ => 1000000 // Default
|
||||
};
|
||||
response.Purchases.Add(new PackagePurchaseHistory
|
||||
{
|
||||
Id = purchase.Id,
|
||||
PackageId = purchase.PackageId,
|
||||
PackageName = purchase.PackageName,
|
||||
Amount = purchase.Amount,
|
||||
PackageType = (PackageTypeEnum)purchase.PackageType,
|
||||
PurchaseDate = Timestamp.FromDateTime(DateTime.SpecifyKind(purchase.PurchaseDate, DateTimeKind.Utc)),
|
||||
ExpiryDate = purchase.ExpiryDate.HasValue
|
||||
? Timestamp.FromDateTime(DateTime.SpecifyKind(purchase.ExpiryDate.Value, DateTimeKind.Utc))
|
||||
: null,
|
||||
Status = (PaymentStatusEnum)purchase.Status,
|
||||
StatusMessage = purchase.StatusMessage,
|
||||
ReferenceCode = purchase.ReferenceCode
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user