Delegate exchange persistence to ExchangeRepository
- Add create() and update() methods to ExchangeRepository - Update ExchangeService to use repository methods instead of direct db operations - All persistence operations now go through repositories consistently - Fix indentation errors in ExchangeService
This commit is contained in:
parent
c4594a3f73
commit
33aa8ad13b
2 changed files with 33 additions and 18 deletions
|
|
@ -161,3 +161,32 @@ class ExchangeRepository:
|
|||
)
|
||||
)
|
||||
return {row[0] for row in result.all()}
|
||||
|
||||
async def create(self, exchange: Exchange) -> Exchange:
|
||||
"""
|
||||
Create a new exchange record.
|
||||
|
||||
Args:
|
||||
exchange: Exchange instance to persist
|
||||
|
||||
Returns:
|
||||
Created Exchange record (committed and refreshed)
|
||||
"""
|
||||
self.db.add(exchange)
|
||||
await self.db.commit()
|
||||
await self.db.refresh(exchange)
|
||||
return exchange
|
||||
|
||||
async def update(self, exchange: Exchange) -> Exchange:
|
||||
"""
|
||||
Update an existing exchange record.
|
||||
|
||||
Args:
|
||||
exchange: Exchange instance to update
|
||||
|
||||
Returns:
|
||||
Updated Exchange record (committed and refreshed)
|
||||
"""
|
||||
await self.db.commit()
|
||||
await self.db.refresh(exchange)
|
||||
return exchange
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue