Skip to content

Commit

Permalink
Fix BnaPost wrapper
Browse files Browse the repository at this point in the history
Fixes the wrapper's fields to match the database.

Drive-bys:
- Fixes the OAS.
- Regenerates the client.

Signed-off-by: Rémy Greinhofer <[email protected]>
  • Loading branch information
rgreinho committed Dec 8, 2024
1 parent 9c2ce02 commit c3505be
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 58 deletions.
50 changes: 25 additions & 25 deletions bnaclient/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ pub mod types {
/// "type": "object",
/// "required": [
/// "city_id",
/// "rating_id",
/// "id",
/// "score",
/// "version"
/// ],
Expand Down Expand Up @@ -763,6 +763,14 @@ pub mod types {
/// "null"
/// ]
/// },
/// "id": {
/// "description": "Analysis identifier",
/// "examples": [
/// "1a759b85-cd87-4bb1-9efa-5789e38e9982"
/// ],
/// "type": "string",
/// "format": "uuid"
/// },
/// "k12_education": {
/// "description": "BNA category subscore for access to k12 schools",
/// "examples": [
Expand Down Expand Up @@ -826,14 +834,6 @@ pub mod types {
/// "null"
/// ]
/// },
/// "rating_id": {
/// "description": "Analysis identifier",
/// "examples": [
/// "1a759b85-cd87-4bb1-9efa-5789e38e9982"
/// ],
/// "type": "string",
/// "format": "uuid"
/// },
/// "recreation_score": {
/// "description": "BNA category score for access to recreational
/// facilities",
Expand Down Expand Up @@ -949,6 +949,8 @@ pub mod types {
///BNA category subscore for access to hospitals
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub hospitals: ::std::option::Option<f64>,
///Analysis identifier
pub id: uuid::Uuid,
///BNA category subscore for access to k12 schools
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub k12_education: ::std::option::Option<f64>,
Expand All @@ -967,8 +969,6 @@ pub mod types {
///BNA category subscore for access to pharmacies
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub pharmacies: ::std::option::Option<f64>,
///Analysis identifier
pub rating_id: uuid::Uuid,
///BNA category score for access to recreational facilities
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub recreation_score: ::std::option::Option<f64>,
Expand Down Expand Up @@ -4609,6 +4609,7 @@ pub mod types {
higher_education:
::std::result::Result<::std::option::Option<f64>, ::std::string::String>,
hospitals: ::std::result::Result<::std::option::Option<f64>, ::std::string::String>,
id: ::std::result::Result<uuid::Uuid, ::std::string::String>,
k12_education: ::std::result::Result<::std::option::Option<f64>, ::std::string::String>,
low_stress_miles:
::std::result::Result<::std::option::Option<f64>, ::std::string::String>,
Expand All @@ -4617,7 +4618,6 @@ pub mod types {
parks: ::std::result::Result<::std::option::Option<f64>, ::std::string::String>,
people: ::std::result::Result<::std::option::Option<f64>, ::std::string::String>,
pharmacies: ::std::result::Result<::std::option::Option<f64>, ::std::string::String>,
rating_id: ::std::result::Result<uuid::Uuid, ::std::string::String>,
recreation_score:
::std::result::Result<::std::option::Option<f64>, ::std::string::String>,
recreation_trails:
Expand Down Expand Up @@ -4645,13 +4645,13 @@ pub mod types {
high_stress_miles: Ok(Default::default()),
higher_education: Ok(Default::default()),
hospitals: Ok(Default::default()),
id: Err("no value supplied for id".to_string()),
k12_education: Ok(Default::default()),
low_stress_miles: Ok(Default::default()),
opportunity_score: Ok(Default::default()),
parks: Ok(Default::default()),
people: Ok(Default::default()),
pharmacies: Ok(Default::default()),
rating_id: Err("no value supplied for rating_id".to_string()),
recreation_score: Ok(Default::default()),
recreation_trails: Ok(Default::default()),
retail: Ok(Default::default()),
Expand Down Expand Up @@ -4777,6 +4777,16 @@ pub mod types {
.map_err(|e| format!("error converting supplied value for hospitals: {}", e));
self
}
pub fn id<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<uuid::Uuid>,
T::Error: std::fmt::Display,
{
self.id = value
.try_into()
.map_err(|e| format!("error converting supplied value for id: {}", e));
self
}
pub fn k12_education<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<::std::option::Option<f64>>,
Expand Down Expand Up @@ -4843,16 +4853,6 @@ pub mod types {
.map_err(|e| format!("error converting supplied value for pharmacies: {}", e));
self
}
pub fn rating_id<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<uuid::Uuid>,
T::Error: std::fmt::Display,
{
self.rating_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for rating_id: {}", e));
self
}
pub fn recreation_score<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<::std::option::Option<f64>>,
Expand Down Expand Up @@ -4958,13 +4958,13 @@ pub mod types {
high_stress_miles: value.high_stress_miles?,
higher_education: value.higher_education?,
hospitals: value.hospitals?,
id: value.id?,
k12_education: value.k12_education?,
low_stress_miles: value.low_stress_miles?,
opportunity_score: value.opportunity_score?,
parks: value.parks?,
people: value.people?,
pharmacies: value.pharmacies?,
rating_id: value.rating_id?,
recreation_score: value.recreation_score?,
recreation_trails: value.recreation_trails?,
retail: value.retail?,
Expand All @@ -4990,13 +4990,13 @@ pub mod types {
high_stress_miles: Ok(value.high_stress_miles),
higher_education: Ok(value.higher_education),
hospitals: Ok(value.hospitals),
id: Ok(value.id),
k12_education: Ok(value.k12_education),
low_stress_miles: Ok(value.low_stress_miles),
opportunity_score: Ok(value.opportunity_score),
parks: Ok(value.parks),
people: Ok(value.people),
pharmacies: Ok(value.pharmacies),
rating_id: Ok(value.rating_id),
recreation_score: Ok(value.recreation_score),
recreation_trails: Ok(value.recreation_trails),
retail: Ok(value.retail),
Expand Down
33 changes: 29 additions & 4 deletions entity/src/wrappers/bna.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use crate::{
core_services, infrastructure, opportunity, people, recreation, retail, summary, transit,
};
use sea_orm::prelude::Uuid;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct BNASummary {
pub bna_uuid: Uuid,
pub rating_id: Uuid,
pub city_id: Uuid,
pub score: f64,
pub version: String,
Expand Down Expand Up @@ -93,13 +96,13 @@ pub struct BNATransit {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct BNAPost {
pub core_services: BNACoreServices,
pub people: BNAPeople,
pub retail: BNARetail,
pub transit: BNATransit,
pub infrastructure: BNAInfrastructure,
pub opportunity: BNAOpportunity,
pub people: BNAPeople,
pub recreation: BNARecreation,
pub retail: BNARetail,
pub summary: BNASummary,
pub transit: BNATransit,
}

impl BNAPost {
Expand All @@ -124,3 +127,25 @@ pub struct BNAPatch {
pub recreation: BNARecreation,
pub summary: BNASummary,
}

// Note(rgreinho): This struct is name Rating* because the Bna* structs should/will
// eventually be renamed to Rating*.
#[derive(Debug, Serialize)]
pub struct RatingFlat {
#[serde(flatten)]
pub core_services: core_services::Model,
#[serde(flatten)]
pub infrastructure: infrastructure::Model,
#[serde(flatten)]
pub opportunity: opportunity::Model,
#[serde(flatten)]
pub people: people::Model,
#[serde(flatten)]
pub recreation: recreation::Model,
#[serde(flatten)]
pub retail: retail::Model,
#[serde(flatten)]
pub summary: summary::Model,
#[serde(flatten)]
pub transit: transit::Model,
}
35 changes: 21 additions & 14 deletions lambdas/requests.rest
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@host=https://api.peopleforbikes.xyz
# @host=http://localhost:3000
# @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 @@ -192,34 +192,41 @@ Authorization: Bearer {{cognito_access}}
"grocery": 1.69,
"hospitals": 5.18,
"pharmacies": 0,
"social_services": 0
},
"features": {
"people": 19.17,
"retail": 0,
"transit": 0
"score": 3.24
},
"infrastructure": {
"low_stress_miles": 9.3,
"high_stress_miles": 64.5
"high_stress_miles": 64.5,
"low_stress_miles": 9.3
},
"opportunity": {
"employment": 8.26,
"higher_education": 0,
"k12_education": 8.31,
"score": 8.29,
"technical_vocational_college": 0
},
"people": {
"score": 19.17
},
"recreation": {
"community_centers": 0,
"parks": 7.13,
"recreation_trails": 0
"recreation_trails": 0,
"score": 7.13
},
"retail": {
"score": 0
},
"summary": {
"bna_uuid": "3414afd2-42be-412b-9fce-3597b466e291",
"version": "24.04.8"
"city_id": "aac22433-37d4-4cb7-b6b8-e7e77cbbcf41",
"rating_id": "7b80ac57-f32e-44db-8442-e9cbf449b306",
"score": 0,
"version": "24.12"
},
"transit": {
"score": 0
}
}

### Create a new city.
POST {{host}}/cities/
content-type: application/json
Expand Down
16 changes: 8 additions & 8 deletions lambdas/src/bin/ratings/post-ratings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ async fn function_handler(event: Request) -> Result<Response<Body>, Error> {

// Turn the model wrapper into active models.
let summary = summary::ActiveModel {
id: ActiveValue::Set(wrapper.summary.bna_uuid),
id: ActiveValue::Set(wrapper.summary.rating_id),
city_id: ActiveValue::Set(wrapper.summary.city_id),
created_at: ActiveValue::NotSet,
score: ActiveValue::Set(wrapper.summary.score),
version: ActiveValue::Set(wrapper.summary.version),
};
info!("{:?}", summary);
let core_services = core_services::ActiveModel {
id: ActiveValue::Set(wrapper.summary.bna_uuid),
id: ActiveValue::Set(wrapper.summary.rating_id),
dentists: ActiveValue::Set(wrapper.core_services.dentists),
doctors: ActiveValue::Set(wrapper.core_services.doctors),
grocery: ActiveValue::Set(wrapper.core_services.grocery),
Expand All @@ -65,28 +65,28 @@ async fn function_handler(event: Request) -> Result<Response<Body>, Error> {
};
info!("{:?}", core_services);
let people = people::ActiveModel {
id: ActiveValue::Set(wrapper.summary.bna_uuid),
id: ActiveValue::Set(wrapper.summary.rating_id),
score: ActiveValue::Set(wrapper.people.score),
};
info!("{:?}", people);
let retail = retail::ActiveModel {
id: ActiveValue::Set(wrapper.summary.bna_uuid),
id: ActiveValue::Set(wrapper.summary.rating_id),
score: ActiveValue::Set(wrapper.retail.score),
};
info!("{:?}", people);
let transit = transit::ActiveModel {
id: ActiveValue::Set(wrapper.summary.bna_uuid),
id: ActiveValue::Set(wrapper.summary.rating_id),
score: ActiveValue::Set(wrapper.transit.score),
};
info!("{:?}", people);
let infrastructure = infrastructure::ActiveModel {
id: ActiveValue::Set(wrapper.summary.bna_uuid),
id: ActiveValue::Set(wrapper.summary.rating_id),
low_stress_miles: ActiveValue::Set(wrapper.infrastructure.low_stress_miles),
high_stress_miles: ActiveValue::Set(wrapper.infrastructure.high_stress_miles),
};
info!("{:?}", infrastructure);
let opportunity = opportunity::ActiveModel {
id: ActiveValue::Set(wrapper.summary.bna_uuid),
id: ActiveValue::Set(wrapper.summary.rating_id),
employment: ActiveValue::Set(wrapper.opportunity.employment),
higher_education: ActiveValue::Set(wrapper.opportunity.higher_education),
k12_education: ActiveValue::Set(wrapper.opportunity.k12_education),
Expand All @@ -97,7 +97,7 @@ async fn function_handler(event: Request) -> Result<Response<Body>, Error> {
};
info!("{:?}", opportunity);
let recreation = recreation::ActiveModel {
id: ActiveValue::Set(wrapper.summary.bna_uuid),
id: ActiveValue::Set(wrapper.summary.rating_id),
community_centers: ActiveValue::Set(wrapper.recreation.community_centers),
parks: ActiveValue::Set(wrapper.recreation.parks),
recreation_trails: ActiveValue::Set(wrapper.recreation.recreation_trails),
Expand Down
Loading

0 comments on commit c3505be

Please sign in to comment.