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

# T01: Add sort=random query param to list_techniques endpoint and API client

Add an optional `sort` query parameter to the backend `list_techniques` endpoint in `backend/routers/techniques.py`. Accepts 'recent' (default, existing created_at DESC behavior) and 'random' (using func.random(), same pattern as creators.py line 67). Update `TechniqueListParams` in `frontend/src/api/public-client.ts` to include `sort?: string` and pass it as a query string param in `fetchTechniques`.

Backend change pattern (from creators.py):
```python
sort: Annotated[str, Query()] = "recent",
```
Then in the query building:
```python
if sort == "random":
    stmt = stmt.order_by(func.random())
else:
    stmt = stmt.order_by(TechniquePage.created_at.desc())
```

Replace the existing hardcoded `.order_by(TechniquePage.created_at.desc())` with the conditional.

## Inputs

- ``backend/routers/techniques.py` — existing list_techniques endpoint to add sort param to`
- ``frontend/src/api/public-client.ts` — existing TechniqueListParams and fetchTechniques to add sort support`

## Expected Output

- ``backend/routers/techniques.py` — list_techniques with sort=random|recent query param`
- ``frontend/src/api/public-client.ts` — TechniqueListParams with sort field, fetchTechniques passing sort param`

## Verification

cd frontend && npx tsc --noEmit && grep -q 'sort.*random' ../backend/routers/techniques.py && grep -q 'sort' src/api/public-client.ts
