feat(artist): post_count on the artist overview response — drives the Posts/Gallery default-tab fallback in the upcoming ArtistView redesign
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -111,12 +111,22 @@ class ArtistService:
|
|||||||
)
|
)
|
||||||
).all()
|
).all()
|
||||||
|
|
||||||
|
post_count = (
|
||||||
|
await self.session.execute(
|
||||||
|
select(func.count(func.distinct(Post.id)))
|
||||||
|
.select_from(Post)
|
||||||
|
.join(Source, Source.id == Post.source_id)
|
||||||
|
.where(Source.artist_id == aid)
|
||||||
|
)
|
||||||
|
).scalar_one()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"id": artist.id,
|
"id": artist.id,
|
||||||
"name": artist.name,
|
"name": artist.name,
|
||||||
"slug": artist.slug,
|
"slug": artist.slug,
|
||||||
"is_subscription": bool(artist.is_subscription),
|
"is_subscription": bool(artist.is_subscription),
|
||||||
"image_count": int(image_count),
|
"image_count": int(image_count),
|
||||||
|
"post_count": int(post_count),
|
||||||
"date_range": {
|
"date_range": {
|
||||||
"min": dmin.isoformat() if dmin else None,
|
"min": dmin.isoformat() if dmin else None,
|
||||||
"max": dmax.isoformat() if dmax else None,
|
"max": dmax.isoformat() if dmax else None,
|
||||||
|
|||||||
@@ -29,6 +29,30 @@ async def test_artist_overview_ok(client, db):
|
|||||||
body = await resp.get_json()
|
body = await resp.get_json()
|
||||||
assert body["name"] == "Mira"
|
assert body["name"] == "Mira"
|
||||||
assert body["image_count"] == 0
|
assert body["image_count"] == 0
|
||||||
|
assert body["post_count"] == 0
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_artist_overview_post_count(client, db):
|
||||||
|
from backend.app.models import Post, Source
|
||||||
|
|
||||||
|
a = Artist(name="Lyra", slug="lyra")
|
||||||
|
db.add(a)
|
||||||
|
await db.flush()
|
||||||
|
s = Source(
|
||||||
|
artist_id=a.id, platform="patreon",
|
||||||
|
url="https://patreon.com/cw/lyra", enabled=True,
|
||||||
|
)
|
||||||
|
db.add(s)
|
||||||
|
await db.flush()
|
||||||
|
db.add(Post(source_id=s.id, external_post_id="p1"))
|
||||||
|
db.add(Post(source_id=s.id, external_post_id="p2"))
|
||||||
|
await db.flush()
|
||||||
|
await db.commit()
|
||||||
|
resp = await client.get("/api/artist/lyra")
|
||||||
|
assert resp.status_code == 200
|
||||||
|
body = await resp.get_json()
|
||||||
|
assert body["post_count"] == 2
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
|||||||
Reference in New Issue
Block a user