---
estimated_steps: 18
estimated_files: 2
skills_used: []
---

# T01: Add video_filename to technique detail API response

Extend the backend technique detail endpoint to include the source video filename on each key moment. This is the data prerequisite for all frontend changes in T02.

## Steps

1. In `backend/schemas.py`, add `video_filename: str = ""` to the `KeyMomentSummary` class.
2. In `backend/routers/techniques.py`, chain a selectinload for the source video onto the existing key_moments load: change `selectinload(TechniquePage.key_moments)` to `selectinload(TechniquePage.key_moments).selectinload(KeyMoment.source_video)`. Import `SourceVideo` from models if not already imported.
3. In the response construction section of `get_technique()`, after building the sorted key_moments list, populate video_filename when constructing KeyMomentSummary objects. Change the model_validate call to manually construct the dict or use a post-processing step:
   ```python
   key_moment_items = []
   for km in key_moments:
       item = KeyMomentSummary.model_validate(km)
       item.video_filename = km.source_video.filename if km.source_video else ""
       key_moment_items.append(item)
   ```
4. Verify locally or on ub01 that `curl http://ub01:8096/api/v1/techniques/wave-shaping-synthesis-m-wave-shaper | python3 -m json.tool` now includes `video_filename` in each key_moments entry.

## Must-Haves

- [ ] `KeyMomentSummary` schema has `video_filename: str = ""` field
- [ ] Technique detail query uses chained selectinload for source_video
- [ ] Each key moment in API response includes populated `video_filename`
- [ ] Existing fields and behavior unchanged

## Inputs

- `backend/schemas.py`
- `backend/routers/techniques.py`
- `backend/models.py`

## Expected Output

- `backend/schemas.py`
- `backend/routers/techniques.py`

## Verification

ssh ub01 'cd /vmPool/r/repos/xpltdco/chrysopedia && docker compose build chrysopedia-api && docker compose up -d chrysopedia-api && sleep 3 && curl -s http://localhost:8096/api/v1/techniques/ | python3 -m json.tool | head -5' && ssh ub01 'curl -s http://localhost:8096/api/v1/techniques/wave-shaping-synthesis-m-wave-shaper | python3 -c "import sys,json; d=json.load(sys.stdin); kms=d.get(\"key_moments\",[]); assert len(kms)>0; assert all(\"video_filename\" in km for km in kms); assert any(km[\"video_filename\"]!=\"\" for km in kms); print(f\"OK: {len(kms)} moments, all have video_filename\")"'
