From 27a2535dde0b0d58d7d2c10834d26470fe0c8771 Mon Sep 17 00:00:00 2001 From: efrilm Date: Tue, 7 Oct 2025 00:02:15 +0700 Subject: [PATCH] update product analytic --- internal/contract/analytics_contract.go | 1 + internal/entities/analytics.go | 1 + internal/models/analytics.go | 1 + internal/processor/analytics_processor.go | 1 + internal/repository/analytics_repository.go | 3 ++- internal/transformer/analytics_transformer.go | 1 + 6 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/contract/analytics_contract.go b/internal/contract/analytics_contract.go index 817ed55..026170a 100644 --- a/internal/contract/analytics_contract.go +++ b/internal/contract/analytics_contract.go @@ -107,6 +107,7 @@ type ProductAnalyticsData struct { ProductName string `json:"product_name"` CategoryID uuid.UUID `json:"category_id"` CategoryName string `json:"category_name"` + CategoryOrder int `json:"category_order"` QuantitySold int64 `json:"quantity_sold"` Revenue float64 `json:"revenue"` AveragePrice float64 `json:"average_price"` diff --git a/internal/entities/analytics.go b/internal/entities/analytics.go index 75ae947..0ba9882 100644 --- a/internal/entities/analytics.go +++ b/internal/entities/analytics.go @@ -33,6 +33,7 @@ type ProductAnalytics struct { ProductName string `json:"product_name"` CategoryID uuid.UUID `json:"category_id"` CategoryName string `json:"category_name"` + CategoryOrder int `json:"category_order"` QuantitySold int64 `json:"quantity_sold"` Revenue float64 `json:"revenue"` AveragePrice float64 `json:"average_price"` diff --git a/internal/models/analytics.go b/internal/models/analytics.go index f0e865d..e20b4df 100644 --- a/internal/models/analytics.go +++ b/internal/models/analytics.go @@ -111,6 +111,7 @@ type ProductAnalyticsData struct { ProductName string `json:"product_name"` CategoryID uuid.UUID `json:"category_id"` CategoryName string `json:"category_name"` + CategoryOrder int `json:"category_order"` QuantitySold int64 `json:"quantity_sold"` Revenue float64 `json:"revenue"` AveragePrice float64 `json:"average_price"` diff --git a/internal/processor/analytics_processor.go b/internal/processor/analytics_processor.go index bf121c0..5d343b5 100644 --- a/internal/processor/analytics_processor.go +++ b/internal/processor/analytics_processor.go @@ -189,6 +189,7 @@ func (p *AnalyticsProcessorImpl) GetProductAnalytics(ctx context.Context, req *m ProductName: data.ProductName, CategoryID: data.CategoryID, CategoryName: data.CategoryName, + CategoryOrder: data.CategoryOrder, QuantitySold: data.QuantitySold, Revenue: data.Revenue, AveragePrice: data.AveragePrice, diff --git a/internal/repository/analytics_repository.go b/internal/repository/analytics_repository.go index b69b39e..d2b0d79 100644 --- a/internal/repository/analytics_repository.go +++ b/internal/repository/analytics_repository.go @@ -113,6 +113,7 @@ func (r *AnalyticsRepositoryImpl) GetProductAnalytics(ctx context.Context, organ p.name as product_name, c.id as category_id, c.name as category_name, + c.order as category_order, COALESCE(SUM(oi.quantity), 0) as quantity_sold, COALESCE(SUM(oi.total_price), 0) as revenue, CASE @@ -133,7 +134,7 @@ func (r *AnalyticsRepositoryImpl) GetProductAnalytics(ctx context.Context, organ } err := query. - Group("p.id, p.name, c.id, c.name"). + Group("p.id, p.name, c.id, c.name, c.order"). Order("revenue DESC"). Limit(limit). Scan(&results).Error diff --git a/internal/transformer/analytics_transformer.go b/internal/transformer/analytics_transformer.go index 96b7786..3592893 100644 --- a/internal/transformer/analytics_transformer.go +++ b/internal/transformer/analytics_transformer.go @@ -159,6 +159,7 @@ func ProductAnalyticsModelToContract(resp *models.ProductAnalyticsResponse) *con ProductName: item.ProductName, CategoryID: item.CategoryID, CategoryName: item.CategoryName, + CategoryOrder: item.CategoryOrder, QuantitySold: item.QuantitySold, Revenue: item.Revenue, AveragePrice: item.AveragePrice,