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
@@ -1,10 +1,22 @@
using CMSMicroservice.Protobuf.Protos.Products;
using Grpc.Core;
using MediatR;
using CMSMicroservice.Application.ProductsCQ.Queries.GetCustomerProducts;
using CMSMicroservice.Application.ProductsCQ.Queries.GetCustomerProductsByFilter;
using Mapster;
using AppModels = CMSMicroservice.Application.Common.Models;
using System.Collections.Generic;
namespace CMSMicroservice.WebApi.Services;
public class ProductsService : ProductsContract.ProductsContractBase
{
private readonly ISender _sender;
public ProductsService(ISender sender)
{
_sender = sender;
}
public override async Task<CreateNewProductsResponse> CreateNewProducts(CreateNewProductsRequest request, ServerCallContext context)
{
throw new RpcException(new Status(StatusCode.Unimplemented, "Method not implemented yet"));
@@ -54,121 +66,159 @@ public class ProductsService : ProductsContract.ProductsContractBase
public override async Task<GetProductsResponse> GetCustomerProducts(GetProductsRequest request, ServerCallContext context)
{
// For now, return mock response with gallery and categories
return new GetProductsResponse
var query = new GetCustomerProductsQuery { Id = request.Id };
var result = await _sender.Send(query, context.CancellationToken);
var response = new GetProductsResponse
{
Id = request.Id,
Title = $"Product {request.Id}",
Description = "Sample product description for customers",
ShortInfomation = "Short info",
FullInformation = "Full product information for customers",
Price = 50000,
Discount = 10,
Rate = 4,
ImagePath = "/images/product.jpg",
ThumbnailPath = "/images/product-thumb.jpg",
SaleCount = 25,
ViewCount = 150,
RemainingCount = 10,
Gallery =
Id = result.Id,
Title = result.Title,
Description = result.Description,
ShortInfomation = result.ShortInfomation,
FullInformation = result.FullInformation,
Price = result.Price,
Discount = result.Discount,
Rate = result.Rate,
ImagePath = result.ImagePath,
ThumbnailPath = result.ThumbnailPath,
SaleCount = result.SaleCount,
ViewCount = result.ViewCount,
RemainingCount = result.RemainingCount
};
// Add gallery items
if (result.Gallery != null)
{
foreach (var item in result.Gallery)
{
new ProductGalleryItem
response.Gallery.Add(new ProductGalleryItem
{
ProductGalleryId = 1,
ProductImageId = 1,
Title = "Main Image",
ImagePath = "/gallery/main.jpg",
ImageThumbnailPath = "/gallery/main-thumb.jpg"
}
},
Categories =
ProductGalleryId = item.ProductGalleryId,
ProductImageId = item.ProductImageId,
Title = item.Title,
ImagePath = item.ImagePath,
ImageThumbnailPath = item.ImageThumbnailPath
});
}
}
// Add categories
if (result.Categories != null)
{
foreach (var cat in result.Categories)
{
new ProductCategoryPath
var categoryPath = new ProductCategoryPath
{
CategoryId = 1,
Title = "Electronics",
Path =
CategoryId = cat.CategoryId,
Title = cat.Title
};
if (cat.Path != null)
{
foreach (var node in cat.Path)
{
new CategoryNode { Id = 1, Title = "Electronics" }
categoryPath.Path.Add(new CategoryNode
{
Id = node.Id,
Title = node.Title,
ParentId = node.ParentId
});
}
}
response.Categories.Add(categoryPath);
}
};
}
return response;
}
public override async Task<GetCustomerProductsByFilterResponse> GetCustomerProductsByFilter(GetAllProductsByFilterRequest request, ServerCallContext context)
{
// Mock response for customers with categories
return new GetCustomerProductsByFilterResponse
var query = new GetCustomerProductsByFilterQuery
{
PaginationState = request.PaginationState?.Adapt<AppModels.PaginationState>(),
SortBy = request.SortBy,
Id = request.Filter?.Id,
Title = request.Filter?.Title,
Description = request.Filter?.Description,
ShortInfomation = request.Filter?.ShortInfomation,
FullInformation = request.Filter?.FullInformation,
Price = request.Filter?.Price,
Discount = request.Filter?.Discount,
Rate = request.Filter?.Rate,
ImagePath = request.Filter?.ImagePath,
ThumbnailPath = request.Filter?.ThumbnailPath,
SaleCount = request.Filter?.SaleCount,
ViewCount = request.Filter?.ViewCount,
RemainingCount = request.Filter?.RemainingCount,
CategoryIds = request.Filter?.CategoryId != null ? new List<long> { request.Filter.CategoryId.Value } : null
};
var result = await _sender.Send(query, context.CancellationToken);
var response = new GetCustomerProductsByFilterResponse
{
MetaData = new CMSMicroservice.Protobuf.Protos.MetaData
{
CurrentPage = 1,
TotalPage = 1,
PageSize = 10,
TotalCount = 2,
HasPrevious = false,
HasNext = false
},
Models =
{
new GetCustomerProductsByFilterResponseModel
{
Id = 1,
Title = "Sample Product 1",
Description = "Description 1",
ShortInfomation = "Short info 1",
FullInformation = "Full info 1",
Price = 45000,
Discount = 5,
Rate = 4,
ImagePath = "/images/product1.jpg",
ThumbnailPath = "/images/product1-thumb.jpg",
SaleCount = 15,
ViewCount = 120,
RemainingCount = 8,
Categories =
{
new ProductCategoryPath
{
CategoryId = 1,
Title = "Electronics",
Path =
{
new CategoryNode { Id = 1, Title = "Electronics" }
}
}
}
},
new GetCustomerProductsByFilterResponseModel
{
Id = 2,
Title = "Sample Product 2",
Description = "Description 2",
ShortInfomation = "Short info 2",
FullInformation = "Full info 2",
Price = 35000,
Discount = 15,
Rate = 5,
ImagePath = "/images/product2.jpg",
ThumbnailPath = "/images/product2-thumb.jpg",
SaleCount = 30,
ViewCount = 200,
RemainingCount = 5,
Categories =
{
new ProductCategoryPath
{
CategoryId = 2,
Title = "Books",
Path =
{
new CategoryNode { Id = 2, Title = "Books" }
}
}
}
}
CurrentPage = result.MetaData.CurrentPage,
TotalPage = result.MetaData.TotalPage,
PageSize = result.MetaData.PageSize,
TotalCount = result.MetaData.TotalCount,
HasPrevious = result.MetaData.HasPrevious,
HasNext = result.MetaData.HasNext
}
};
foreach (var model in result.Models)
{
var productModel = new GetCustomerProductsByFilterResponseModel
{
Id = model.Id,
Title = model.Title,
Description = model.Description,
ShortInfomation = model.ShortInfomation,
FullInformation = model.FullInformation,
Price = model.Price,
Discount = model.Discount,
Rate = model.Rate,
ImagePath = model.ImagePath,
ThumbnailPath = model.ThumbnailPath,
SaleCount = model.SaleCount,
ViewCount = model.ViewCount,
RemainingCount = model.RemainingCount
};
if (model.Categories != null)
{
foreach (var cat in model.Categories)
{
var categoryPath = new ProductCategoryPath
{
CategoryId = cat.CategoryId,
Title = cat.Title
};
if (cat.Path != null)
{
foreach (var node in cat.Path)
{
categoryPath.Path.Add(new CategoryNode
{
Id = node.Id,
Title = node.Title,
ParentId = node.ParentId
});
}
}
productModel.Categories.Add(categoryPath);
}
}
response.Models.Add(productModel);
}
return response;
}
}