feat: add admin panel

This commit is contained in:
2026-06-15 20:54:05 +03:30
parent 7dadb23fbe
commit 02060a4dc0
16 changed files with 698 additions and 108 deletions
+8
View File
@@ -11,6 +11,7 @@ import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"hakemsho/internal/admin"
"hakemsho/internal/auth"
"hakemsho/internal/config"
"hakemsho/internal/economy"
@@ -41,6 +42,10 @@ func main() {
// اقتصاد و فروشگاه. تأییدکننده‌ها فعلاً نسخه‌ی توسعه‌اند؛ آداپتر واقعی
// تپسل (تبلیغ) و بازار/مایکت (IAP) با تنظیم creds جایگزین می‌شوند.
eco := economy.New(st.DB, economy.DevAdVerifier{}, economy.DevIAPVerifier{})
if err := eco.LoadCatalog(context.Background()); err != nil {
slog.Error("load catalog", "err", err)
os.Exit(1)
}
ecoH := economy.NewHandler(eco)
// هاب WebSocket برای بازی realtime
@@ -75,6 +80,9 @@ func main() {
// WebSocket بازی (احراز هویت با توکن در ?token= یا هدر Authorization)
r.Get("/ws", hub.ServeWS)
// پنل ادمین (HTML سرور‌ساید، پشت Basic Auth)
r.Mount("/admin", admin.New(st.DB, eco).Routes(cfg.AdminUser, cfg.AdminPass))
r.Route("/api", func(r chi.Router) {
r.Route("/auth", func(r chi.Router) {
r.Post("/login-otp", authH.LoginOTP)
+4 -4
View File
@@ -14,7 +14,7 @@ type gameSettler struct {
}
func (g gameSettler) ChargeEntry(userID int64, tier string) error {
t := economy.FindTier(tier)
t := g.eco.FindTier(tier)
if t == nil {
return nil // tier ناشناخته ⇒ بدون ورودی
}
@@ -22,7 +22,7 @@ func (g gameSettler) ChargeEntry(userID int64, tier string) error {
}
func (g gameSettler) Refund(userID int64, tier string) {
t := economy.FindTier(tier)
t := g.eco.FindTier(tier)
if t == nil {
return
}
@@ -32,7 +32,7 @@ func (g gameSettler) Refund(userID int64, tier string) {
}
func (g gameSettler) AwardWinner(userID int64, tier string) {
t := economy.FindTier(tier)
t := g.eco.FindTier(tier)
if t == nil {
return
}
@@ -49,7 +49,7 @@ func (g gameSettler) RecordGame(room, playersJSON string, winnerTeam int, kot bo
// TargetHands تعداد هَندِ لازم برای برد بازی در این tier (مثلاً مبتدی=۳).
func (g gameSettler) TargetHands(tier string) int {
t := economy.FindTier(tier)
t := g.eco.FindTier(tier)
if t == nil || t.Hands <= 0 {
return 7
}