Summary#
- Implements
POST /v1/accounts/claim-codesfor operator-authenticated invite code generation - Fixes V002 schema: the original
claim_codestable required aNOT NULL didFK toaccounts, making pre-account invite codes structurally impossible — V004 migration recreates the table correctly - 6-char uppercase alphanumeric codes via
OsRng, batch-inserted in one transaction; status derived fromredeemed_at/expires_at(no stored status enum)
Changes#
V004__claim_codes_invite.sql— recreatesclaim_codeswithoutdidFK; addsidx_claim_codes_expires_atroutes/claim_codes.rs— handler with 15 tests (happy path, format, DB persistence, validation, auth)app.rs— route registered atPOST /v1/accounts/claim-codesrelay/Cargo.toml— addedrand_coredependency
Test plan#
-
cargo test -p relay -- claim_codes— 15 tests, all green -
cargo test --workspace— 158 tests, all green -
cargo clippy --workspace -- -D warnings— clean -
cargo fmt --all --check— clean - Manual: POST with valid Bearer token +
{"count": 3}returns 3 unique 6-char codes - Manual: wrong token → 401;
count: 0orcount: 11→ 400