feat: Implement DiscountCategoryProfile for mapping GetDiscountCategories response to protobuf
Build and Deploy / build (push) Successful in 2m16s
Build and Deploy / build (push) Successful in 2m16s
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using BackOffice.BFF.Application.DiscountCategoryCQ.Queries.GetDiscountCategories;
|
||||
using BackOffice.BFF.DiscountCategory.Protobuf.Protos.DiscountCategory;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using Mapster;
|
||||
|
||||
namespace BackOffice.BFF.WebApi.Common.Mappings;
|
||||
|
||||
public class DiscountCategoryProfile : IRegister
|
||||
{
|
||||
void IRegister.Register(TypeAdapterConfig config)
|
||||
{
|
||||
// Map GetDiscountCategories response DTO to protobuf response
|
||||
config.NewConfig<GetDiscountCategoriesResponseDto, GetDiscountCategoriesResponse>()
|
||||
.MapWith(src => new GetDiscountCategoriesResponse
|
||||
{
|
||||
Categories = { src.Categories.Select(MapCategoryTree) }
|
||||
});
|
||||
}
|
||||
|
||||
private static DiscountCategoryDto MapCategoryTree(DiscountCategoryTreeDto src)
|
||||
{
|
||||
var dto = new DiscountCategoryDto
|
||||
{
|
||||
Id = src.Id,
|
||||
Name = src.Name ?? string.Empty,
|
||||
Title = src.Title ?? string.Empty,
|
||||
Description = !string.IsNullOrWhiteSpace(src.Description) ? src.Description : null,
|
||||
ImagePath = !string.IsNullOrWhiteSpace(src.ImagePath) ? src.ImagePath : null,
|
||||
ParentCategoryId = src.ParentCategoryId,
|
||||
SortOrder = src.SortOrder,
|
||||
IsActive = src.IsActive,
|
||||
ProductCount = src.ProductCount
|
||||
};
|
||||
|
||||
// Recursively map children
|
||||
if (src.ChildCategories != null && src.ChildCategories.Any())
|
||||
{
|
||||
dto.Children.AddRange(src.ChildCategories.Select(MapCategoryTree));
|
||||
}
|
||||
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user