Add GET /stats endpoint + redeemed_item column for gamification #16
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Lineage
plan-mcd-tracker→ Phase 7 (SvelteKit + Capacitor) — backend prereqsRepo
forgejo_admin/mcd-tracker-apiUser Story
As a user viewing my home dashboard or history page
I want to see my lifetime stats (codes redeemed, level, XP) and record what menu item I got when redeeming
So that the app celebrates my usage and tracks my preferences over time
Context
The frontend playground (Phase 6) added gamification UX: an XP banner on the home page ("Level 3 — BOGO Hunter · 12 codes redeemed"), a lifetime stats bar on the history page (scanned/earned/redeemed/expired counts), and a "What did you get?" chip picker on the redemption success screen (Big Mac, McChicken, etc.).
The frontend needs two backend changes before it can wire these up:
GET /statsendpoint returning lifetime counts and level infoPATCH /codes/{id}/redeemendpoint needs to accept an optionalredeemed_itemfieldThe 5-day expiry (
expires_aton CouponUsage) already exists in the schema — no changes needed there.File Targets
Files to modify:
src/mcd_tracker_api/models.py— addredeemed_itemcolumn to CouponUsagesrc/mcd_tracker_api/routes/locations.py— update redeem endpoint to acceptredeemed_item, addGET /statsendpointsrc/mcd_tracker_api/schemas.py(or wherever Pydantic models live) — addredeemed_itemto redeem request/response schemas, add StatsResponse schemaalembic/versions/— new migration addingredeemed_itemcolumnFiles NOT to touch:
src/mcd_tracker_api/auth.py— no auth changessrc/mcd_tracker_api/config.py— no config changesAcceptance Criteria
GET /statsreturns JSON:{ "total_scanned": int, "total_earned": int, "total_redeemed": int, "total_expired": int, "current_level": int, "level_name": str, "xp_progress": float }xp_progressis a float 0.0-1.0 representing progress within current levelPATCH /codes/{id}/redeemaccepts optional body{ "redeemed_item": "Big Mac" }— string, nullableredeemed_itemstill works (backward compatible)redeemed_itemappears in code response objectsGET /statsrequires auth (returns stats for the authenticated user only)Test Expectations
GET /statswith 0 codes → Level 1, all zerosGET /statswith 6 redeemed → Level 2, correct xp_progressPATCH /codes/{id}/redeemwithredeemed_item→ item savedPATCH /codes/{id}/redeemwithout body → still works,redeemed_itemis nullGET /statscounts expired codes correctly (codes pastexpires_atand not redeemed)pytest tests/ -vConstraints
routes/locations.pyget_current_userdependency for authredeemed_itemis a simple nullable String column, not a foreign key (structured item tracking is Phase 14)Checklist
Related
project-mcd-tracker— parent projectphase-mcd-tracker-13-gamification— the phase this feeds into (XP system)