From 3aabf10a510f7cf8cbd5d9183fef531be9d49d0c Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Sun, 4 Jan 2026 22:38:39 +0330 Subject: [PATCH] feat: Implement DiscountCategoryProfile for mapping GetDiscountCategories response to protobuf --- .../Mappings/DiscountCategoryProfile.cs | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/BackOffice.BFF.WebApi/Common/Mappings/DiscountCategoryProfile.cs diff --git a/src/BackOffice.BFF.WebApi/Common/Mappings/DiscountCategoryProfile.cs b/src/BackOffice.BFF.WebApi/Common/Mappings/DiscountCategoryProfile.cs new file mode 100644 index 0000000..57cce8f --- /dev/null +++ b/src/BackOffice.BFF.WebApi/Common/Mappings/DiscountCategoryProfile.cs @@ -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() + .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; + } +}