Delegate invite persistence to InviteRepository

- Add create(), update(), and reload_with_relationships() methods to InviteRepository
- Update InviteService to use repository methods instead of direct db operations
This commit is contained in:
counterweight 2025-12-25 18:52:52 +01:00
parent 04333d210b
commit c4594a3f73
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
2 changed files with 49 additions and 16 deletions

View file

@ -147,20 +147,10 @@ class InviteService:
godfather_id=godfather_id,
status=InviteStatus.READY,
)
self.db.add(invite)
try:
await self.db.commit()
await self.db.refresh(invite)
invite = await self.invite_repo.create(invite)
# Reload with relationships
from sqlalchemy import select
from sqlalchemy.orm import joinedload
result = await self.db.execute(
select(Invite)
.options(joinedload(Invite.godfather), joinedload(Invite.used_by))
.where(Invite.id == invite.id)
)
invite = result.scalar_one()
invite = await self.invite_repo.reload_with_relationships(invite.id)
break
except IntegrityError:
await self.db.rollback()
@ -200,7 +190,4 @@ class InviteService:
invite.status = InviteStatus.REVOKED
invite.revoked_at = datetime.now(UTC)
await self.db.commit()
await self.db.refresh(invite)
return invite
return await self.invite_repo.update(invite)