Update routes/stylist.py
Browse files- routes/stylist.py +19 -1
routes/stylist.py
CHANGED
@@ -143,6 +143,22 @@ def get_active_subscribers(user_id: str, page: int) -> Dict[str, Any]:
|
|
143 |
|
144 |
return {"subscribers": [], "has_next_page": False}
|
145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
@router.get("/dashboard")
|
147 |
def get_dashboard(user_token: str = Header(None, alias="User-key"), page: int = Query(0, ge=0)):
|
148 |
try:
|
@@ -156,8 +172,10 @@ def get_dashboard(user_token: str = Header(None, alias="User-key"), page: int =
|
|
156 |
"stripe_id": stripe_id,
|
157 |
"available_balance": get_account_balance(stripe_id),
|
158 |
"monthly_revenue": get_monthly_revenue(stripe_id),
|
|
|
|
|
159 |
**get_active_subscribers(user_id, page)
|
160 |
}
|
161 |
except Exception as e:
|
162 |
logger.error(f"❌ Error: {str(e)}")
|
163 |
-
raise HTTPException(status_code=500, detail=str(e))
|
|
|
143 |
|
144 |
return {"subscribers": [], "has_next_page": False}
|
145 |
|
146 |
+
def get_total_followers(user_id: str) -> int:
|
147 |
+
url = f"{SUPABASE_URL}/rest/v1/followers?following_id=eq.{user_id}"
|
148 |
+
response = requests.get(url, headers=SUPABASE_HEADERS)
|
149 |
+
if response.status_code == 200:
|
150 |
+
followers = response.json()
|
151 |
+
return len(followers)
|
152 |
+
return 0
|
153 |
+
|
154 |
+
def get_total_subscribers(user_id: str) -> int:
|
155 |
+
url = f"{SUPABASE_URL}/rest/v1/Subscriptions?stylist_id=eq.{user_id}&active=eq.true"
|
156 |
+
response = requests.get(url, headers=SUPABASE_HEADERS)
|
157 |
+
if response.status_code == 200:
|
158 |
+
subscribers = response.json()
|
159 |
+
return len(subscribers)
|
160 |
+
return 0
|
161 |
+
|
162 |
@router.get("/dashboard")
|
163 |
def get_dashboard(user_token: str = Header(None, alias="User-key"), page: int = Query(0, ge=0)):
|
164 |
try:
|
|
|
172 |
"stripe_id": stripe_id,
|
173 |
"available_balance": get_account_balance(stripe_id),
|
174 |
"monthly_revenue": get_monthly_revenue(stripe_id),
|
175 |
+
"total_followers": get_total_followers(user_id),
|
176 |
+
"total_subscribers": get_total_subscribers(user_id),
|
177 |
**get_active_subscribers(user_id, page)
|
178 |
}
|
179 |
except Exception as e:
|
180 |
logger.error(f"❌ Error: {str(e)}")
|
181 |
+
raise HTTPException(status_code=500, detail=str(e))
|