fix: change return on state backend
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user