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
|
|
@ -267,11 +267,8 @@ class ExchangeService:
|
|||
status=ExchangeStatus.BOOKED,
|
||||
)
|
||||
|
||||
self.db.add(exchange)
|
||||
|
||||
try:
|
||||
await self.db.commit()
|
||||
await self.db.refresh(exchange)
|
||||
return await self.exchange_repo.create(exchange)
|
||||
except IntegrityError as e:
|
||||
await self.db.rollback()
|
||||
# This should rarely happen now since we check explicitly above,
|
||||
|
|
@ -280,8 +277,6 @@ class ExchangeService:
|
|||
"Database constraint violation. Please try again."
|
||||
) from e
|
||||
|
||||
return exchange
|
||||
|
||||
async def get_exchange_by_public_id(
|
||||
self, public_id: uuid.UUID, user: User | None = None
|
||||
) -> Exchange:
|
||||
|
|
@ -331,10 +326,7 @@ class ExchangeService:
|
|||
)
|
||||
exchange.cancelled_at = datetime.now(UTC)
|
||||
|
||||
await self.db.commit()
|
||||
await self.db.refresh(exchange)
|
||||
|
||||
return exchange
|
||||
return await self.exchange_repo.update(exchange)
|
||||
|
||||
async def complete_exchange(self, exchange: Exchange) -> Exchange:
|
||||
"""
|
||||
|
|
@ -354,10 +346,7 @@ class ExchangeService:
|
|||
exchange.status = ExchangeStatus.COMPLETED
|
||||
exchange.completed_at = datetime.now(UTC)
|
||||
|
||||
await self.db.commit()
|
||||
await self.db.refresh(exchange)
|
||||
|
||||
return exchange
|
||||
return await self.exchange_repo.update(exchange)
|
||||
|
||||
async def mark_no_show(self, exchange: Exchange) -> Exchange:
|
||||
"""
|
||||
|
|
@ -379,10 +368,7 @@ class ExchangeService:
|
|||
exchange.status = ExchangeStatus.NO_SHOW
|
||||
exchange.completed_at = datetime.now(UTC)
|
||||
|
||||
await self.db.commit()
|
||||
await self.db.refresh(exchange)
|
||||
|
||||
return exchange
|
||||
return await self.exchange_repo.update(exchange)
|
||||
|
||||
def _expand_availability_to_slots(
|
||||
self, avail: Availability, slot_date: date, booked_starts: set[datetime]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue