Skip to content

Commit

Permalink
Update BNA REST API client (#19)
Browse files Browse the repository at this point in the history
Updates the BNA REST API client to the current version.

Drive-by:
- Updates runtime dependencies.
- Adds test-log to the dev dependencies.

Signed-off-by: Rémy Greinhofer <[email protected]>
  • Loading branch information
rgreinho authored Dec 7, 2024
1 parent beaae31 commit 10ce66c
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 9 deletions.
113 changes: 112 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ aws-sdk-s3 = "1.65.0"
aws-sdk-sqs = "1.50.0"
aws-smithy-types-convert = "0.60.8"
axum = "0.7.7"
bnaclient = { git = "https://github.com/PeopleForBikes/bna-api", rev = "c8ca326" }
bnaclient = { git = "https://github.com/PeopleForBikes/bna-api", rev = "1b40300" }
# bnaclient = { path = "/Users/rgreinhofer/projects/PeopleForBikes/bna-api/bnaclient" }
bnacore = { git = "https://github.com/PeopleForBikes/brokenspoke", rev = "c20ec31" }
chrono = "0.4.19"
clap = "4.5.20"
Expand Down Expand Up @@ -44,7 +45,8 @@ serde_with = "3.11.0"
simple-error = "0.3.0"
slug = "0.1.6"
svg2pdf = "0.12.0"
thiserror = "2.0.4"
test-log = "0.2.16"
thiserror = "2.0.5"
tokio = "1.42.0"
tower = "0.5.1"
tower-cookies = "0.10.0"
Expand Down
3 changes: 3 additions & 0 deletions lambdas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ url = { workspace = true, features = ["serde"] }
uuid = { workspace = true, features = ["v4", "serde"] }
usvg = { workspace = true }

[dev-dependencies]
test-log = { workspace = true, features = ["trace"] }

[[bin]]
name = "bna-fargate-run"
path = "src/bna-fargate-run.rs"
Expand Down
23 changes: 17 additions & 6 deletions lambdas/src/bna-save-results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use bnalambdas::{create_service_account_bna_client, AnalysisParameters, Context,
use csv::ReaderBuilder;
use heck::ToTitleCase;
use lambda_runtime::{run, service_fn, Error, LambdaEvent};
use rust_decimal::prelude::ToPrimitive;
use rust_decimal::Decimal;
use rust_decimal::{prelude::ToPrimitive, Decimal};
use rust_decimal_macros::dec;
use serde::Deserialize;
use simple_error::SimpleError;
Expand Down Expand Up @@ -180,9 +179,10 @@ async fn get_or_create_city(
region: &str,
name: &str,
) -> Result<Uuid, Error> {
let normalized_country = Country::from_str(country.to_title_case().as_str())?;
let response = client
.get_city()
.country(country)
.country(normalized_country)
.region(region)
.name(name)
.send()
Expand All @@ -199,20 +199,21 @@ async fn get_or_create_city(
}
};
info!("City: {:#?}", city);
dbg!(&city);

let city_id: Uuid;
if let Some(city) = city {
info!("The city exists, update the population...");
city_id = city.city_id.expect("a city id to be present");
city_id = city.id;
} else {
info!("Create a new city...");
// Create the city.
let c = CityPost::builder()
.country(Country::from_str(country.to_title_case().as_str())?)
.country(normalized_country)
.state(Some(region.to_title_case()))
.name(name.to_title_case());
let city = client.post_city().body(c).send().await?;
city_id = city.city_id.expect("a city id to be present");
city_id = city.id;
}

Ok(city_id)
Expand Down Expand Up @@ -358,6 +359,7 @@ async fn main() -> Result<(), Error> {
mod tests {
use super::*;
use aws_sdk_s3::primitives::DateTime;
use test_log::test;

#[test]
fn test_input_deserialization() {
Expand Down Expand Up @@ -648,4 +650,13 @@ mod tests {
// let event = LambdaEvent::new(payload, context);
// function_handler(event).await.unwrap();
// }

// #[test(tokio::test)]
// async fn test_get_or_create_city() {
// let client = bnaclient::Client::new("http://localhost:3000");
// let city = get_or_create_city(&client, "United States", "New Mexico", "Santa Rosa")
// .await
// .unwrap();
// dbg!(city);
// }
}

0 comments on commit 10ce66c

Please sign in to comment.