habulaj commited on
Commit
01810cf
·
verified ·
1 Parent(s): ada84bb

Update routes/dashboard_home.py

Browse files
Files changed (1) hide show
  1. routes/dashboard_home.py +21 -7
routes/dashboard_home.py CHANGED
@@ -213,17 +213,18 @@ def get_app_revenue_share(total_revenue: int, total_transferred: int) -> Dict[st
213
  }
214
 
215
  async def get_platform_users() -> Dict[str, Any]:
216
- """Obtém informações sobre usuários e estilistas da plataforma de forma assíncrona"""
217
  try:
218
  async with aiohttp.ClientSession() as session:
219
- # Executar ambas as chamadas em paralelo
220
  tasks = [
221
  session.get(f"{SUPABASE_URL}/rest/v1/User?select=id", headers=SUPABASE_HEADERS),
222
- session.get(f"{SUPABASE_URL}/rest/v1/User?role=eq.stylist&select=id", headers=SUPABASE_HEADERS)
 
223
  ]
224
 
225
  responses = await asyncio.gather(*tasks)
226
- users_response, stylists_response = responses
227
 
228
  total_users = 0
229
  if users_response.status == 200:
@@ -234,19 +235,32 @@ async def get_platform_users() -> Dict[str, Any]:
234
  if stylists_response.status == 200:
235
  stylists_data = await stylists_response.json()
236
  total_stylists = len(stylists_data)
 
 
 
 
 
 
 
 
237
 
238
- logger.info(f"Total de usuários: {total_users}, Total de estilistas: {total_stylists}")
 
239
 
240
  return {
241
  "total_users": total_users,
242
- "total_stylists": total_stylists
 
 
243
  }
244
 
245
  except Exception as e:
246
- logger.error(f"❌ Erro ao obter informações de usuários: {str(e)}")
247
  return {
248
  "total_users": 0,
249
  "total_stylists": 0,
 
 
250
  "error": str(e)
251
  }
252
 
 
213
  }
214
 
215
  async def get_platform_users() -> Dict[str, Any]:
216
+ """Obtém informações sobre usuários, estilistas e assinaturas da plataforma de forma assíncrona"""
217
  try:
218
  async with aiohttp.ClientSession() as session:
219
+ # Executar chamadas em paralelo para obter usuários, estilistas e assinaturas
220
  tasks = [
221
  session.get(f"{SUPABASE_URL}/rest/v1/User?select=id", headers=SUPABASE_HEADERS),
222
+ session.get(f"{SUPABASE_URL}/rest/v1/User?role=eq.stylist&select=id", headers=SUPABASE_HEADERS),
223
+ session.get(f"{SUPABASE_URL}/rest/v1/Subscriptions?select=id,active", headers=SUPABASE_HEADERS)
224
  ]
225
 
226
  responses = await asyncio.gather(*tasks)
227
+ users_response, stylists_response, subscriptions_response = responses
228
 
229
  total_users = 0
230
  if users_response.status == 200:
 
235
  if stylists_response.status == 200:
236
  stylists_data = await stylists_response.json()
237
  total_stylists = len(stylists_data)
238
+
239
+ # Processar dados de assinaturas
240
+ total_subscriptions = 0
241
+ active_subscriptions = 0
242
+ if subscriptions_response.status == 200:
243
+ subscriptions_data = await subscriptions_response.json()
244
+ total_subscriptions = len(subscriptions_data)
245
+ active_subscriptions = sum(1 for sub in subscriptions_data if sub.get("active", False))
246
 
247
+ logger.info(f"Total de usuários: {total_users}, Total de estilistas: {total_stylists}, "
248
+ f"Assinaturas ativas: {active_subscriptions}, Total de assinaturas: {total_subscriptions}")
249
 
250
  return {
251
  "total_users": total_users,
252
+ "total_stylists": total_stylists,
253
+ "active_subscriptions": active_subscriptions,
254
+ "total_subscriptions": total_subscriptions
255
  }
256
 
257
  except Exception as e:
258
+ logger.error(f"❌ Erro ao obter informações de usuários e assinaturas: {str(e)}")
259
  return {
260
  "total_users": 0,
261
  "total_stylists": 0,
262
+ "active_subscriptions": 0,
263
+ "total_subscriptions": 0,
264
  "error": str(e)
265
  }
266