---
estimated_steps: 20
estimated_files: 3
skills_used: []
---

# T01: Add moment_count to CreatorDetail backend response and frontend type

The backend CreatorDetail schema and router don't include moment_count. The frontend type also lacks it. This task adds the count (via KeyMoment→SourceVideo join) to the backend, adds the field to the Pydantic schema, and syncs the frontend TypeScript interface.

## Steps

1. In `backend/schemas.py`, add `moment_count: int = 0` to the `CreatorDetail` class (after `technique_count`).
2. In `backend/routers/creators.py` `get_creator()` function (~line 127), add a moment count query after the video_count query:
   ```python
   moment_count = (await db.execute(
       select(func.count()).select_from(KeyMoment)
       .join(SourceVideo, KeyMoment.source_video_id == SourceVideo.id)
       .where(SourceVideo.creator_id == creator.id)
   )).scalar() or 0
   ```
   Ensure `KeyMoment` is imported from `models`. Pass `moment_count=moment_count` in the `CreatorDetail(...)` constructor (~line 164).
3. In `frontend/src/api/public-client.ts`, add `moment_count: number;` to the `CreatorDetailResponse` interface (after `technique_count`).
4. Verify: `cd frontend && npx tsc --noEmit` — zero errors.

## Must-Haves

- [ ] `moment_count: int = 0` on CreatorDetail schema
- [ ] Subquery joins KeyMoment→SourceVideo→creator.id
- [ ] `moment_count` passed in CreatorDetail constructor
- [ ] Frontend type includes `moment_count: number`
- [ ] TypeScript compiles with zero errors

## Inputs

- `backend/schemas.py`
- `backend/routers/creators.py`
- `frontend/src/api/public-client.ts`

## Expected Output

- `backend/schemas.py`
- `backend/routers/creators.py`
- `frontend/src/api/public-client.ts`

## Verification

cd frontend && npx tsc --noEmit
