sipi-web/sipi-app/api/api_v1/crud/users.py

21 lines
543 B
Python
Raw Normal View History

2024-07-12 11:44:02 +00:00
from typing import Sequence
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from core.models import User
from core.schemas.user import UserCreate
async def get_all_users(session: AsyncSession) -> Sequence[User]:
stmt = select(User).order_by(User.id)
result = await session.scalars(stmt)
return result.all()
async def create_user(session: AsyncSession, user_create: UserCreate) -> User:
user = User(**user_create.model_dump())
session.add(user)
await session.commit()
return user