초기 커밋

This commit is contained in:
2026-03-01 07:44:19 +09:00
commit 09359f30be
146 changed files with 6120 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
from __future__ import annotations
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload
from app.models.mariadb.user import User, UserProfile
from app.repositories.base import BaseRepository
class UserRepository(BaseRepository[User]):
def __init__(self, session: AsyncSession):
super().__init__(User, session)
async def get_by_email(self, email: str) -> User | None:
stmt = select(User).where(User.email == email)
result = await self.session.execute(stmt)
return result.scalar_one_or_none()
async def get_with_profile(self, user_id: int) -> User | None:
stmt = (
select(User)
.options(selectinload(User.profile))
.where(User.id == user_id)
)
result = await self.session.execute(stmt)
return result.scalar_one_or_none()
async def create_with_profile(
self, user: User, full_name: str = "", phone: str = "", organization: str = ""
) -> User:
self.session.add(user)
await self.session.flush()
profile = UserProfile(
user_id=user.id, # type: ignore[arg-type]
full_name=full_name,
phone=phone,
organization=organization,
)
self.session.add(profile)
await self.session.flush()
await self.session.refresh(user)
return user