refactor: improve code structure and optimize key functions

This commit is contained in:
Cheng Zhou
2025-12-16 15:55:08 +08:00
commit 223d445a94
1290 changed files with 1361 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
from typing import Sequence
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.user import User
from app.schemas.user import UserCreate
async def get_by_username(db: AsyncSession, username: str) -> User | None:
result = await db.execute(select(User).where(User.username == username))
return result.scalar_one_or_none()
async def create(db: AsyncSession, user_in: UserCreate, hashed_password: str) -> User:
user = User(
username=user_in.username,
hashed_password=hashed_password,
role=user_in.role,
is_active=user_in.is_active,
)
db.add(user)
await db.commit()
await db.refresh(user)
return user
async def list_users(db: AsyncSession, limit: int = 100) -> Sequence[User]:
result = await db.execute(select(User).limit(limit))
return result.scalars().all()