feat(server): GET /api/sessions 支持 project 查询参数
This commit is contained in:
@@ -154,11 +154,11 @@ def create_app(
|
||||
return {"session_id": rec.session_id, "status": rec.status, "name": rec.name}
|
||||
|
||||
@app.get("/api/sessions")
|
||||
def list_sessions(user_id: str = "default"):
|
||||
def list_sessions(user_id: str = "default", project: str | None = None):
|
||||
return [
|
||||
{"session_id": r.session_id, "name": r.name, "project": r.project,
|
||||
"status": r.status, "updated_at": r.updated_at}
|
||||
for r in service.store.list_sessions(user_id)
|
||||
for r in service.store.list_sessions(user_id, project=project)
|
||||
]
|
||||
|
||||
@app.get("/api/sessions/{sid}")
|
||||
|
||||
@@ -347,3 +347,12 @@ def test_generate_with_project_config_no_template_upload(client):
|
||||
gen = client.post(f"/api/sessions/{sid}/generate", json={})
|
||||
assert gen.status_code == 200, gen.text
|
||||
assert client.get(f"/api/sessions/{sid}/result/download").status_code == 200
|
||||
|
||||
def test_api_list_sessions_filter_by_project(client):
|
||||
r0 = client.post("/api/sessions", json={"user_id": "u1", "project": "stock"})
|
||||
r1 = client.post("/api/sessions", json={"user_id": "u1", "project": "other"})
|
||||
res = client.get("/api/sessions", params={"user_id": "u1", "project": "stock"})
|
||||
assert res.status_code == 200
|
||||
ids = {x["session_id"] for x in res.json()}
|
||||
assert r0.json()["session_id"] in ids
|
||||
assert r1.json()["session_id"] not in ids
|
||||
|
||||
Reference in New Issue
Block a user