Fix review queue pagination and API fallback handling
This commit is contained in:
@@ -367,13 +367,15 @@ def _external_out(item: ExternalObservation) -> ExternalObservationOut:
|
||||
@app.get("/api/v1/admin/external-observations", response_model=list[ExternalObservationOut])
|
||||
def admin_external_observations(
|
||||
db: Db, _: Annotated[str, Depends(_admin)],
|
||||
status: Literal["staged", "mapped", "ready", "published", "rejected"] | None = None,
|
||||
status: Literal["staged", "mapped", "ready", "published", "rejected", "review"] | None = None,
|
||||
source_system: str | None = None, limit: int = Query(50, ge=1, le=200), offset: int = Query(0, ge=0),
|
||||
) -> list[ExternalObservationOut]:
|
||||
query = select(ExternalObservation).options(
|
||||
joinedload(ExternalObservation.fish), joinedload(ExternalObservation.waterbody),
|
||||
)
|
||||
if status:
|
||||
if status == "review":
|
||||
query = query.where(ExternalObservation.status.in_(["staged", "mapped", "ready"]))
|
||||
elif status:
|
||||
query = query.where(ExternalObservation.status == status)
|
||||
if source_system:
|
||||
query = query.where(ExternalObservation.source_system == source_system)
|
||||
|
||||
@@ -57,6 +57,32 @@ def test_invalid_period_is_rejected() -> None:
|
||||
assert client.get("/api/v1/activity?sort=unknown").status_code == 422
|
||||
|
||||
|
||||
def test_review_queue_filters_before_pagination() -> None:
|
||||
with Session(engine) as db:
|
||||
stage_observations(db, [{
|
||||
"source_system": "rf4map", "source_external_id": f"queue-{i}",
|
||||
"source_url": f"https://rf4map.ru/points/queue-{i}",
|
||||
"fish": "Queue fish", "waterbody": "Queue water",
|
||||
} for i in range(3)])
|
||||
rows = list(db.scalars(select(ExternalObservation).where(ExternalObservation.source_system == "rf4map")))
|
||||
for i, row in enumerate(rows):
|
||||
row.status = "published" if i == 0 else "ready"
|
||||
row.last_seen_at = datetime.now(timezone.utc) - timedelta(minutes=i)
|
||||
db.commit()
|
||||
try:
|
||||
headers = {"Authorization": "Bearer change-me-in-production"}
|
||||
url = "/api/v1/admin/external-observations?status=review&source_system=rf4map&limit=1"
|
||||
first = client.get(url, headers=headers).json()
|
||||
second = client.get(url + "&offset=1", headers=headers).json()
|
||||
assert len(first) == len(second) == 1
|
||||
assert first[0]["status"] == second[0]["status"] == "ready"
|
||||
assert first[0]["id"] != second[0]["id"]
|
||||
finally:
|
||||
for row in rows:
|
||||
db.delete(row)
|
||||
db.commit()
|
||||
|
||||
|
||||
def test_timeline_includes_more_than_catch_page_and_sitemap_includes_old_spots() -> None:
|
||||
with Session(engine) as db:
|
||||
fish = db.scalar(select(Fish).where(Fish.slug == "pike"))
|
||||
|
||||
Reference in New Issue
Block a user