Fix #146: Add missing icon field to badges API response #147

Merged
typosaurus merged 1 commits from typosaurus/ticket-146 into master 2026-07-27 12:35:49 +02:00
Collaborator

Resolves #146.

Plan

Plan: Add icon field to badge API response

  1. Update schema (devplacepy/schemas/content.py lines 68–71)
    Add icon: Optional[str] = None to BadgeOut. No other fields or aliases needed.

  2. Enrich badge rows in profile route (devplacepy/routers/profile/index.py around line 203)
    After the list(get_table("badges").find(...)) call (line 203) and before the response context is built, insert a loop:

    for b in badges:
        b["icon"] = get_badge(b["badge_name"])["icon"]
    

    The get_badge function is already imported (used elsewhere). This makes icon available in each row dict so BadgeOut serializes it into JSON.

  3. (Optional) Add API test (tests/api/profile/index.py)
    Add a test that fetches a profile with Accept: application/json and asserts every badge in the response has an icon field (non‑empty string). This is recommended but not mandatory for the fix.

  4. Run verification
    Execute the project’s test command targeting relevant test files:

    pip install -e '.[dev]' -q && python -m pytest tests/api/profile/index.py tests/unit/utils.py
    

    Do not include e2e tests (known flakiness unrelated to this change).


Definition of Done

  • BadgeOut schema contains icon: Optional[str] = None.
  • Profile route handler enriches each badge dict with icon from the catalog before response serialization.
  • JSON response for profile endpoint includes icon for every badge (verified via a new or existing API test).
  • All unit and API tests (tests/api/profile/index.py, tests/unit/utils.py) pass with exit code 0.
  • No database migrations or template changes required.
  • Existing HTML profile rendering remains unchanged.

Opened automatically by Typosaurus.

Resolves #146. ## Plan **Plan: Add `icon` field to badge API response** 1. **Update schema** (`devplacepy/schemas/content.py` lines 68–71) Add `icon: Optional[str] = None` to `BadgeOut`. No other fields or aliases needed. 2. **Enrich badge rows in profile route** (`devplacepy/routers/profile/index.py` around line 203) After the `list(get_table("badges").find(...))` call (line 203) and before the response context is built, insert a loop: ```python for b in badges: b["icon"] = get_badge(b["badge_name"])["icon"] ``` The `get_badge` function is already imported (used elsewhere). This makes `icon` available in each row dict so `BadgeOut` serializes it into JSON. 3. **(Optional) Add API test** (`tests/api/profile/index.py`) Add a test that fetches a profile with `Accept: application/json` and asserts every badge in the response has an `icon` field (non‑empty string). This is recommended but not mandatory for the fix. 4. **Run verification** Execute the project’s test command targeting relevant test files: ``` pip install -e '.[dev]' -q && python -m pytest tests/api/profile/index.py tests/unit/utils.py ``` Do not include e2e tests (known flakiness unrelated to this change). --- **Definition of Done** - `BadgeOut` schema contains `icon: Optional[str] = None`. - Profile route handler enriches each badge dict with `icon` from the catalog before response serialization. - JSON response for profile endpoint includes `icon` for every badge (verified via a new or existing API test). - All unit and API tests (`tests/api/profile/index.py`, `tests/unit/utils.py`) pass with exit code 0. - No database migrations or template changes required. - Existing HTML profile rendering remains unchanged. Opened automatically by Typosaurus.
typosaurus added 1 commit 2026-07-27 12:08:33 +02:00
ticket #146 attempt 1
Some checks failed
DevPlace CI / test (pull_request) Failing after 1h26m26s
d895de1b47
typosaurus merged commit 5079f40f46 into master 2026-07-27 12:35:49 +02:00
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: retoor/devplacepy#147
No description provided.