Fix #112: Expose level progress percentage in profile API response #127
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "typosaurus/ticket-112"
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?
Resolves #112.
Plan
Implementation Plan: Expose Level Progress in Profile API
Objective
Add derived fields
xp_progress_pct(integer percentage toward next level) andxp_next_level(total XP required for next level) toGET /profileandGET /profile/{username}responses.1. Schema Change
File:
devplacepy/schemas/profile.pyProfileOut(line 29–82), add two optional integer fields:xp_progress_pct: Optional[int] = Nonexp_next_level: Optional[int] = NoneThese fields are optional to avoid breaking existing consumers and because the value is computed at request time.
2. Route Handler Computation
File:
devplacepy/routers/profile/index.pyprofile_page()function (starting line 128). Locate therespond()call at line 383–445. Before that call, compute:Include these values in the context dict passed to
respond(). For example:If
user.xpisNone, default to0for the computation.3. Test Addition
File:
tests/api/profile/index.py(add a new test function, e.g.,test_profile_contains_xp_progress)GET /profileandGET /profile/{username}.xp_progress_pctandxp_next_level.xp_progress_pct= 250 % 100 = 50xp_next_level= ((250 // 100) + 1) * 100 = 300Use the existing test infrastructure (e.g.,
test_clientfixture andauth_headers).4. Verification
tests/api/) to ensure no regressions, but the primary verification is the command above.Definition of Done
ProfileOutschema includesxp_progress_pctandxp_next_levelfields./profileand/profile/{username}responses containxp_progress_pct(0–99 integer) andxp_next_level(total XP for next level).test_profile_contains_xp_progress(or equivalent) exists and verifies the fields for at least one known XP value.pip install -e '.[dev]' -q && python -m pytest tests/api/profile/index.pyexits with code 0 and shows all tests passing. (Pre-existing Playwright-related failures in other test directories are unrelated and ignored for this change’s validation.)Opened automatically by Typosaurus.
Checkout
From your project repository, check out a new branch and test the changes.