From 3b2c1aeda0f137b8ebcc677c098cf8b7a4077ef1 Mon Sep 17 00:00:00 2001 From: Joshua Coles Date: Mon, 3 Jun 2024 20:26:31 +0100 Subject: [PATCH] Add some documentation to the CLI and the csv ingestion route --- src/ingestion/routes.rs | 4 +++- src/main.rs | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ingestion/routes.rs b/src/ingestion/routes.rs index 4c583d1..777171c 100644 --- a/src/ingestion/routes.rs +++ b/src/ingestion/routes.rs @@ -43,10 +43,12 @@ pub async fn monzo_batched_csv( Extension(db): Extension, multipart: Multipart, ) -> Result<&'static str, AppError> { + static CSV_MISSING_ERR_MSG: &'static str = "No CSV file provided. Expected a multipart request with a `csv` field containing the contents of the CSV."; + let csv = extract_csv(multipart) .await .map_err(|e| AppError::BadRequest(anyhow!(e))) - .and_then(|csv| csv.ok_or(AppError::BadRequest(anyhow!("No CSV file provided"))))?; + .and_then(|csv| csv.ok_or(AppError::BadRequest(anyhow!(CSV_MISSING_ERR_MSG))))?; let csv = Cursor::new(csv); let mut csv = csv::Reader::from_reader(csv); diff --git a/src/main.rs b/src/main.rs index 724f65f..8c3c14b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,7 @@ use tracing::log::LevelFilter; #[derive(Debug, Subcommand)] enum Commands { + /// Manually run database migrations. Migrate { /// Number of migration steps to perform. If not provided, all migrations will be run. #[arg(long)] @@ -28,8 +29,9 @@ enum Commands { down: bool, }, + /// Start web app for to the google-sheets app script Serve { - /// If we should perform migration on startup. + /// If we should perform migration at startup. #[clap(short, long, env, default_value_t = true)] migrate: bool, @@ -38,12 +40,14 @@ enum Commands { addr: SocketAddr, }, + /// Ingest a google-sheets CSV export into the database. Csv { - /// The path to the CSV file to ingest. + /// The path of the CSV file to ingest. csv_file: PathBuf, }, } +/// Ingest and manage monzo transactions from the Monzo Plus auto-export feature #[derive(Debug, clap::Parser)] struct Cli { /// URL to PostgreSQL database.