feat: include animated_url in tier-up response for T3/T4 (#201) #208

Merged
cal merged 1 commits from issue/201-feat-include-animated-url-in-tier-up-response-for into main 2026-04-08 10:25:54 +00:00
Collaborator

Closes #201

Summary

Adds animated_url to the tier-up response in the POST /api/v2/refractor/evaluate-game/{game_id} endpoint for T3 and T4 tier-ups.

Changes

  • app/routers_v2/refractor.py: Added from datetime import date import; extended the if boost_result: block to set animated_url on the tier-up entry when computed_tier >= 3 and a variant was created.

Behaviour

For T3/T4 tier-ups where boost_result is present, the response now includes:

{
  "player_id": 123,
  "team_id": 456,
  "variant_created": 7,
  "animated_url": "/api/v2/players/123/battingcard/2026-04-08/7/animated"
}

The animated_url is constructed as:

{API_BASE_URL}/api/v2/players/{player_id}/{card_type}card/{date}/{variant}/animated
  • API_BASE_URL env var controls the base (defaults to empty string, producing a relative URL). Set to e.g. https://pd.manticorum.com:815 in production for an absolute URL the Discord bot can use directly.
  • d is today's date (YYYY-MM-DD), matching the cache-bust convention in the S3 URL pipeline.
  • For T0/T1/T2 tier-ups, animated_url is absent (not included in the response).

Other observations

  • Issue #198 (APNG S3 pipeline) is not yet implemented. Once it is, animated_url could be updated to return the S3 URL instead of the API endpoint URL.
Closes #201 ## Summary Adds `animated_url` to the tier-up response in the `POST /api/v2/refractor/evaluate-game/{game_id}` endpoint for T3 and T4 tier-ups. ## Changes - `app/routers_v2/refractor.py`: Added `from datetime import date` import; extended the `if boost_result:` block to set `animated_url` on the tier-up entry when `computed_tier >= 3` and a variant was created. ## Behaviour For T3/T4 tier-ups where `boost_result` is present, the response now includes: ```json { "player_id": 123, "team_id": 456, "variant_created": 7, "animated_url": "/api/v2/players/123/battingcard/2026-04-08/7/animated" } ``` The `animated_url` is constructed as: ``` {API_BASE_URL}/api/v2/players/{player_id}/{card_type}card/{date}/{variant}/animated ``` - `API_BASE_URL` env var controls the base (defaults to empty string, producing a relative URL). Set to e.g. `https://pd.manticorum.com:815` in production for an absolute URL the Discord bot can use directly. - `d` is today's date (`YYYY-MM-DD`), matching the cache-bust convention in the S3 URL pipeline. - For T0/T1/T2 tier-ups, `animated_url` is absent (not included in the response). ## Other observations - Issue #198 (APNG S3 pipeline) is not yet implemented. Once it is, `animated_url` could be updated to return the S3 URL instead of the API endpoint URL.
Claude added 1 commit 2026-04-08 09:36:14 +00:00
Closes #201

Add animated_url to evaluate-game tier-up entries when new_tier >= 3.
URL is constructed from API_BASE_URL env var + the /animated endpoint
path, using today's date as the cache-bust segment.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude added the
ai-reviewing
label 2026-04-08 09:45:50 +00:00
Claude reviewed 2026-04-08 09:47:03 +00:00
Claude left a comment
Author
Collaborator

AI Code Review

Files Reviewed

  • app/routers_v2/refractor.py (modified)

Findings

Correctness

No issues found.

  • from datetime import date added at top-level — follows CLAUDE.md no-lazy-import rule
  • variant_num refactor is clean; tier_up_entry["variant_created"] behavior unchanged
  • Guard computed_tier >= 3 and variant_num and card_type: at this code path card_type is always truthy (the else: continue at line 457 ensures we never reach if boost_result: with a null card_type), so the card_type check is redundant but harmless
  • {card_type}card correctly yields battingcard / pitchingcard matching the /animated endpoint path from PR #188
  • computed_tier at the point of the guard reflects the last-committed tier (partial-failure path at line 456 sets computed_tier = last_successful_tier), so a T3-succeeded / T4-failed partial boost correctly still generates a T3 animated_url
  • os.environ.get("API_BASE_URL", "")os was already imported at line 1; env var default produces a relative URL as documented
  • variant_num truthiness: SHA-256 variants are remapped so 0→1 (see refractor_boost.py), making variant=0 theoretically impossible. Silently omitting animated_url if variant_num==0 is correct defensive behavior

Security

No issues found. URL is constructed entirely from server-controlled values (player_id from DB, card_type from DB state, date from server clock, variant_num from boost result). No user-controlled input in the URL.

Style & Conventions

No issues found.

Suggestions

  • PR ordering note: PR #207 (refactor evaluate-game to service layer) is also open and touches the same code block. If #207 merges first, this PR will need a rebase. Consider merging in order: #208#207, or coordinate accordingly — the logic here is simpler and has a lower rebase cost.
  • Minor: The card_type check in if computed_tier >= 3 and variant_num and card_type: is logically unreachable as a falsy value (see Correctness note above). It's harmless and adds defensive clarity, so no change needed.

Verdict: COMMENT

Implementation is correct. animated_url is only emitted for T3/T4 boosts, the URL format matches the /animated endpoint, env var configuration is sound, and the import follows project conventions. Self-review restriction prevents APPROVED — no blocking issues; ready to merge.


Automated review by Claude PR Reviewer

## AI Code Review ### Files Reviewed - `app/routers_v2/refractor.py` (modified) ### Findings #### Correctness No issues found. - `from datetime import date` added at top-level — follows CLAUDE.md no-lazy-import rule ✅ - `variant_num` refactor is clean; `tier_up_entry["variant_created"]` behavior unchanged ✅ - Guard `computed_tier >= 3 and variant_num and card_type`: at this code path `card_type` is always truthy (the `else: continue` at line 457 ensures we never reach `if boost_result:` with a null card_type), so the `card_type` check is redundant but harmless ✅ - `{card_type}card` correctly yields `battingcard` / `pitchingcard` matching the `/animated` endpoint path from PR #188 ✅ - `computed_tier` at the point of the guard reflects the last-committed tier (partial-failure path at line 456 sets `computed_tier = last_successful_tier`), so a T3-succeeded / T4-failed partial boost correctly still generates a T3 animated_url ✅ - `os.environ.get("API_BASE_URL", "")` — `os` was already imported at line 1; env var default produces a relative URL as documented ✅ - `variant_num` truthiness: SHA-256 variants are remapped so 0→1 (see refractor_boost.py), making variant=0 theoretically impossible. Silently omitting animated_url if variant_num==0 is correct defensive behavior ✅ #### Security No issues found. URL is constructed entirely from server-controlled values (player_id from DB, card_type from DB state, date from server clock, variant_num from boost result). No user-controlled input in the URL. #### Style & Conventions No issues found. #### Suggestions - **PR ordering note**: PR #207 (refactor evaluate-game to service layer) is also open and touches the same code block. If #207 merges first, this PR will need a rebase. Consider merging in order: #208 → #207, or coordinate accordingly — the logic here is simpler and has a lower rebase cost. - **Minor**: The `card_type` check in `if computed_tier >= 3 and variant_num and card_type:` is logically unreachable as a falsy value (see Correctness note above). It's harmless and adds defensive clarity, so no change needed. ### Verdict: COMMENT Implementation is correct. `animated_url` is only emitted for T3/T4 boosts, the URL format matches the `/animated` endpoint, env var configuration is sound, and the import follows project conventions. Self-review restriction prevents APPROVED — no blocking issues; ready to merge. --- *Automated review by Claude PR Reviewer*
Claude added
ai-reviewed
and removed
ai-reviewing
labels 2026-04-08 09:47:24 +00:00
cal approved these changes 2026-04-08 10:25:43 +00:00
cal left a comment
Owner

Approved via pd-pr

Approved via pd-pr
cal merged commit 7701777273 into main 2026-04-08 10:25:54 +00:00
cal deleted branch issue/201-feat-include-animated-url-in-tier-up-response-for 2026-04-08 10:25:54 +00:00
Sign in to join this conversation.
No description provided.