3.6 KiB
3.6 KiB
Copilot Instructions
Build, test, and lint
cargo buildcargo run- requires a local.envfile withANTARES_USERCODEandANTARES_PASSWORDcargo testcargo test <test_name>to run one testcargo test -- --listto discover test names; the repository currently has no defined testscargo fmt --all -- --checkcargo clippy --all-targets -- -D warnings
High-level architecture
This is a modular single-binary Rust utility that fetches Antares B2B product data and exports it to Excel. The codebase is organized into separate concerns:
Modules:
src/main.rs- orchestrates the pipeline: credential loading, API calls, JSON deserialization, and delegating to toolssrc/api/client.rs- handles URL construction for the Antares B2B APIsrc/tools/excel.rs- implements Excel export with selective field mapping and business rule validationsrc/tools/logger.rs- provides dual output (terminal + file) logging tolog/{YYYY-MM-DD}.logsrc/template/antares.rs- serde models with#[serde(rename_all = "PascalCase")]; top-level isAntaresalias forVec<AntaresItem>
Pipeline:
- Initialize logger (creates
log/dir if needed) - Load credentials from
.envviadotenv - Build Antares API URL using
src/api/client::make_url() - Fetch with 300-second timeout via blocking
reqwest::blocking::Client - Deserialize into typed
Antaresstructs; if schema mismatch, preserve response as JSON/text - Write
antares.jsonwith pretty formatting - Export filtered rows to
out/antares_export.xlsxviasrc/tools/excel::export_to_excel() - Log success/failure at each step
Logging:
- All significant events logged to terminal and
log/{YYYY-MM-DD}.log - Specialized methods:
log_api_success(),log_api_failure(),log_export_success(),log_export_failure() - Directory created automatically if missing; logs appended daily by date
Key conventions
Credentials:
- Load only via
ANTARES_USERCODEandANTARES_PASSWORDenv vars from.env .env.exampledocuments required variables- No hardcoded credentials; missing vars cause graceful failure with instructions
Artifacts:
antares.json- saved at repo root after each successful API fetchout/antares_export.xlsx- Excel export;out/directory created auto if missinglog/{YYYY-MM-DD}.log- daily logs;log/directory created auto if missing.gitignoreexcludes:*.json,*.xlsx,.env,/out,/log
Excel export (src/tools/excel.rs):
- Not a generic dump; maps selected Antares fields to fixed column layout per business rules
- Rows skipped if
cikkszamempty OR both name fields (cikk_megnevezes_rovid,cikk_megnevezes) empty BESZCIKKNEVpreferscikk_megnevezes_rovid, falls back tocikk_megnevezesEGYSEGARprefersnetto_kisker_ar; if0.0, searchescikk_jellemzokfor entry withjellemzo_nev == "Alap ár"- Headers are bold-formatted
API integration:
- When extending the schema, add/modify structs in
src/template/antares.rsfirst - Avoid ad hoc JSON traversal in
main.rs; keep deserialization flow centered on typed structs - Preserve response on schema mismatch (save as JSON or text) unless deliberately changing error handling
Modularity:
- Extend by adding new files to
src/tools/(e.g.,csv.rs,database.rs) - Each tool should be self-contained and exposed via
src/tools/mod.rs - HTTP client logic stays in
src/api/; reusemake_request()frommain.rsfor consistency
Blocking HTTP:
- Uses
reqwest::blocking::Clientwith 300-second timeout - No async runtime; synchronous flow is intentional
- Only change to async if architecture overhaul is deliberate