service_man/api/repositories/user.py

34 lines
938 B
Python

from sqlalchemy import insert, select
from sqlalchemy.ext.asyncio.session import AsyncSession
from api.models import UserModel
from api.schemas.user_schema import UserReadDTO, UserWriteDTO
class UserRepository:
def __init__(self, session: AsyncSession):
self.session = session
async def add_one(
self,
data: UserWriteDTO,
):
stmt = insert(UserModel).values(**data.model_dump())
res = await self.session.execute(stmt)
return UserReadDTO.model_validate(res.scalar_one())
async def find_all(self):
stmt = select(UserModel)
res = await self.session.execute(stmt)
res = [UserReadDTO.model_validate(row) for row in res.scalars().all()]
return res
async def find_one(self, filter: dict):
return
async def update_one(self, filter: dict, data: dict):
return
async def delete_one(self, filter: dict):
return