Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -1401,16 +1401,21 @@ def admin_list_stories():
|
|
| 1401 |
all_stories = stories_ref.get() or {}
|
| 1402 |
total_stories = len(all_stories)
|
| 1403 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1404 |
# If you want to see how many stories each user has, do:
|
| 1405 |
stories_per_user = {}
|
| 1406 |
for sid, sdata in all_stories.items():
|
| 1407 |
-
user_id = sdata.get('
|
| 1408 |
if user_id:
|
| 1409 |
-
|
|
|
|
| 1410 |
|
| 1411 |
return jsonify({
|
| 1412 |
'total_stories': total_stories,
|
| 1413 |
-
'stories_per_user': stories_per_user
|
| 1414 |
}), 200
|
| 1415 |
except Exception as e:
|
| 1416 |
return jsonify({'error': str(e)}), 500
|
|
|
|
| 1401 |
all_stories = stories_ref.get() or {}
|
| 1402 |
total_stories = len(all_stories)
|
| 1403 |
|
| 1404 |
+
# Fetch all users' data to map UIDs to emails
|
| 1405 |
+
users_ref = db.reference('users')
|
| 1406 |
+
users_data = users_ref.get() or {}
|
| 1407 |
+
|
| 1408 |
# If you want to see how many stories each user has, do:
|
| 1409 |
stories_per_user = {}
|
| 1410 |
for sid, sdata in all_stories.items():
|
| 1411 |
+
user_id = sdata.get('uid')
|
| 1412 |
if user_id:
|
| 1413 |
+
user_email = users_data.get(user_id, {}).get('email', 'Unknown')
|
| 1414 |
+
stories_per_user[user_email] = stories_per_user.get(user_email, 0) + 1
|
| 1415 |
|
| 1416 |
return jsonify({
|
| 1417 |
'total_stories': total_stories,
|
| 1418 |
+
'stories_per_user': stories_per_user # Now contains emails instead of UIDs
|
| 1419 |
}), 200
|
| 1420 |
except Exception as e:
|
| 1421 |
return jsonify({'error': str(e)}), 500
|