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:
counterweight 2025-12-25 18:54:29 +01:00
parent c4594a3f73
commit 33aa8ad13b
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
2 changed files with 33 additions and 18 deletions

View file

@ -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