From b59b7b4ddd8da2d272f23767fdad5ee8ea706fa1 Mon Sep 17 00:00:00 2001 From: efrilm Date: Sat, 3 Oct 2026 00:15:43 +0700 Subject: [PATCH] feat: update parent category detail --- internal/contract/analytics_contract.go | 3 +++ internal/models/analytics.go | 3 +++ internal/processor/analytics_processor.go | 11 +++++++++++ internal/transformer/analytics_transformer.go | 3 +++ 4 files changed, 20 insertions(+) diff --git a/internal/contract/analytics_contract.go b/internal/contract/analytics_contract.go index 97ec2a8..d5dccfe 100644 --- a/internal/contract/analytics_contract.go +++ b/internal/contract/analytics_contract.go @@ -329,6 +329,9 @@ type ParentCategoryAnalyticsDetailSummary struct { type ParentCategoryAnalyticsDetailData struct { CategoryID uuid.UUID `json:"category_id"` CategoryName string `json:"category_name"` + OwnerFeePercent float64 `json:"owner_fee_percent"` + SDL float64 `json:"sdl"` + TopProduct *ParentCategoryTopProduct `json:"top_product"` TotalRevenue float64 `json:"total_revenue"` TotalQuantity int64 `json:"total_quantity"` ProductCount int64 `json:"product_count"` diff --git a/internal/models/analytics.go b/internal/models/analytics.go index 1810dfd..0e23750 100644 --- a/internal/models/analytics.go +++ b/internal/models/analytics.go @@ -369,6 +369,9 @@ type ParentCategoryAnalyticsDetailSummary struct { type ParentCategoryAnalyticsDetailData struct { CategoryID uuid.UUID `json:"category_id"` CategoryName string `json:"category_name"` + OwnerFeePercent float64 `json:"owner_fee_percent"` + SDL float64 `json:"sdl"` + TopProduct *ParentCategoryTopProduct `json:"top_product"` TotalRevenue float64 `json:"total_revenue"` TotalQuantity int64 `json:"total_quantity"` ProductCount int64 `json:"product_count"` diff --git a/internal/processor/analytics_processor.go b/internal/processor/analytics_processor.go index 921015e..80d8bdd 100644 --- a/internal/processor/analytics_processor.go +++ b/internal/processor/analytics_processor.go @@ -469,7 +469,9 @@ func (p *AnalyticsProcessorImpl) GetParentCategoryAnalyticsDetail(ctx context.Co // Bucket the product rows by the category they belong to productsByCategory := make(map[uuid.UUID][]models.ParentCategoryAnalyticsProductData) + productRowsByCategory := make(map[uuid.UUID][]*entities.ProductAnalytics) for _, product := range detail.Products { + productRowsByCategory[product.CategoryID] = append(productRowsByCategory[product.CategoryID], product) productsByCategory[product.CategoryID] = append(productsByCategory[product.CategoryID], models.ParentCategoryAnalyticsProductData{ ProductID: product.ProductID, ProductName: product.ProductName, @@ -489,6 +491,12 @@ func (p *AnalyticsProcessorImpl) GetParentCategoryAnalyticsDetail(ctx context.Co }) } + // Sub-categories take the owner fee of the parent category they sit under + var ownerFeePercent float64 + if detail.Summary != nil { + ownerFeePercent = detail.Summary.OwnerFeePercent + } + categories := make([]models.ParentCategoryAnalyticsDetailData, 0, len(detail.Categories)) for _, category := range detail.Categories { products := productsByCategory[category.CategoryID] @@ -499,6 +507,9 @@ func (p *AnalyticsProcessorImpl) GetParentCategoryAnalyticsDetail(ctx context.Co categories = append(categories, models.ParentCategoryAnalyticsDetailData{ CategoryID: category.CategoryID, CategoryName: category.CategoryName, + OwnerFeePercent: ownerFeePercent, + SDL: category.TotalRevenue * ownerFeePercent / 100, + TopProduct: topProductByRevenue(productRowsByCategory[category.CategoryID]), TotalRevenue: category.TotalRevenue, TotalQuantity: category.TotalQuantity, ProductCount: category.ProductCount, diff --git a/internal/transformer/analytics_transformer.go b/internal/transformer/analytics_transformer.go index bb09349..0166d2a 100644 --- a/internal/transformer/analytics_transformer.go +++ b/internal/transformer/analytics_transformer.go @@ -544,6 +544,9 @@ func ParentCategoryAnalyticsDetailModelToContract(resp *models.ParentCategoryAna categories = append(categories, contract.ParentCategoryAnalyticsDetailData{ CategoryID: category.CategoryID, CategoryName: category.CategoryName, + OwnerFeePercent: category.OwnerFeePercent, + SDL: category.SDL, + TopProduct: parentCategoryTopProductModelToContract(category.TopProduct), TotalRevenue: category.TotalRevenue, TotalQuantity: category.TotalQuantity, ProductCount: category.ProductCount,