Skip to content

Commit

Permalink
Fix POST /ratings/analyses
Browse files Browse the repository at this point in the history
Fixes the endpoint for POSTing new analyses.

This involved fixing the following items:
- the OAS3 itself
- the entity wrappers
- the seeder

And regenerating the bna-client.

A significant change was switching to chrono instead of time.rs.

Signed-off-by: Rémy Greinhofer <[email protected]>
  • Loading branch information
rgreinho committed Dec 7, 2024
1 parent 8cd0240 commit f286fcf
Show file tree
Hide file tree
Showing 35 changed files with 1,589 additions and 1,162 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ serde_json = "1.0.132"
serde_plain = "1.0.2"
serde_with = "3.11.0"
thiserror = "2.0.3"
time = "0.3.37"
tokio = "1.41.0"
tracing = "0.1"
tracing-subscriber = { version = "0.3", default-features = false }
Expand Down
2,529 changes: 1,487 additions & 1,042 deletions bnaclient/src/lib.rs

Large diffs are not rendered by default.

37 changes: 28 additions & 9 deletions bnaclient/src/progenitor_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct ResponseValue<T> {

impl<T: DeserializeOwned> ResponseValue<T> {
#[doc(hidden)]
pub async fn from_response<E: std::fmt::Debug>(
pub async fn from_response<E>(
response: reqwest::Response,
) -> Result<Self, Error<E>> {
let status = response.status();
Expand Down Expand Up @@ -258,6 +258,9 @@ pub enum Error<E = ()> {

/// An error occurred in the processing of a request pre-hook.
PreHookError(String),

/// An error occurred in the processing of a request post-hook.
PostHookError(String),
}

impl<E> Error<E> {
Expand All @@ -266,6 +269,7 @@ impl<E> Error<E> {
match self {
Error::InvalidRequest(_) => None,
Error::PreHookError(_) => None,
Error::PostHookError(_) => None,
Error::CommunicationError(e) => e.status(),
Error::ErrorResponse(rv) => Some(rv.status()),
Error::InvalidUpgrade(e) => e.status(),
Expand All @@ -283,6 +287,7 @@ impl<E> Error<E> {
match self {
Error::InvalidRequest(s) => Error::InvalidRequest(s),
Error::PreHookError(s) => Error::PreHookError(s),
Error::PostHookError(s) => Error::PostHookError(s),
Error::CommunicationError(e) => Error::CommunicationError(e),
Error::ErrorResponse(ResponseValue {
inner: _,
Expand Down Expand Up @@ -322,31 +327,45 @@ where
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::InvalidRequest(s) => {
write!(f, "Invalid Request: {}", s)
write!(f, "Invalid Request: {}", s)?;
}
Error::CommunicationError(e) => {
write!(f, "Communication Error: {}", e)
write!(f, "Communication Error: {}", e)?;
}
Error::ErrorResponse(rve) => {
write!(f, "Error Response: ")?;
rve.fmt_info(f)
rve.fmt_info(f)?;
}
Error::InvalidUpgrade(e) => {
write!(f, "Invalid Response Upgrade: {}", e)
write!(f, "Invalid Response Upgrade: {}", e)?;
}
Error::ResponseBodyError(e) => {
write!(f, "Invalid Response Body Bytes: {}", e)
write!(f, "Invalid Response Body Bytes: {}", e)?;
}
Error::InvalidResponsePayload(b, e) => {
write!(f, "Invalid Response Payload ({:?}): {}", b, e)
write!(f, "Invalid Response Payload ({:?}): {}", b, e)?;
}
Error::UnexpectedResponse(r) => {
write!(f, "Unexpected Response: {:?}", r)
write!(f, "Unexpected Response: {:?}", r)?;
}
Error::PreHookError(s) => {
write!(f, "Pre-hook Error: {}", s)
write!(f, "Pre-hook Error: {}", s)?;
}
Error::PostHookError(s) => {
write!(f, "Post-hook Error: {}", s)?;
}
}

if f.alternate() {
use std::error::Error as _;

let mut src = self.source().and_then(|e| e.source());
while let Some(s) = src {
write!(f, ": {s}")?;
src = s.source();
}
}
Ok(())
}
}

Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/approval_status.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
6 changes: 3 additions & 3 deletions entity/src/entities/bna_pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand All @@ -14,8 +14,8 @@ pub struct Model {
pub fargate_task_arn: Option<String>,
pub s3_bucket: Option<String>,
pub status: String,
pub start_time: TimeDateTimeWithTimeZone,
pub end_time: Option<TimeDateTimeWithTimeZone>,
pub start_time: DateTimeWithTimeZone,
pub end_time: Option<DateTimeWithTimeZone>,
pub torn_down: Option<bool>,
pub results_posted: Option<bool>,
pub cost: Option<Decimal>,
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/bna_pipeline_status.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/bna_pipeline_step.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/bna_region.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
4 changes: 2 additions & 2 deletions entity/src/entities/census.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand All @@ -9,7 +9,7 @@ pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub city_id: Uuid,
pub created_at: TimeDateTimeWithTimeZone,
pub created_at: DateTimeWithTimeZone,
pub fips_code: String,
pub pop_size: i32,
pub population: i32,
Expand Down
6 changes: 3 additions & 3 deletions entity/src/entities/city.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand All @@ -21,8 +21,8 @@ pub struct Model {
pub region: Option<String>,
pub state_abbrev: Option<String>,
pub speed_limit: Option<i32>,
pub created_at: TimeDateTimeWithTimeZone,
pub updated_at: Option<TimeDateTimeWithTimeZone>,
pub created_at: DateTimeWithTimeZone,
pub updated_at: Option<DateTimeWithTimeZone>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/core_services.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/country.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
4 changes: 2 additions & 2 deletions entity/src/entities/fargate_price.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand All @@ -9,7 +9,7 @@ pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub per_second: Decimal,
pub created_at: TimeDateTimeWithTimeZone,
pub created_at: DateTimeWithTimeZone,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/infrastructure.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
pub mod prelude;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/opportunity.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/people.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
pub use super::approval_status::Entity as ApprovalStatus;
pub use super::bna_pipeline::Entity as BnaPipeline;
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/recreation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/retail.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
4 changes: 2 additions & 2 deletions entity/src/entities/speed_limit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand All @@ -9,7 +9,7 @@ pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub city_id: Uuid,
pub created_at: TimeDateTimeWithTimeZone,
pub created_at: DateTimeWithTimeZone,
pub residential: i32,
}

Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/state_region_crosswalk.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
4 changes: 2 additions & 2 deletions entity/src/entities/submission.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand All @@ -19,7 +19,7 @@ pub struct Model {
pub fips_code: String,
pub consent: bool,
pub status: String,
pub created_at: TimeDateTimeWithTimeZone,
pub created_at: DateTimeWithTimeZone,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
4 changes: 2 additions & 2 deletions entity/src/entities/summary.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand All @@ -9,7 +9,7 @@ pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub city_id: Uuid,
pub created_at: TimeDateTimeWithTimeZone,
pub created_at: DateTimeWithTimeZone,
#[sea_orm(column_type = "Double")]
pub score: f64,
pub version: String,
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/transit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/us_state.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
10 changes: 5 additions & 5 deletions entity/src/wrappers/bna_pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use crate::entities::bna_pipeline;
use sea_orm::{
prelude::{Decimal, Json, TimeDateTimeWithTimeZone, Uuid},
prelude::{DateTimeWithTimeZone, Decimal, Json, Uuid},
ActiveValue, IntoActiveModel,
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct BNAPipelinePost {
pub cost: Option<Decimal>,
pub end_time: Option<TimeDateTimeWithTimeZone>,
pub end_time: Option<DateTimeWithTimeZone>,
pub fargate_price_id: Option<i32>,
pub fargate_task_arn: Option<String>,
pub result_posted: Option<bool>,
pub s3_bucket: Option<String>,
pub sqs_message: Option<Json>,
pub start_time: TimeDateTimeWithTimeZone,
pub start_time: DateTimeWithTimeZone,
pub state_machine_id: Uuid,
pub step: Option<String>,
pub torn_down: Option<bool>,
Expand Down Expand Up @@ -42,13 +42,13 @@ impl IntoActiveModel<bna_pipeline::ActiveModel> for BNAPipelinePost {
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct BNAPipelinePatch {
pub cost: Option<Option<Decimal>>,
pub end_time: Option<Option<TimeDateTimeWithTimeZone>>,
pub end_time: Option<Option<DateTimeWithTimeZone>>,
pub fargate_price_id: Option<Option<i32>>,
pub fargate_task_arn: Option<Option<String>>,
pub result_posted: Option<Option<bool>>,
pub s3_bucket: Option<Option<String>>,
pub sqs_message: Option<Option<Json>>,
pub start_time: Option<Option<TimeDateTimeWithTimeZone>>,
pub start_time: Option<Option<DateTimeWithTimeZone>>,
pub status: Option<String>,
pub step: Option<Option<String>>,
pub torn_down: Option<Option<bool>>,
Expand Down
7 changes: 6 additions & 1 deletion examples/seeder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use bnacore::{
scorecard::{scorecard24::ScoreCard24, Scorecard},
versioning::Calver,
};
use chrono::{DateTime, FixedOffset};
use color_eyre::{eyre::Report, Result};
use csv::Reader;
use dotenv::dotenv;
Expand Down Expand Up @@ -81,7 +82,11 @@ async fn main() -> Result<(), Report> {
let version = Calver::try_from_ubuntu(&calver).unwrap();

// Get the records creation date.
let created_at = scorecard.creation_date;
let created_at = scorecard
.creation_date
.to_string()
.parse::<DateTime<FixedOffset>>()
.unwrap();

// Get the City UUID.
let city_uuid = Uuid::parse_str(&scorecard.bna_id).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ db-generate-models:
sea-orm-cli generate entity \
-o {{ entites }} \
--with-serde both \
--date-time-crate time
--date-time-crate chrono


# Apply migrations and seed the database.
Expand Down
3 changes: 2 additions & 1 deletion lambdas/requests.rest
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@host=https://api.peopleforbikes.xyz
# @host=http://localhost:3000
# Austin, TX, USA.
@city_id=ef8384d5-b96f-439d-a83b-bc801735ddc6
@rating_id=1a759b85-cd87-4bb1-9efa-5789e38e9982
Expand Down Expand Up @@ -148,7 +149,7 @@ Authorization: Bearer {{cognito_access}}
@state_machine_id=e6aade5a-b343-120b-dbaa-bd916cd99221

### Create a new BNA analysis performed by the Brokenspoke-analyzer pipeline.
POST {{host}}/ratings/analysis
POST {{host}}/ratings/analyses
content-type: application/json
Authorization: Bearer {{cognito_access}}

Expand Down
Loading

0 comments on commit f286fcf

Please sign in to comment.