feat: update parent category detail

This commit is contained in:
efrilm
2026-10-03 00:15:43 +07:00
parent fbe7e97dc7
commit b59b7b4ddd
4 changed files with 20 additions and 0 deletions
+3
View File
@@ -329,6 +329,9 @@ type ParentCategoryAnalyticsDetailSummary struct {
type ParentCategoryAnalyticsDetailData struct { type ParentCategoryAnalyticsDetailData struct {
CategoryID uuid.UUID `json:"category_id"` CategoryID uuid.UUID `json:"category_id"`
CategoryName string `json:"category_name"` 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"` TotalRevenue float64 `json:"total_revenue"`
TotalQuantity int64 `json:"total_quantity"` TotalQuantity int64 `json:"total_quantity"`
ProductCount int64 `json:"product_count"` ProductCount int64 `json:"product_count"`
+3
View File
@@ -369,6 +369,9 @@ type ParentCategoryAnalyticsDetailSummary struct {
type ParentCategoryAnalyticsDetailData struct { type ParentCategoryAnalyticsDetailData struct {
CategoryID uuid.UUID `json:"category_id"` CategoryID uuid.UUID `json:"category_id"`
CategoryName string `json:"category_name"` 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"` TotalRevenue float64 `json:"total_revenue"`
TotalQuantity int64 `json:"total_quantity"` TotalQuantity int64 `json:"total_quantity"`
ProductCount int64 `json:"product_count"` ProductCount int64 `json:"product_count"`
+11
View File
@@ -469,7 +469,9 @@ func (p *AnalyticsProcessorImpl) GetParentCategoryAnalyticsDetail(ctx context.Co
// Bucket the product rows by the category they belong to // Bucket the product rows by the category they belong to
productsByCategory := make(map[uuid.UUID][]models.ParentCategoryAnalyticsProductData) productsByCategory := make(map[uuid.UUID][]models.ParentCategoryAnalyticsProductData)
productRowsByCategory := make(map[uuid.UUID][]*entities.ProductAnalytics)
for _, product := range detail.Products { for _, product := range detail.Products {
productRowsByCategory[product.CategoryID] = append(productRowsByCategory[product.CategoryID], product)
productsByCategory[product.CategoryID] = append(productsByCategory[product.CategoryID], models.ParentCategoryAnalyticsProductData{ productsByCategory[product.CategoryID] = append(productsByCategory[product.CategoryID], models.ParentCategoryAnalyticsProductData{
ProductID: product.ProductID, ProductID: product.ProductID,
ProductName: product.ProductName, 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)) categories := make([]models.ParentCategoryAnalyticsDetailData, 0, len(detail.Categories))
for _, category := range detail.Categories { for _, category := range detail.Categories {
products := productsByCategory[category.CategoryID] products := productsByCategory[category.CategoryID]
@@ -499,6 +507,9 @@ func (p *AnalyticsProcessorImpl) GetParentCategoryAnalyticsDetail(ctx context.Co
categories = append(categories, models.ParentCategoryAnalyticsDetailData{ categories = append(categories, models.ParentCategoryAnalyticsDetailData{
CategoryID: category.CategoryID, CategoryID: category.CategoryID,
CategoryName: category.CategoryName, CategoryName: category.CategoryName,
OwnerFeePercent: ownerFeePercent,
SDL: category.TotalRevenue * ownerFeePercent / 100,
TopProduct: topProductByRevenue(productRowsByCategory[category.CategoryID]),
TotalRevenue: category.TotalRevenue, TotalRevenue: category.TotalRevenue,
TotalQuantity: category.TotalQuantity, TotalQuantity: category.TotalQuantity,
ProductCount: category.ProductCount, ProductCount: category.ProductCount,
@@ -544,6 +544,9 @@ func ParentCategoryAnalyticsDetailModelToContract(resp *models.ParentCategoryAna
categories = append(categories, contract.ParentCategoryAnalyticsDetailData{ categories = append(categories, contract.ParentCategoryAnalyticsDetailData{
CategoryID: category.CategoryID, CategoryID: category.CategoryID,
CategoryName: category.CategoryName, CategoryName: category.CategoryName,
OwnerFeePercent: category.OwnerFeePercent,
SDL: category.SDL,
TopProduct: parentCategoryTopProductModelToContract(category.TopProduct),
TotalRevenue: category.TotalRevenue, TotalRevenue: category.TotalRevenue,
TotalQuantity: category.TotalQuantity, TotalQuantity: category.TotalQuantity,
ProductCount: category.ProductCount, ProductCount: category.ProductCount,