add admin user management: list and delete registered users
This commit is contained in:
@@ -805,6 +805,25 @@ class VideoRepository:
|
||||
).fetchone()
|
||||
return dict(row) if row else None
|
||||
|
||||
def list_users(self) -> List[Dict[str, Any]]:
|
||||
with self._connect() as connection:
|
||||
rows = connection.execute(
|
||||
"""
|
||||
SELECT u.id, u.username, u.nickname, u.phone, u.created_at,
|
||||
COUNT(DISTINCT e.video_hash) AS enrollment_count
|
||||
FROM users u
|
||||
LEFT JOIN enrollments e ON e.user_id = u.id
|
||||
GROUP BY u.id
|
||||
ORDER BY u.created_at DESC
|
||||
"""
|
||||
).fetchall()
|
||||
return [dict(row) for row in rows]
|
||||
|
||||
def delete_user(self, user_id: str) -> bool:
|
||||
with self._connect() as connection:
|
||||
cursor = connection.execute("DELETE FROM users WHERE id = ?", (user_id,))
|
||||
return cursor.rowcount > 0
|
||||
|
||||
def authenticate_user(self, username: str, password: str) -> Optional[Dict[str, Any]]:
|
||||
with self._connect() as connection:
|
||||
row = connection.execute(
|
||||
|
||||
Reference in New Issue
Block a user