From b5f7b6aee3f34e631bce41c7255af44809aec9f2 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Fri, 27 Feb 2026 22:57:59 -0600 Subject: [PATCH] =?UTF-8?q?store:=20SBA=20Scout=20Rust=20rewrite=20Phase?= =?UTF-8?q?=202=20complete=20=E2=80=94=20API=20client,=20sync,=20and=20CSV?= =?UTF-8?q?=20importers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...e-2-complete-api-client-sync-and-4dc83e.md | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 graph/decisions/sba-scout-rust-rewrite-phase-2-complete-api-client-sync-and-4dc83e.md diff --git a/graph/decisions/sba-scout-rust-rewrite-phase-2-complete-api-client-sync-and-4dc83e.md b/graph/decisions/sba-scout-rust-rewrite-phase-2-complete-api-client-sync-and-4dc83e.md new file mode 100644 index 00000000000..fe429dce326 --- /dev/null +++ b/graph/decisions/sba-scout-rust-rewrite-phase-2-complete-api-client-sync-and-4dc83e.md @@ -0,0 +1,33 @@ +--- +id: 4dc83eed-b0b1-4924-b82e-faf352426785 +type: decision +title: "SBA Scout Rust rewrite Phase 2 complete — API client, sync, and CSV importers" +tags: [sba-scout, rust, migration, phase-2, reqwest, api, csv, serde] +importance: 0.8 +confidence: 0.8 +created: "2026-02-28T04:57:59.820017+00:00" +updated: "2026-02-28T04:57:59.820017+00:00" +--- + +# SBA Scout Rust Rewrite — Phase 2 Complete + +Phase 2 (API Client + Sync + CSV Import) committed as `3c70ecc` on branch `feat/rust-rewrite`. 1,580 lines across 6 files. + +## Files Implemented + +- **`api/types.rs`** (175 lines): Serde response types with `#[serde(rename)]` for API field mismatches (`sname`→`short_name`, `wara`→`swar`, `gmid`→`gm_discord_id`, etc.) +- **`api/client.rs`** (225 lines): `ApiError` enum (Http/CloudflareBlocked/Request/Parse) + `LeagueApiClient` with core `get()` and 10 endpoint methods +- **`api/sync.rs`** (243 lines): `sync_teams` (INSERT OR REPLACE), `sync_players` (ON CONFLICT omitting `hand` to preserve CSV data), `sync_transactions` (ON CONFLICT on composite key), `sync_all` orchestrator +- **`api/importer.rs`** (666 lines): `parse_float`/`parse_int`/`parse_endurance` helpers, `import_batter_cards` (30+ column mapping), `import_pitcher_cards` (different header names, endurance parsing), `import_all_cards` (resilient — tries both CSVs independently) + +## Key Decisions + +- **Serde rename**: `#[serde(rename = "...")]` handles API field name mismatches at deserialization layer — cleaner than manual mapping +- **sync_players ON CONFLICT**: Uses `DO UPDATE SET ... (excluding hand column)` to preserve hand data from CSV imports while updating all other fields from API +- **import_all_cards resilience**: Doesn't abort if one CSV is missing — tries both independently so partial data is still loaded +- **response.text() + serde_json::from_str()**: Used instead of `response.json()` to properly populate `ApiError::Parse(serde_json::Error)` variant (see related fix memory) + +## Relates To + +- Phase 1 decision: c9add129 (foundation layer — DB schema, queries, config) +- Branch: `feat/rust-rewrite`