|
|
|
@ -59,12 +59,14 @@ async def get_db():
|
|
|
|
|
async with app.state.pool.acquire() as connection:
|
|
|
|
|
yield connection
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 初始化 OpenAI 客户端
|
|
|
|
|
client = AsyncOpenAI(
|
|
|
|
|
api_key=MODEL_API_KEY,
|
|
|
|
|
base_url=MODEL_API_URL,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/questions/get_excel")
|
|
|
|
|
async def get_excel(question_id: str = Form(...), question_str: str = Form(...),
|
|
|
|
|
db: asyncpg.Connection = Depends(get_db)):
|
|
|
|
@ -261,19 +263,58 @@ async def set_user_collect(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/questions/get_system_recommend")
|
|
|
|
|
async def get_system_recommend(db: asyncpg.Connection = Depends(get_db)): # 添加 db 参数
|
|
|
|
|
# 查询所有系统推荐问题
|
|
|
|
|
system_recommend_questions = await get_system_recommend_questions(db)
|
|
|
|
|
async def get_system_recommend(
|
|
|
|
|
db: asyncpg.Connection = Depends(get_db), # 数据库连接
|
|
|
|
|
page: int = Query(1, description="当前页码,默认为 1"), # 页码参数
|
|
|
|
|
page_size: int = Query(10, description="每页数据量,默认为 10") # 每页数据量参数
|
|
|
|
|
):
|
|
|
|
|
# 计算 OFFSET
|
|
|
|
|
offset = (page - 1) * page_size
|
|
|
|
|
|
|
|
|
|
# 查询分页后的系统推荐问题
|
|
|
|
|
system_recommend_questions = await get_system_recommend_questions(db, offset, page_size)
|
|
|
|
|
|
|
|
|
|
# 查询总数据量
|
|
|
|
|
total = await get_system_recommend_questions_count(db)
|
|
|
|
|
|
|
|
|
|
# 返回查询结果
|
|
|
|
|
return {"success": True, "data": system_recommend_questions}
|
|
|
|
|
return {
|
|
|
|
|
"success": True,
|
|
|
|
|
"data": system_recommend_questions,
|
|
|
|
|
"pagination": {
|
|
|
|
|
"page": page,
|
|
|
|
|
"page_size": page_size,
|
|
|
|
|
"total": total # 总数据量
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/questions/get_user_questions")
|
|
|
|
|
async def get_user_questions(
|
|
|
|
|
db: asyncpg.Connection = Depends(get_db), # 数据库连接
|
|
|
|
|
page: int = Query(1, description="当前页码,默认为 1"), # 页码参数
|
|
|
|
|
page_size: int = Query(10, description="每页数据量,默认为 10"), # 每页数据量参数
|
|
|
|
|
type_id: int = Query(1, description="1:用户收藏的问题,0:全部")
|
|
|
|
|
):
|
|
|
|
|
# 计算 OFFSET
|
|
|
|
|
offset = (page - 1) * page_size
|
|
|
|
|
|
|
|
|
|
# 查询分页后的用户收藏问题
|
|
|
|
|
user_questions = await get_user_publish_questions(db, type_id, offset, page_size)
|
|
|
|
|
|
|
|
|
|
# 查询总数据量
|
|
|
|
|
total = await get_user_publish_questions_count(db)
|
|
|
|
|
|
|
|
|
|
@app.get("/questions/get_user_collect")
|
|
|
|
|
async def get_user_collect(db: asyncpg.Connection = Depends(get_db)): # 添加 db 参数
|
|
|
|
|
# 查询所有用户收藏问题
|
|
|
|
|
user_collect_questions = await get_user_collect_questions(db)
|
|
|
|
|
# 返回查询结果
|
|
|
|
|
return {"success": True, "data": user_collect_questions}
|
|
|
|
|
return {
|
|
|
|
|
"success": True,
|
|
|
|
|
"data": user_questions,
|
|
|
|
|
"pagination": {
|
|
|
|
|
"page": page,
|
|
|
|
|
"page_size": page_size,
|
|
|
|
|
"total": total # 总数据量
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 获取数据库字段名
|
|
|
|
|