From f84d20ba20bb64ba615f00377163385df39efe8a Mon Sep 17 00:00:00 2001 From: LeonG11 Date: Tue, 7 Jul 2026 14:58:23 +0300 Subject: [PATCH] fix: change return on state backend --- backend/handlers/analytics_handler.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/handlers/analytics_handler.go b/backend/handlers/analytics_handler.go index 316f5fa..6666874 100644 --- a/backend/handlers/analytics_handler.go +++ b/backend/handlers/analytics_handler.go @@ -20,14 +20,15 @@ func GetTopItems(c *gin.Context) { results := []TopItem{} err := database.DB.Table("order_items"). - Select("items.name, SUM(order_items.price * order_items.quantity) AS revenue, order_items.price, SUM(order_items.quantity) as sale_quantity, items.unit"). + Select("items.name, SUM(order_items.price * order_items.quantity) AS revenue, AVG(order_items.price) as price, SUM(order_items.quantity) as sale_quantity, items.unit"). Joins("JOIN items ON items.id = order_items.item_id"). - Group("items.name, order_items.price, items.unit"). + Group("items.name, items.unit"). Order("revenue DESC"). Limit(5). Scan(&results).Error if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + return } c.JSON(http.StatusOK, results)