Skip to content

Commit f0d7552

Browse files
committed
Harmonize added/removed/deleted fields to count
1 parent ad9b3b7 commit f0d7552

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/paperoni/web/restapi.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class PaperIncludeResponse:
259259

260260
success: bool
261261
message: str
262-
added: int = 0
262+
count: int = 0
263263
ids: list[int | str] = field(default_factory=list)
264264

265265

@@ -276,7 +276,7 @@ class DeletePapersResponse:
276276

277277
success: bool
278278
message: str
279-
deleted: int
279+
count: int
280280

281281

282282
@dataclass
@@ -320,7 +320,7 @@ class AddExclusionsResponse:
320320

321321
success: bool
322322
message: str
323-
added: int
323+
count: int
324324

325325

326326
@dataclass
@@ -336,7 +336,7 @@ class RemoveExclusionsResponse:
336336

337337
success: bool
338338
message: str
339-
removed: int
339+
count: int
340340

341341

342342
def install_api(app) -> FastAPI:
@@ -481,14 +481,14 @@ async def include_papers(request: PaperIncludeRequest):
481481
return PaperIncludeResponse(
482482
success=True,
483483
message=f"Processed {len(added_ids)} paper(s)",
484-
added=len(added_ids),
484+
count=len(added_ids),
485485
ids=added_ids,
486486
)
487487
except Exception as e:
488488
return PaperIncludeResponse(
489489
success=False,
490490
message=f"Error processing papers: {str(e)}",
491-
added=0,
491+
count=0,
492492
)
493493

494494
@app.post(
@@ -503,7 +503,7 @@ async def delete_papers(request: DeletePapersRequest):
503503
return DeletePapersResponse(
504504
success=True,
505505
message=f"Deleted {deleted} paper(s)",
506-
deleted=deleted,
506+
count=deleted,
507507
)
508508

509509
@app.get(
@@ -588,7 +588,7 @@ async def add_exclusions(request: AddExclusionsRequest):
588588
return AddExclusionsResponse(
589589
success=True,
590590
message=f"Added {added} exclusion(s)",
591-
added=added,
591+
count=added,
592592
)
593593

594594
@app.delete(
@@ -604,7 +604,7 @@ async def remove_exclusions(request: RemoveExclusionsRequest):
604604
return RemoveExclusionsResponse(
605605
success=True,
606606
message=f"Removed {removed} exclusion(s)",
607-
removed=removed,
607+
count=removed,
608608
)
609609

610610
return app

tests/web/test_restapi.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def test_include_papers_endpoint(wr_app, edited_paper):
223223
assert "Watermelon" not in modified["title"]
224224
assert "Cantaloupe" in modified["title"]
225225
assert len(modified["authors"]) == 1
226-
assert response.json()["added"] == 1
226+
assert response.json()["count"] == 1
227227
assert response.json()["ids"] == [3]
228228

229229

@@ -240,7 +240,7 @@ def test_include_papers_endpoint_not_found(wr_app, edited_paper):
240240
data = response.json()
241241
assert data["success"] is False
242242
assert "Paper with ID 999 not found" in data["message"]
243-
assert data["added"] == 0
243+
assert data["count"] == 0
244244

245245

246246
def test_include_papers_endpoint_no_id(wr_app, edited_paper):
@@ -256,7 +256,7 @@ def test_include_papers_endpoint_no_id(wr_app, edited_paper):
256256
assert response.status_code == 200
257257
data = response.json()
258258
assert data["success"] is True
259-
assert data["added"] == 1
259+
assert data["count"] == 1
260260
assert len(data["ids"]) == 1
261261
assert isinstance(data["ids"][0], int)
262262

@@ -296,7 +296,7 @@ def test_delete_papers_endpoint(wr_app):
296296
assert response.status_code == 200
297297
data = response.json()
298298
assert data["success"] is True
299-
assert data["deleted"] == 1
299+
assert data["count"] == 1
300300

301301
# Paper 3 should be gone
302302
assert admin.get("/api/v1/paper/3", expect=404).status_code == 404
@@ -305,4 +305,4 @@ def test_delete_papers_endpoint(wr_app):
305305
response = admin.post("/api/v1/delete", ids=[999])
306306
assert response.status_code == 200
307307
data = response.json()
308-
assert data["deleted"] == 0
308+
assert data["count"] == 0

0 commit comments

Comments
 (0)