ilk
This commit is contained in:
61
svc/routes/admin_piyasa.go
Normal file
61
svc/routes/admin_piyasa.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"bssapp-backend/auth"
|
||||
"bssapp-backend/internal/authz"
|
||||
"bssapp-backend/middlewares"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// =====================================================
|
||||
// 🔐 ADMIN — PIYASA CACHE SYNC
|
||||
// =====================================================
|
||||
// POST /api/admin/users/{id}/piyasa-sync
|
||||
func AdminSyncUserPiyasaHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// --------------------------------------------------
|
||||
// 🔐 AUTH
|
||||
// --------------------------------------------------
|
||||
claims, ok := auth.GetClaimsFromContext(r.Context())
|
||||
if !ok || claims == nil {
|
||||
http.Error(w, "unauthorized", 401)
|
||||
return
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// 🆔 USER ID PARAM
|
||||
// --------------------------------------------------
|
||||
vars := mux.Vars(r)
|
||||
|
||||
idStr := vars["id"]
|
||||
|
||||
targetID, err := strconv.ParseInt(idStr, 10, 64)
|
||||
if err != nil {
|
||||
http.Error(w, "invalid user id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// --------------------------------------------------
|
||||
// 🧹 CACHE CLEAR
|
||||
// --------------------------------------------------
|
||||
authz.ClearPiyasaCache(int(targetID))
|
||||
middlewares.ClearAuthzScopeCacheForUser(targetID)
|
||||
|
||||
log.Printf(
|
||||
"🔄 ADMIN PIYASA SYNC | admin=%d target=%d",
|
||||
claims.ID,
|
||||
targetID,
|
||||
)
|
||||
|
||||
// --------------------------------------------------
|
||||
// ✅ OK
|
||||
// --------------------------------------------------
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
w.Write([]byte(`{"status":"ok"}`))
|
||||
}
|
||||
Reference in New Issue
Block a user