feat: add table for purchase

This commit is contained in:
2026-08-07 08:33:09 +03:30
parent 3883d1b471
commit ba660f156c
6 changed files with 301 additions and 15 deletions
+13 -6
View File
@@ -30,6 +30,8 @@ func (h *Handler) APIRoutes() http.Handler {
r.Post("/users/coins", h.apiUserCoins)
r.Post("/users/grant", h.apiUserGrant)
r.Get("/purchases", h.apiPurchases)
r.Get("/carpets", h.apiCarpets)
r.Post("/carpets", h.apiCarpetUpsert)
r.Delete("/carpets", h.apiCarpetDelete)
@@ -73,13 +75,18 @@ func (h *Handler) apiDashboard(w http.ResponseWriter, r *http.Request) {
_ = h.db.QueryRowContext(ctx, q).Scan(&n)
return n
}
stats := h.purchasesStats(ctx)
httpx.JSON(w, http.StatusOK, map[string]any{
"users": count(`SELECT COUNT(*) FROM users`),
"purchases": count(`SELECT COUNT(*) FROM purchases WHERE status='verified'`),
"games": count(`SELECT COUNT(*) FROM game_history`),
"coins": count(`SELECT COALESCE(SUM(coins),0) FROM users`),
"tournaments": count(`SELECT COUNT(*) FROM tournaments`),
"season": h.eco.Season(ctx),
"users": count(`SELECT COUNT(*) FROM users`),
"purchases": count(`SELECT COUNT(*) FROM purchases WHERE status='verified'`),
"games": count(`SELECT COUNT(*) FROM game_history`),
"coins": count(`SELECT COALESCE(SUM(coins),0) FROM users`),
"tournaments": count(`SELECT COUNT(*) FROM tournaments`),
"season": h.eco.Season(ctx),
"revenue": stats["total_revenue"],
"revenue_today": stats["today"],
"revenue_14d": stats["last_14_days"],
"recent": h.purchaseRows(ctx, ` WHERE p.status = 'verified'`, nil, 8, 0),
})
}