feat: 初始化考培练系统项目
- 从服务器拉取完整代码 - 按框架规范整理项目结构 - 配置 Drone CI 测试环境部署 - 包含后端(FastAPI)、前端(Vue3)、管理端 技术栈: Vue3 + TypeScript + FastAPI + MySQL
This commit is contained in:
64
backend/test_api_endpoint.py
Normal file
64
backend/test_api_endpoint.py
Normal file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
创建一个测试端点来调试
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# 添加项目根目录到 Python 路径
|
||||
project_root = Path(__file__).parent
|
||||
sys.path.append(str(project_root))
|
||||
|
||||
import uvicorn
|
||||
from fastapi import FastAPI
|
||||
from app.api.v1 import api_router
|
||||
|
||||
# 创建应用
|
||||
app = FastAPI(title="调试API")
|
||||
|
||||
# 包含现有路由
|
||||
app.include_router(api_router, prefix="/api/v1")
|
||||
|
||||
# 添加测试路由
|
||||
from fastapi import Depends
|
||||
from app.core.deps import get_current_user
|
||||
from app.schemas.user import User as UserSchema
|
||||
from app.schemas.base import ResponseModel
|
||||
|
||||
@app.get("/debug/user/raw")
|
||||
async def debug_user_raw(current_user = Depends(get_current_user)):
|
||||
"""直接返回用户对象的dict"""
|
||||
return {
|
||||
"id": current_user.id,
|
||||
"username": current_user.username,
|
||||
"email": current_user.email,
|
||||
"phone": current_user.phone,
|
||||
"school": current_user.school,
|
||||
"major": current_user.major,
|
||||
"full_name": current_user.full_name,
|
||||
"bio": current_user.bio,
|
||||
"gender": current_user.gender,
|
||||
"role": current_user.role
|
||||
}
|
||||
|
||||
@app.get("/debug/user/schema")
|
||||
async def debug_user_schema(current_user = Depends(get_current_user)):
|
||||
"""使用UserSchema序列化"""
|
||||
return UserSchema.model_validate(current_user)
|
||||
|
||||
@app.get("/debug/user/response")
|
||||
async def debug_user_response(current_user = Depends(get_current_user)):
|
||||
"""使用ResponseModel包装"""
|
||||
return ResponseModel(data=UserSchema.model_validate(current_user))
|
||||
|
||||
@app.get("/debug/user/dict")
|
||||
async def debug_user_dict(current_user = Depends(get_current_user)):
|
||||
"""返回model_dump结果"""
|
||||
user_schema = UserSchema.model_validate(current_user)
|
||||
return user_schema.model_dump()
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("启动调试API服务器...")
|
||||
uvicorn.run(app, host="0.0.0.0", port=8001)
|
||||
Reference in New Issue
Block a user