refactors
This commit is contained in:
parent
139a5fbef3
commit
f46d2ae8b3
12 changed files with 734 additions and 536 deletions
23
backend/repositories/user.py
Normal file
23
backend/repositories/user.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
"""User repository for database queries."""
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from models import User
|
||||
|
||||
|
||||
class UserRepository:
|
||||
"""Repository for user-related database queries."""
|
||||
|
||||
def __init__(self, db: AsyncSession):
|
||||
self.db = db
|
||||
|
||||
async def get_by_email(self, email: str) -> User | None:
|
||||
"""Get a user by email."""
|
||||
result = await self.db.execute(select(User).where(User.email == email))
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
async def get_by_id(self, user_id: int) -> User | None:
|
||||
"""Get a user by ID."""
|
||||
result = await self.db.execute(select(User).where(User.id == user_id))
|
||||
return result.scalar_one_or_none()
|
||||
Loading…
Add table
Add a link
Reference in a new issue