feat: Added summary, topic_tags, and key_moment_count fields to Creator…
- "backend/schemas.py" - "backend/routers/creators.py" GSD-Task: S03/T01
This commit is contained in:
parent
f4f21b6c36
commit
371494c2f8
2 changed files with 16 additions and 1 deletions
|
|
@ -12,7 +12,7 @@ from sqlalchemy import func, select
|
|||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from database import get_session
|
||||
from models import Creator, SourceVideo, TechniquePage
|
||||
from models import Creator, KeyMoment, SourceVideo, TechniquePage
|
||||
from schemas import CreatorBrowseItem, CreatorDetail, CreatorRead, CreatorTechniqueItem
|
||||
|
||||
logger = logging.getLogger("chrysopedia.creators")
|
||||
|
|
@ -137,12 +137,22 @@ async def get_creator(
|
|||
)).scalar() or 0
|
||||
|
||||
# Technique pages for this creator
|
||||
key_moment_count_sq = (
|
||||
select(func.count(KeyMoment.id))
|
||||
.where(KeyMoment.technique_page_id == TechniquePage.id)
|
||||
.correlate(TechniquePage)
|
||||
.scalar_subquery()
|
||||
.label("key_moment_count")
|
||||
)
|
||||
technique_rows = (await db.execute(
|
||||
select(
|
||||
TechniquePage.title,
|
||||
TechniquePage.slug,
|
||||
TechniquePage.topic_category,
|
||||
TechniquePage.created_at,
|
||||
TechniquePage.summary,
|
||||
TechniquePage.topic_tags,
|
||||
key_moment_count_sq,
|
||||
)
|
||||
.where(TechniquePage.creator_id == creator.id)
|
||||
.order_by(TechniquePage.created_at.desc())
|
||||
|
|
@ -152,6 +162,8 @@ async def get_creator(
|
|||
CreatorTechniqueItem(
|
||||
title=t.title, slug=t.slug,
|
||||
topic_category=t.topic_category, created_at=t.created_at,
|
||||
summary=t.summary, topic_tags=t.topic_tags,
|
||||
key_moment_count=t.key_moment_count,
|
||||
)
|
||||
for t in technique_rows
|
||||
]
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ class CreatorTechniqueItem(BaseModel):
|
|||
slug: str
|
||||
topic_category: str
|
||||
created_at: datetime
|
||||
summary: str | None = None
|
||||
topic_tags: list[str] | None = None
|
||||
key_moment_count: int = 0
|
||||
|
||||
|
||||
class CreatorDetail(CreatorRead):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue