fix: change return on state backend

This commit is contained in:
2026-07-07 14:58:23 +03:00
parent 3027684395
commit f84d20ba20
+3 -2
View File
@@ -20,14 +20,15 @@ func GetTopItems(c *gin.Context) {
results := []TopItem{} results := []TopItem{}
err := database.DB.Table("order_items"). 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"). 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"). Order("revenue DESC").
Limit(5). Limit(5).
Scan(&results).Error Scan(&results).Error
if err != nil { if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
} }
c.JSON(http.StatusOK, results) c.JSON(http.StatusOK, results)