diff --git a/lambdas/Cargo.toml b/lambdas/Cargo.toml index 611a077..9e99f57 100644 --- a/lambdas/Cargo.toml +++ b/lambdas/Cargo.toml @@ -45,7 +45,7 @@ name = "lambdas" path = "src/lib.rs" [[bin]] -name = "server" +name = "axumed" path = "src/main.rs" [[bin]] diff --git a/lambdas/src/core/resource/ratings/db.rs b/lambdas/src/core/resource/ratings/db.rs index 66bdc91..d026640 100644 --- a/lambdas/src/core/resource/ratings/db.rs +++ b/lambdas/src/core/resource/ratings/db.rs @@ -11,10 +11,10 @@ use uuid::Uuid; use super::BNAComponent; -#[derive(FromQueryResult, Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, FromQueryResult, Clone, PartialEq, Serialize, Deserialize)] pub struct Bna { // BNA Summary - bna_id: Uuid, + id: Uuid, city_id: Uuid, score: f64, version: String, @@ -55,21 +55,21 @@ pub struct Bna { transit: Option, } -#[derive(FromQueryResult, Deserialize, Serialize)] +#[derive(Debug, FromQueryResult, Deserialize, Serialize)] pub struct Summary { - bna_id: Uuid, + id: Uuid, city_id: Uuid, score: f64, version: String, } -#[derive(FromQueryResult, Deserialize, Serialize)] +#[derive(Debug, FromQueryResult, Deserialize, Serialize)] pub struct Infrastructure { low_stress_miles: Option, high_stress_miles: Option, } -#[derive(FromQueryResult, Deserialize, Serialize)] +#[derive(Debug, FromQueryResult, Deserialize, Serialize)] pub struct Recreation { community_centers: Option, parks: Option, @@ -77,7 +77,7 @@ pub struct Recreation { recreation_score: Option, } -#[derive(FromQueryResult, Deserialize, Serialize)] +#[derive(Debug, FromQueryResult, Deserialize, Serialize)] pub struct Opportunity { employment: Option, higher_education: Option, @@ -86,7 +86,7 @@ pub struct Opportunity { technical_vocational_college: Option, } -#[derive(FromQueryResult, Deserialize, Serialize)] +#[derive(Debug, FromQueryResult, Deserialize, Serialize)] pub struct CoreServices { dentists: Option, doctors: Option, @@ -97,21 +97,22 @@ pub struct CoreServices { social_services: Option, } -#[derive(FromQueryResult, Deserialize, Serialize)] +#[derive(Debug, FromQueryResult, Deserialize, Serialize)] pub struct People { people: Option, } -#[derive(FromQueryResult, Deserialize, Serialize)] +#[derive(Debug, FromQueryResult, Deserialize, Serialize)] pub struct Retail { retail: Option, } -#[derive(FromQueryResult, Deserialize, Serialize)] +#[derive(Debug, FromQueryResult, Deserialize, Serialize)] pub struct Transit { transit: Option, } +#[derive(Debug)] pub enum BNAComponentValue { All(Bna), Summary(Summary), @@ -146,6 +147,7 @@ pub async fn fetch_ratings_summary_with_parts( ) -> Result, sea_orm::DbErr> { let select = summary::Entity::find_by_id(rating_id); let component = component.unwrap_or(BNAComponent::All); + dbg!(&component); let res = match component { BNAComponent::All => select .clone() diff --git a/lambdas/src/core/resource/ratings/endpoint.rs b/lambdas/src/core/resource/ratings/endpoint.rs index 5ebb3d9..3901ccf 100644 --- a/lambdas/src/core/resource/ratings/endpoint.rs +++ b/lambdas/src/core/resource/ratings/endpoint.rs @@ -16,6 +16,7 @@ use axum::{ use effortless::api::PaginationParameters; use entity::wrappers::bna_pipeline::{BNAPipelinePatch, BNAPipelinePost}; use serde_json::{json, Value}; +use tracing::debug; use uuid::Uuid; pub fn routes() -> Router { @@ -53,6 +54,10 @@ async fn get_rating( get_rating_adaptor(rating_id, component, ctx) .await + .map_err(|e| { + debug!("{e}"); + e + }) .map(|v| Json(json!(v))) } diff --git a/lambdas/src/main.rs b/lambdas/src/main.rs index 90f57d0..a8b649f 100644 --- a/lambdas/src/main.rs +++ b/lambdas/src/main.rs @@ -13,9 +13,18 @@ async fn main() -> Result<(), Error> { // i.e with: `GET /test-stage/todo/id/123` without: `GET /todo/id/123` set_var("AWS_LAMBDA_HTTP_IGNORE_STAGE_IN_PATH", "true"); + // Check for user-defined log level. + let log_level = match env::var("BNA_API_LOG_LEVEL") { + Ok(v) => match v.to_ascii_lowercase().as_str() { + "debug" => tracing::Level::DEBUG, + _ => tracing::Level::INFO, + }, + Err(_) => tracing::Level::INFO, + }; + // required to enable CloudWatch error logging by the runtime tracing_subscriber::fmt() - .with_max_level(tracing::Level::INFO) + .with_max_level(log_level) // disable printing the name of the module in every log line. .with_target(false) // disabling time is handy because CloudWatch will add the ingestion time. diff --git a/lambdas/tests/endpoints/pricing.hurl b/lambdas/tests/endpoints/pricing.hurl new file mode 100644 index 0000000..0b052ce --- /dev/null +++ b/lambdas/tests/endpoints/pricing.hurl @@ -0,0 +1,14 @@ +# Queries the first page of the fargate prices. +GET {{host}}/prices/fargate + +HTTP 200 +[Asserts] +jsonpath "$" count > 0 +[Captures] +price_id: jsonpath "$.[0].id" + + +# Queries a specific fargate price. +GET {{host}}/prices/fargate/{{price_id}} + +HTTP 200