Files
bssapp/svc/routes/account.go
2026-02-11 17:46:22 +03:00

40 lines
928 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package routes
import (
"bssapp-backend/auth"
"bssapp-backend/internal/authz"
"bssapp-backend/queries"
"encoding/json"
"log"
"net/http"
)
func GetAccountsHandler(w http.ResponseWriter, r *http.Request) {
// ✅ AUTH (sadece login kontrolü)
claims, ok := auth.GetClaimsFromContext(r.Context())
if !ok || claims == nil {
http.Error(w, "unauthorized", http.StatusUnauthorized)
return
}
// ✅ DEBUG (scope kontrol için faydalı)
log.Println("🔍 PIYASA CTX:", authz.GetPiyasaCodesFromCtx(r.Context()))
// ✅ QUERY
accounts, err := queries.GetAccounts(r.Context())
if err != nil {
log.Println("❌ GetAccounts error:", err)
http.Error(w, "db error", http.StatusInternalServerError)
return
}
// ✅ RESPONSE
w.Header().Set("Content-Type", "application/json; charset=utf-8")
if err := json.NewEncoder(w).Encode(accounts); err != nil {
log.Println("❌ JSON encode error:", err)
return
}
}