Commit Graph

11 Commits

Author SHA1 Message Date
Jason Stedwell 5e45031789 Harden dog endpoints: parent validation, 404s, safe photo handling, transactions
- safeParsePhotos(): corrupted photo_urls JSON no longer crashes every request
  that loads the dog
- DELETE /photos/:idx rejects NaN/out-of-range indexes with 400 (was silent no-op)
- PUT /:id returns 404 for missing dogs (was silent success)
- POST/PUT validate sire/dam exist, have the right sex, and aren't the dog itself
- Dog create (dog+parents), update (dog+parent swap), and cascade delete now run
  in transactions — no more partial writes

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-06 14:47:41 -05:00
jason b8633863b0 fix: add pagination to unbounded GET endpoints
All list endpoints now accept ?page and ?limit (default 50, max 200) and
return { data, total, page, limit } instead of a bare array, preventing
memory and performance failures at scale.

- GET /api/dogs: adds pagination, server-side search (?search) and sex
  filter (?sex), and a stats aggregate (total/males/females) for the
  Dashboard to avoid counting from the array
- GET /api/litters: adds pagination; also fixes N+1 query by fetching
  all puppies for the current page in a single query instead of one per
  litter
- DogList: moves search/sex filtering server-side with 300ms debounce;
  adds Prev/Next pagination controls
- LitterList: uses paginated response; adds Prev/Next pagination controls
- Dashboard: reads counts from stats/total fields instead of array length
- LitterDetail, LitterForm: switch dogs fetch to /api/dogs/all (complete
  list, no pagination, for sire/dam dropdowns)
- DogForm: updates litters fetch to use paginated response shape

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-16 16:40:28 -05:00
jason 5eaa6e566c fix: GET /api/dogs honours ?include_external=1 query param for pairing simulator 2026-03-11 01:00:48 -05:00
jason 9738b24db6 feat(api): add is_external support — GET /api/dogs filters kennel dogs; GET /api/dogs/external returns external roster 2026-03-10 15:24:50 -05:00
jason 0ade8586f9 feat(dogs): add hard DELETE /api/dogs/:id with cascade cleanup 2026-03-09 22:57:43 -05:00
jason 421ea5cb58 feat(api): expose is_champion on all dog queries incl sire/dam/offspring joins 2026-03-09 22:24:39 -05:00
jason d311bc24a7 Clean: Proper sire/dam handling via parents table with logging 2026-03-09 02:01:18 -05:00
jason eec18daeea Fix: Remove weight/height columns - match actual schema 2026-03-09 01:38:42 -05:00
jason e62d35041f Fix: Don't return sire/dam columns from dogs table, select explicit fields 2026-03-09 01:29:40 -05:00
jason 56fb9cb7af Fix: Convert empty microchip strings to NULL in database 2026-03-08 23:55:38 -05:00
jason e8c7d77c52 Add dogs API routes 2026-03-08 22:44:23 -05:00