update product analytic

This commit is contained in:
efrilm 2025-10-07 00:02:15 +07:00
parent f55ea1ceb0
commit 27a2535dde
6 changed files with 7 additions and 1 deletions

View File

@ -107,6 +107,7 @@ type ProductAnalyticsData struct {
ProductName string `json:"product_name"` ProductName string `json:"product_name"`
CategoryID uuid.UUID `json:"category_id"` CategoryID uuid.UUID `json:"category_id"`
CategoryName string `json:"category_name"` CategoryName string `json:"category_name"`
CategoryOrder int `json:"category_order"`
QuantitySold int64 `json:"quantity_sold"` QuantitySold int64 `json:"quantity_sold"`
Revenue float64 `json:"revenue"` Revenue float64 `json:"revenue"`
AveragePrice float64 `json:"average_price"` AveragePrice float64 `json:"average_price"`

View File

@ -33,6 +33,7 @@ type ProductAnalytics struct {
ProductName string `json:"product_name"` ProductName string `json:"product_name"`
CategoryID uuid.UUID `json:"category_id"` CategoryID uuid.UUID `json:"category_id"`
CategoryName string `json:"category_name"` CategoryName string `json:"category_name"`
CategoryOrder int `json:"category_order"`
QuantitySold int64 `json:"quantity_sold"` QuantitySold int64 `json:"quantity_sold"`
Revenue float64 `json:"revenue"` Revenue float64 `json:"revenue"`
AveragePrice float64 `json:"average_price"` AveragePrice float64 `json:"average_price"`

View File

@ -111,6 +111,7 @@ type ProductAnalyticsData struct {
ProductName string `json:"product_name"` ProductName string `json:"product_name"`
CategoryID uuid.UUID `json:"category_id"` CategoryID uuid.UUID `json:"category_id"`
CategoryName string `json:"category_name"` CategoryName string `json:"category_name"`
CategoryOrder int `json:"category_order"`
QuantitySold int64 `json:"quantity_sold"` QuantitySold int64 `json:"quantity_sold"`
Revenue float64 `json:"revenue"` Revenue float64 `json:"revenue"`
AveragePrice float64 `json:"average_price"` AveragePrice float64 `json:"average_price"`

View File

@ -189,6 +189,7 @@ func (p *AnalyticsProcessorImpl) GetProductAnalytics(ctx context.Context, req *m
ProductName: data.ProductName, ProductName: data.ProductName,
CategoryID: data.CategoryID, CategoryID: data.CategoryID,
CategoryName: data.CategoryName, CategoryName: data.CategoryName,
CategoryOrder: data.CategoryOrder,
QuantitySold: data.QuantitySold, QuantitySold: data.QuantitySold,
Revenue: data.Revenue, Revenue: data.Revenue,
AveragePrice: data.AveragePrice, AveragePrice: data.AveragePrice,

View File

@ -113,6 +113,7 @@ func (r *AnalyticsRepositoryImpl) GetProductAnalytics(ctx context.Context, organ
p.name as product_name, p.name as product_name,
c.id as category_id, c.id as category_id,
c.name as category_name, c.name as category_name,
c.order as category_order,
COALESCE(SUM(oi.quantity), 0) as quantity_sold, COALESCE(SUM(oi.quantity), 0) as quantity_sold,
COALESCE(SUM(oi.total_price), 0) as revenue, COALESCE(SUM(oi.total_price), 0) as revenue,
CASE CASE
@ -133,7 +134,7 @@ func (r *AnalyticsRepositoryImpl) GetProductAnalytics(ctx context.Context, organ
} }
err := query. 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"). Order("revenue DESC").
Limit(limit). Limit(limit).
Scan(&results).Error Scan(&results).Error

View File

@ -159,6 +159,7 @@ func ProductAnalyticsModelToContract(resp *models.ProductAnalyticsResponse) *con
ProductName: item.ProductName, ProductName: item.ProductName,
CategoryID: item.CategoryID, CategoryID: item.CategoryID,
CategoryName: item.CategoryName, CategoryName: item.CategoryName,
CategoryOrder: item.CategoryOrder,
QuantitySold: item.QuantitySold, QuantitySold: item.QuantitySold,
Revenue: item.Revenue, Revenue: item.Revenue,
AveragePrice: item.AveragePrice, AveragePrice: item.AveragePrice,