generated from PeopleForBikes/bna-mechanics-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Adds endpoints to: - get the city census details - get partial/full bna results - post a new bna result Signed-off-by: Rémy Greinhofer <[email protected]>
- Loading branch information
Showing
24 changed files
with
1,090 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use sea_orm::prelude::Uuid; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct BNASummary { | ||
pub bna_uuid: Uuid, | ||
pub city_id: Uuid, | ||
pub score: f64, | ||
pub version: String, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct BNAInfrastructure { | ||
pub low_stress_miles: Option<f64>, | ||
pub high_stress_miles: Option<f64>, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct BNARecreation { | ||
pub community_centers: Option<f64>, | ||
pub parks: Option<f64>, | ||
pub recreation_trails: Option<f64>, | ||
pub score: Option<f64>, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct BNAOpportunity { | ||
pub employment: Option<f64>, | ||
pub higher_education: Option<f64>, | ||
pub k12_education: Option<f64>, | ||
pub score: Option<f64>, | ||
pub technical_vocational_college: Option<f64>, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct BNACoreServices { | ||
pub dentists: Option<f64>, | ||
pub doctors: Option<f64>, | ||
pub grocery: Option<f64>, | ||
pub hospitals: Option<f64>, | ||
pub pharmacies: Option<f64>, | ||
pub score: Option<f64>, | ||
pub social_services: Option<f64>, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct BNAFeatures { | ||
pub people: Option<f64>, | ||
pub retail: Option<f64>, | ||
pub transit: Option<f64>, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct BNAPost { | ||
pub core_services: BNACoreServices, | ||
pub features: BNAFeatures, | ||
pub infrastructure: BNAInfrastructure, | ||
pub opportunity: BNAOpportunity, | ||
pub recreation: BNARecreation, | ||
pub summary: BNASummary, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
pub struct BNAPatch { | ||
pub core_services: BNACoreServices, | ||
pub features: BNAFeatures, | ||
pub infrastructure: BNAInfrastructure, | ||
pub opportunity: BNAOpportunity, | ||
pub recreation: BNARecreation, | ||
pub summary: BNASummary, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use crate::entities::{brokenspoke_pipeline, sea_orm_active_enums}; | ||
use sea_orm::{ | ||
prelude::{Json, TimeDateTimeWithTimeZone, Uuid}, | ||
ActiveValue, IntoActiveModel, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct BrokenspokePipelinePost { | ||
pub state: Option<sea_orm_active_enums::BrokenspokeState>, | ||
pub state_machine_id: Uuid, | ||
pub scheduled_trigger_id: Option<Uuid>, | ||
pub sqs_message: Option<Json>, | ||
pub neon_branch_id: Option<String>, | ||
pub fargate_task_arn: Option<String>, | ||
pub s3_bucket: Option<String>, | ||
pub start_time: TimeDateTimeWithTimeZone, | ||
pub end_time: Option<TimeDateTimeWithTimeZone>, | ||
pub torn_down: Option<bool>, | ||
} | ||
|
||
impl IntoActiveModel<brokenspoke_pipeline::ActiveModel> for BrokenspokePipelinePost { | ||
fn into_active_model(self) -> brokenspoke_pipeline::ActiveModel { | ||
brokenspoke_pipeline::ActiveModel { | ||
state: ActiveValue::Set(self.state), | ||
state_machine_id: ActiveValue::Set(self.state_machine_id), | ||
sqs_message: ActiveValue::Set(self.sqs_message), | ||
neon_branch_id: ActiveValue::Set(self.neon_branch_id), | ||
fargate_task_arn: ActiveValue::Set(self.fargate_task_arn), | ||
s3_bucket: ActiveValue::Set(self.s3_bucket), | ||
scheduled_trigger_id: ActiveValue::Set(self.scheduled_trigger_id), | ||
start_time: ActiveValue::Set(self.start_time), | ||
end_time: ActiveValue::Set(self.end_time), | ||
torn_down: ActiveValue::Set(self.torn_down), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct BrokenspokePipelinePatch { | ||
pub state: Option<Option<sea_orm_active_enums::BrokenspokeState>>, | ||
pub scheduled_trigger_id: Option<Option<Uuid>>, | ||
pub sqs_message: Option<Option<Json>>, | ||
pub neon_branch_id: Option<Option<String>>, | ||
pub fargate_task_arn: Option<Option<String>>, | ||
pub s3_bucket: Option<Option<String>>, | ||
pub start_time: Option<Option<TimeDateTimeWithTimeZone>>, | ||
pub end_time: Option<Option<TimeDateTimeWithTimeZone>>, | ||
pub torn_down: Option<Option<bool>>, | ||
} | ||
|
||
impl IntoActiveModel<brokenspoke_pipeline::ActiveModel> for BrokenspokePipelinePatch { | ||
fn into_active_model(self) -> brokenspoke_pipeline::ActiveModel { | ||
brokenspoke_pipeline::ActiveModel { | ||
state_machine_id: ActiveValue::NotSet, | ||
state: self.state.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
sqs_message: self | ||
.sqs_message | ||
.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
neon_branch_id: self | ||
.neon_branch_id | ||
.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
fargate_task_arn: self | ||
.fargate_task_arn | ||
.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
s3_bucket: self.s3_bucket.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
scheduled_trigger_id: self | ||
.scheduled_trigger_id | ||
.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
start_time: ActiveValue::NotSet, | ||
end_time: self.end_time.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
torn_down: self.torn_down.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use crate::census; | ||
use sea_orm::{prelude::Uuid, ActiveValue, IntoActiveModel}; | ||
|
||
pub struct CensusPost { | ||
pub city_id: Uuid, | ||
pub fips_code: String, | ||
pub pop_size: i32, | ||
pub population: i32, | ||
} | ||
|
||
impl IntoActiveModel<census::ActiveModel> for CensusPost { | ||
fn into_active_model(self) -> census::ActiveModel { | ||
census::ActiveModel { | ||
census_id: ActiveValue::NotSet, | ||
city_id: ActiveValue::Set(self.city_id), | ||
created_at: ActiveValue::NotSet, | ||
fips_code: ActiveValue::Set(self.fips_code), | ||
pop_size: ActiveValue::Set(self.pop_size), | ||
population: ActiveValue::Set(self.population), | ||
} | ||
} | ||
} | ||
|
||
pub struct CensusPatch { | ||
pub city_id: Option<Uuid>, | ||
pub fips_code: Option<String>, | ||
pub pop_size: Option<i32>, | ||
pub population: Option<i32>, | ||
} | ||
|
||
impl IntoActiveModel<census::ActiveModel> for CensusPatch { | ||
fn into_active_model(self) -> census::ActiveModel { | ||
census::ActiveModel { | ||
census_id: ActiveValue::NotSet, | ||
city_id: self.city_id.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
created_at: ActiveValue::NotSet, | ||
fips_code: self.fips_code.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
pop_size: self.pop_size.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
population: self | ||
.population | ||
.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use crate::city; | ||
use sea_orm::{ActiveValue, IntoActiveModel}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
pub struct CityPost { | ||
pub country: String, | ||
pub latitude: f64, | ||
pub longitude: f64, | ||
pub name: String, | ||
pub region: String, | ||
pub state: String, | ||
pub state_abbrev: Option<String>, | ||
pub speed_limit: Option<i32>, | ||
} | ||
|
||
impl IntoActiveModel<city::ActiveModel> for CityPost { | ||
fn into_active_model(self) -> city::ActiveModel { | ||
city::ActiveModel { | ||
city_id: ActiveValue::NotSet, | ||
country: ActiveValue::Set(self.country), | ||
latitude: ActiveValue::Set(self.latitude), | ||
longitude: ActiveValue::Set(self.longitude), | ||
name: ActiveValue::Set(self.name), | ||
region: ActiveValue::Set(self.region), | ||
state: ActiveValue::Set(self.state), | ||
state_abbrev: ActiveValue::Set(self.state_abbrev), | ||
speed_limit: ActiveValue::Set(self.speed_limit), | ||
created_at: ActiveValue::NotSet, | ||
updated_at: ActiveValue::NotSet, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
pub struct CityPatch { | ||
pub country: Option<String>, | ||
pub latitude: Option<f64>, | ||
pub longitude: Option<f64>, | ||
pub name: Option<String>, | ||
pub region: Option<String>, | ||
pub state: Option<String>, | ||
pub state_abbrev: Option<Option<String>>, | ||
pub speed_limit: Option<Option<i32>>, | ||
} | ||
|
||
impl IntoActiveModel<city::ActiveModel> for CityPatch { | ||
fn into_active_model(self) -> city::ActiveModel { | ||
city::ActiveModel { | ||
city_id: ActiveValue::NotSet, | ||
country: self.country.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
latitude: self.latitude.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
longitude: self.longitude.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
name: self.name.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
region: self.region.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
state: self.state.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
state_abbrev: self | ||
.state_abbrev | ||
.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
speed_limit: self | ||
.speed_limit | ||
.map_or(ActiveValue::NotSet, ActiveValue::Set), | ||
created_at: ActiveValue::NotSet, | ||
updated_at: ActiveValue::NotSet, | ||
} | ||
} | ||
} |
Oops, something went wrong.