feat: 完善后端 API OpenAPI 文档与统一错误响应 schema

This commit is contained in:
caoxiaozhu
2026-05-11 05:18:16 +00:00
parent b2beeaa136
commit 321dd6fdaf
20 changed files with 7359 additions and 225 deletions

View File

@@ -7,13 +7,25 @@ from sqlalchemy.orm import Session
from app.api.deps import get_db
from app.schemas.auth import LoginRequest, LoginResponse
from app.schemas.common import ErrorResponse
from app.services.auth import AuthService
router = APIRouter(prefix="/auth")
DbSession = Annotated[Session, Depends(get_db)]
@router.post("/login", response_model=LoginResponse)
@router.post(
"/login",
response_model=LoginResponse,
summary="用户登录",
description="支持管理员账号和员工账号登录,成功后返回前端会话所需的用户信息。",
responses={
status.HTTP_401_UNAUTHORIZED: {
"model": ErrorResponse,
"description": "账号或密码错误。",
}
},
)
def login(payload: LoginRequest, db: DbSession) -> LoginResponse:
try:
return AuthService(db).login(payload)