File tree 2 files changed +41
-0
lines changed
2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ # FILE: auth/group/list.py
2
+ from flask import Blueprint , request , jsonify
3
+ from firebase_admin import firestore
4
+
5
+ list_group_bp = Blueprint ('list_group' , __name__ )
6
+
7
+ db = firestore .client ()
8
+
9
+ @list_group_bp .route ('/auth/group/list' , methods = ['GET' ])
10
+ def list_groups ():
11
+ """
12
+ Route to retrieve the list of public groups. Optionally filter by user email if a 'user' query parameter is provided.
13
+ """
14
+ try :
15
+ # Get the optional 'user' query parameter
16
+ user_email = request .args .get ('user' )
17
+
18
+ # Query Firestore for public groups
19
+ groups_ref = db .collection ('groups' ).where ("privacy" , "==" , "public" )
20
+ public_groups = groups_ref .stream ()
21
+
22
+ groups_list = []
23
+ for group in public_groups :
24
+ group_data = group .to_dict ()
25
+ if user_email :
26
+ # If filtering by user email, only include groups where the user is a member
27
+ if user_email in group_data .get ('members' , []):
28
+ groups_list .append ({"id" : group .id , ** group_data })
29
+ else :
30
+ # Include all public groups if no user filter is applied
31
+ groups_list .append ({"id" : group .id , ** group_data })
32
+
33
+ return jsonify ({
34
+ "success" : True ,
35
+ "groups" : groups_list
36
+ }), 200
37
+
38
+ except Exception as e :
39
+ return jsonify ({"error" : str (e )}), 500
Original file line number Diff line number Diff line change 69
69
from auth .group .create import create_group_bp
70
70
from auth .group .delete import delete_group_bp
71
71
from auth .group .privacy import privacy_group_bp
72
+ from auth .group .list import list_group_bp
72
73
73
74
app .register_blueprint (signup_bp )
74
75
app .register_blueprint (login_bp )
75
76
app .register_blueprint (create_group_bp )
76
77
app .register_blueprint (delete_group_bp )
77
78
app .register_blueprint (privacy_group_bp )
79
+ app .register_blueprint (list_group_bp )
78
80
print ("Auth blueprints registered successfully." )
79
81
except ImportError as e :
80
82
print (f"Error importing blueprints: { e } " )
You can’t perform that action at this time.
0 commit comments