diff --git a/app/api.py b/app/api.py index dac1efb..7f591da 100644 --- a/app/api.py +++ b/app/api.py @@ -90,3 +90,20 @@ def post_label(req: LabelRequest): _write_jsonl(_queue_file(), [x for x in items if x["id"] != req.id]) _last_action = {"type": "label", "item": match, "label": req.label} return {"ok": True} + + +class SkipRequest(BaseModel): + id: str + + +@app.post("/api/skip") +def post_skip(req: SkipRequest): + global _last_action + items = _read_jsonl(_queue_file()) + match = next((x for x in items if x["id"] == req.id), None) + if not match: + raise HTTPException(404, f"Item {req.id!r} not found in queue") + reordered = [x for x in items if x["id"] != req.id] + [match] + _write_jsonl(_queue_file(), reordered) + _last_action = {"type": "skip", "item": match} + return {"ok": True} diff --git a/tests/test_api.py b/tests/test_api.py index ad6275a..ebfb59d 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -73,3 +73,15 @@ def test_label_removes_from_queue(client, queue_with_items): def test_label_unknown_id_returns_404(client, queue_with_items): r = client.post("/api/label", json={"id": "unknown", "label": "neutral"}) assert r.status_code == 404 + +def test_skip_moves_to_back(client, queue_with_items): + from app import api as api_module + r = client.post("/api/skip", json={"id": "id0"}) + assert r.status_code == 200 + queue = api_module._read_jsonl(api_module._queue_file()) + assert queue[-1]["id"] == "id0" + assert queue[0]["id"] == "id1" + +def test_skip_unknown_id_returns_404(client, queue_with_items): + r = client.post("/api/skip", json={"id": "nope"}) + assert r.status_code == 404