From 7c0ee01c1d134cbee0a2c8243dd55e4eeaaa5f7c Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 30 May 2024 12:03:38 -0500 Subject: Move user creation from db resultset into static method Creation of a User object from the database resultset will mostly be the same. This commit moves the repetitive code into a static method that can be called wherever we need it. This improves maintainability, since we only ever need to do an update in one place now. --- gn_auth/auth/authorisation/users/models.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'gn_auth/auth/authorisation/users/models.py') diff --git a/gn_auth/auth/authorisation/users/models.py b/gn_auth/auth/authorisation/users/models.py index 8b47fc1..bde2e33 100644 --- a/gn_auth/auth/authorisation/users/models.py +++ b/gn_auth/auth/authorisation/users/models.py @@ -17,9 +17,7 @@ def list_users(conn: db.DbConnection) -> tuple[User, ...]: """List out all users.""" with db.cursor(conn) as cursor: cursor.execute("SELECT * FROM users") - return tuple( - User(uuid.UUID(row["user_id"]), row["email"], row["name"]) - for row in cursor.fetchall()) + return tuple(User.from_sqlite3_row(row) for row in cursor.fetchall()) def __build_resource_roles__(rows): def __build_roles__(roles, row): -- cgit v1.2.3