feat(gallery): faceted filter params + /facets counts endpoint (Phase 2 backend)
Extend the composable gallery filter with platform / untagged / no_artist / date_from / date_to, AND-composed with the existing tag/artist/media/sort params and threaded through scroll, timeline, and jump_cursor. Add GalleryService.facets() + GET /api/gallery/facets returning live counts scoped to the current filter with per-group minus-self semantics: platform counts (COUNT(DISTINCT image) incl. a null unsourced bucket), curation-flag counts (untagged / no_artist), and effective_date min/max bounds. The UNSOURCED_PLATFORM sentinel makes filesystem-imported content reachable via the platform facet. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -77,3 +77,40 @@ async def test_scroll_media_param(client, db):
|
||||
resp = await client.get("/api/gallery/scroll?limit=10&media=video")
|
||||
assert resp.status_code == 200
|
||||
assert (await resp.get_json())["images"] == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_facets_endpoint(client, db):
|
||||
await _seed(db, 3) # filesystem images: no artist, no tags, no platform
|
||||
resp = await client.get("/api/gallery/facets")
|
||||
assert resp.status_code == 200
|
||||
body = await resp.get_json()
|
||||
assert body["total"] == 3
|
||||
assert body["untagged"] == 3
|
||||
assert body["no_artist"] == 3
|
||||
assert "platforms" in body
|
||||
assert body["date_min"] is not None
|
||||
assert body["date_max"] is not None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_facets_rejects_bad_date(client):
|
||||
resp = await client.get("/api/gallery/facets?date_from=notadate")
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_scroll_untagged_param(client, db):
|
||||
await _seed(db, 2)
|
||||
resp = await client.get("/api/gallery/scroll?untagged=1&limit=10")
|
||||
assert resp.status_code == 200
|
||||
assert len((await resp.get_json())["images"]) == 2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_scroll_date_from_param(client, db):
|
||||
await _seed(db, 2) # all created ~now
|
||||
# A future date_from excludes everything.
|
||||
resp = await client.get("/api/gallery/scroll?date_from=2099-01-01&limit=10")
|
||||
assert resp.status_code == 200
|
||||
assert (await resp.get_json())["images"] == []
|
||||
|
||||
Reference in New Issue
Block a user