@@ -199,6 +199,51 @@ async def is_user_in_product(
199199 )
200200
201201
202+ async def list_users_as_admin (
203+ app : web .Application ,
204+ * ,
205+ filter_approved : bool | None = None ,
206+ limit : int = 50 ,
207+ offset : int = 0 ,
208+ ) -> tuple [list [dict [str , Any ]], int ]:
209+ """
210+ Get a paginated list of users for admin view with filtering options.
211+
212+ Args:
213+ app: The web application instance
214+ filter_approved: If set, filters users by their approval status
215+ limit: Maximum number of users to return
216+ offset: Number of users to skip for pagination
217+
218+ Returns:
219+ A tuple containing (list of user dictionaries, total count of users)
220+ """
221+ engine = get_asyncpg_engine (app )
222+
223+ # Get user data with pagination
224+ users_data , total_count = await _users_repository .list_users_for_admin (
225+ engine = engine , filter_approved = filter_approved , limit = limit , offset = offset
226+ )
227+
228+ # For each user, append additional information if needed
229+ result = []
230+ for user in users_data :
231+ # Add any additional processing needed for admin view
232+ user_dict = dict (user )
233+
234+ # Add products information if needed
235+ user_id = user .get ("user_id" )
236+ if user_id :
237+ products = await _users_repository .get_user_products (
238+ engine , user_id = user_id
239+ )
240+ user_dict ["products" ] = [p .product_name for p in products ]
241+
242+ result .append (user_dict )
243+
244+ return result , total_count
245+
246+
202247#
203248# GET USER PROPERTIES
204249#
0 commit comments