246d893b62
Build and Deploy to Kubernetes / build-and-deploy (push) Has been cancelled
- Introduced InStock property to GetDiscountProductsQuery and GetCustomerProductsByFilterQuery for filtering based on product availability. - Updated query handlers to apply InStock filtering logic in both discount and customer product queries. - Enhanced mapping configurations to include InStock in the response DTOs. - Bumped Protobuf project version to reflect the addition of new features.
81 lines
3.3 KiB
C#
81 lines
3.3 KiB
C#
using CMSMicroservice.Application.Common.Models;
|
|
using CMSMicroservice.Application.DiscountShopCQ.Queries.GetDiscountProducts;
|
|
using CMSMicroservice.Protobuf.Protos.DiscountProduct;
|
|
using Google.Protobuf.WellKnownTypes;
|
|
using Mapster;
|
|
using ProtoDiscountProductDto = CMSMicroservice.Protobuf.Protos.DiscountProduct.DiscountProductDto;
|
|
|
|
namespace CMSMicroservice.WebApi.Common.Mappings;
|
|
|
|
public class DiscountProductProfile : IRegister
|
|
{
|
|
void IRegister.Register(TypeAdapterConfig config)
|
|
{
|
|
// GetDiscountProductsRequest (proto) → GetDiscountProductsQuery (CQRS)
|
|
config.NewConfig<GetDiscountProductsRequest, GetDiscountProductsQuery>()
|
|
.Map(dest => dest.SearchTerm,
|
|
src => string.IsNullOrEmpty(src.SearchQuery) ? null : src.SearchQuery)
|
|
.Map(dest => dest.CategoryId,
|
|
src => src.CategoryId != null ? src.CategoryId.Value : (long?)null)
|
|
.Map(dest => dest.IsActive,
|
|
src => src.IsActive != null ? src.IsActive.Value : (bool?)null)
|
|
.Map(dest => dest.InStock,
|
|
src => src.InStock != null ? src.InStock.Value : (bool?)null)
|
|
.Map(dest => dest.MinPrice,
|
|
src => src.MinPrice != null ? (int?)src.MinPrice.Value : null)
|
|
.Map(dest => dest.MaxPrice,
|
|
src => src.MaxPrice != null ? (int?)src.MaxPrice.Value : null)
|
|
.Map(dest => dest.SortBy,
|
|
src => string.IsNullOrEmpty(src.SortBy) ? null : src.SortBy)
|
|
.Map(dest => dest.PaginationQuery, src => new PaginationState
|
|
{
|
|
PageNumber = src.PageNumber > 0 ? src.PageNumber : 1,
|
|
PageSize = src.PageSize > 0 ? src.PageSize : 12
|
|
});
|
|
|
|
// GetDiscountProductsResponseDto (CQRS) → GetDiscountProductsResponse (proto)
|
|
config.NewConfig<GetDiscountProductsResponseDto, GetDiscountProductsResponse>()
|
|
.MapWith(src => MapToResponse(src));
|
|
}
|
|
|
|
private static GetDiscountProductsResponse MapToResponse(GetDiscountProductsResponseDto src)
|
|
{
|
|
var response = new GetDiscountProductsResponse();
|
|
|
|
if (src.MetaData != null)
|
|
{
|
|
response.MetaData = new CMSMicroservice.Protobuf.Protos.MetaData
|
|
{
|
|
TotalCount = src.MetaData.TotalCount,
|
|
PageSize = src.MetaData.PageSize,
|
|
CurrentPage = src.MetaData.CurrentPage,
|
|
TotalPage = src.MetaData.TotalPage
|
|
};
|
|
}
|
|
|
|
if (src.Models != null)
|
|
{
|
|
foreach (var p in src.Models)
|
|
{
|
|
response.Models.Add(new ProtoDiscountProductDto
|
|
{
|
|
Id = p.Id,
|
|
Title = p.Title ?? string.Empty,
|
|
ShortInfomation = p.ShortInfomation ?? string.Empty,
|
|
Price = p.Price,
|
|
MaxDiscountPercent = p.MaxDiscountPercent,
|
|
ImagePath = p.ImagePath ?? string.Empty,
|
|
ThumbnailPath = p.ThumbnailPath ?? string.Empty,
|
|
RemainingCount = p.RemainingCount,
|
|
ViewCount = p.ViewCount,
|
|
SaleCount = p.SaleCount,
|
|
IsActive = p.IsActive,
|
|
Created = Timestamp.FromDateTime(DateTime.UtcNow)
|
|
});
|
|
}
|
|
}
|
|
|
|
return response;
|
|
}
|
|
}
|