[Feature] POST /objectives/claim — Claim Completed Objective Rewards #3
Reference in New Issue
Block a user
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?
Overview
Allow the player to claim the reward for a completed objective. Objectives can currently be viewed and progress is tracked, but rewards cannot yet be collected.
Prerequisites
GET /objectivesendpoint (already implemented)Implementation Steps
1. Verify the objective is complete
In
src/services/objectives.rs:Query
SELECT progress, target FROM objectives WHERE id = ?and checkprogress >= target.2. Verify the objective has not already been claimed
Check for an existing
claimed_attimestamp. If already claimed →409 Conflict:3. Grant the reward by type
Reward types come from
data/objectives.json:coins→UPDATE clubs SET coins = coins + ? WHERE id = 1pack→ add pack to player inventory (pack_inventorytable, create if needed)card→ add a specific card to the collectionxp→ update player XP and trigger level-up check4. Mark objective as claimed atomically
The
AND claimed_at IS NULLguard prevents double-claiming even under concurrent requests.5. Add
claimed_atmigration6. Register route in
src/routes/objectives.rs7. Request/Response format
Request:
POST /objectives/score_5_goals/claim(no body needed)Response 200:
Response 400: Objective not yet complete
Response 409: Already claimed
8. Write integration tests
Acceptance Criteria
POST /objectives/:id/claimroute existsclaimed_atcolumn added via migrationcargo clippy -- -D warningspasses