fix: sửa lỗi Ai prompt multi

This commit is contained in:
2026-07-22 18:37:52 +07:00
parent ec178b42f3
commit 6f0fac9f2d
3 changed files with 62 additions and 4 deletions
+53
View File
@@ -126,3 +126,56 @@ async def list_cloud_projects(current_user: dict = Depends(get_current_user)):
"updated_at": r["updated_at"]
} for r in rows
]
@router.get("/cloud/{project_id}")
async def get_cloud_project(project_id: str, current_user: dict = Depends(get_current_user)):
user_id = current_user["user_id"]
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute("SELECT name, data_json FROM projects WHERE id = ? AND user_id = ? AND is_temp = 0", (project_id, user_id))
row = cursor.fetchone()
conn.close()
if not row:
raise HTTPException(status_code=404, detail="Không tìm thấy dự án")
return {
"id": project_id,
"name": row["name"],
"data_json": row["data_json"]
}
@router.delete("/cloud/{project_id}")
async def delete_cloud_project(project_id: str, current_user: dict = Depends(get_current_user)):
user_id = current_user["user_id"]
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute("DELETE FROM projects WHERE id = ? AND user_id = ? AND is_temp = 0", (project_id, user_id))
conn.commit()
conn.close()
return {"success": True, "message": "Đã xóa dự án thành công"}
@router.put("/cloud/{project_id}")
async def update_cloud_project(project_id: str, req: SaveProjectRequest, current_user: dict = Depends(get_current_user)):
user_id = current_user["user_id"]
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute("SELECT id FROM projects WHERE id = ? AND user_id = ? AND is_temp = 0", (project_id, user_id))
exists = cursor.fetchone()
if not exists:
conn.close()
raise HTTPException(status_code=404, detail="Không tìm thấy dự án để cập nhật")
new_size_bytes = len(req.data_json.encode("utf-8"))
now = time.time()
cursor.execute("""
UPDATE projects
SET name = ?, data_json = ?, size_bytes = ?, updated_at = ?
WHERE id = ? AND user_id = ?
""", (req.name, req.data_json, new_size_bytes, now, project_id, user_id))
conn.commit()
conn.close()
return {"success": True, "message": "Đã cập nhật dự án thành công"}