From d77ab87719f164e863c6249ab88375f1993c7b2f Mon Sep 17 00:00:00 2001 From: mrtedn21 Date: Wed, 4 Oct 2023 16:43:55 +0700 Subject: [PATCH] refactor get users controller --- main.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 7e2494c..f568520 100644 --- a/main.py +++ b/main.py @@ -110,9 +110,9 @@ class Message(MessageSchema, metaclass=MarshmallowToDataclass): @register_route( '/users/', ('get', ), - response=user_get_schema, + response=user_list_get_schema, ) -async def get_users() -> list[User]: +async def get_users() -> str: async with db.create_session() as session: sql_query = ( select( @@ -121,11 +121,8 @@ async def get_users() -> list[User]: .outerjoin(CityOrm).outerjoin(CountryOrm) .outerjoin(LanguageOrm).outerjoin(GenderOrm) ) - result = await session.execute(sql_query) - users = result.fetchall() - schema = UserSchema(many=True) - return schema.dump(map(itemgetter(0), users)) + return user_list_get_schema.dumps(map(itemgetter(0), result.fetchall())) @register_route(