@@ -48,27 +48,25 @@ async def _get_account_entity_by_email(self, email: str) -> AccountEntity:
4848 async def get_accounts (self ) -> list [Account ]:
4949 result = await self .session .execute (select (AccountEntity ))
5050 accounts = result .scalars ().all ()
51- return [Account . from_entity ( account ) for account in accounts ]
51+ return [account . to_model ( ) for account in accounts ]
5252
53- async def get_accounts_by_roles (
54- self , roles : list [AccountRole ] | None = None
55- ) -> list [Account ]:
53+ async def get_accounts_by_roles (self , roles : list [AccountRole ] | None = None ) -> list [Account ]:
5654 if not roles :
5755 return await self .get_accounts ()
5856
5957 result = await self .session .execute (
6058 select (AccountEntity ).where (AccountEntity .role .in_ (roles ))
6159 )
6260 accounts = result .scalars ().all ()
63- return [Account . from_entity ( account ) for account in accounts ]
61+ return [account . to_model ( ) for account in accounts ]
6462
6563 async def get_account_by_id (self , account_id : int ) -> Account :
6664 account_entity = await self ._get_account_entity_by_id (account_id )
67- return Account . from_entity ( account_entity )
65+ return account_entity . to_model ( )
6866
6967 async def get_account_by_email (self , email : str ) -> Account :
7068 account_entity = await self ._get_account_entity_by_email (email )
71- return Account . from_entity ( account_entity )
69+ return account_entity . to_model ( )
7270
7371 async def create_account (self , data : AccountData ) -> Account :
7472 try :
@@ -93,7 +91,7 @@ async def create_account(self, data: AccountData) -> Account:
9391 # handle race condition where another session inserted the same email
9492 raise AccountConflictException (data .email )
9593 await self .session .refresh (new_account )
96- return Account . from_entity ( new_account )
94+ return new_account . to_model ( )
9795
9896 async def update_account (self , account_id : int , data : AccountData ) -> Account :
9997 account_entity = await self ._get_account_entity_by_id (account_id )
@@ -120,11 +118,11 @@ async def update_account(self, account_id: int, data: AccountData) -> Account:
120118 except IntegrityError :
121119 raise AccountConflictException (data .email )
122120 await self .session .refresh (account_entity )
123- return Account . from_entity ( account_entity )
121+ return account_entity . to_model ( )
124122
125123 async def delete_account (self , account_id : int ) -> Account :
126124 account_entity = await self ._get_account_entity_by_id (account_id )
127- account = Account . from_entity ( account_entity )
125+ account = account_entity . to_model ( )
128126 await self .session .delete (account_entity )
129127 await self .session .commit ()
130- return account
128+ return account
0 commit comments