Skip to content

Commit

Permalink
Refactor /cities endpoints
Browse files Browse the repository at this point in the history
Refactors the /cities endpoints.

Signed-off-by: Rémy Greinhofer <[email protected]>
  • Loading branch information
rgreinho committed Aug 8, 2024
1 parent 1ea73b4 commit 6ecad18
Show file tree
Hide file tree
Showing 34 changed files with 150 additions and 219 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ nom = "7.1.3"
once_cell = "1.17.1"
reqwest = "0.12.1"
rstest = "0.22.0"
sea-orm = "0.12.1"
sea-orm = "1"
sea-orm-migration = "1.0.0"
serde = "1.0.159"
serde_json = "1.0.95"
Expand Down
4 changes: 2 additions & 2 deletions entity/src/entities/census.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
#[sea_orm(table_name = "census")]
pub struct Model {
#[sea_orm(primary_key)]
pub census_id: i32,
pub id: i32,
pub city_id: Uuid,
pub created_at: TimeDateTimeWithTimeZone,
pub fips_code: String,
Expand All @@ -20,7 +20,7 @@ pub enum Relation {
#[sea_orm(
belongs_to = "super::city::Entity",
from = "Column::CityId",
to = "super::city::Column::CityId",
to = "super::city::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/city.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
#[sea_orm(table_name = "city")]
pub struct Model {
#[sea_orm(unique)]
pub city_id: Uuid,
pub id: Uuid,
#[sea_orm(primary_key, auto_increment = false)]
pub country: String,
#[sea_orm(primary_key, auto_increment = false)]
Expand Down
6 changes: 3 additions & 3 deletions entity/src/entities/core_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
#[sea_orm(table_name = "core_services")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub bna_uuid: Uuid,
pub bna_id: Uuid,
#[sea_orm(column_type = "Double", nullable)]
pub dentists: Option<f64>,
#[sea_orm(column_type = "Double", nullable)]
Expand All @@ -28,8 +28,8 @@ pub struct Model {
pub enum Relation {
#[sea_orm(
belongs_to = "super::summary::Entity",
from = "Column::BnaUuid",
to = "super::summary::Column::BnaUuid",
from = "Column::BnaId",
to = "super::summary::Column::BnaId",
on_update = "NoAction",
on_delete = "Cascade"
)]
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/country.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
#[sea_orm(table_name = "country")]
pub struct Model {
#[sea_orm(primary_key)]
pub country_id: i32,
pub id: i32,
#[sea_orm(unique)]
pub name: String,
}
Expand Down
6 changes: 3 additions & 3 deletions entity/src/entities/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
#[sea_orm(table_name = "features")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub bna_uuid: Uuid,
pub bna_id: Uuid,
#[sea_orm(column_type = "Double", nullable)]
pub people: Option<f64>,
#[sea_orm(column_type = "Double", nullable)]
Expand All @@ -20,8 +20,8 @@ pub struct Model {
pub enum Relation {
#[sea_orm(
belongs_to = "super::summary::Entity",
from = "Column::BnaUuid",
to = "super::summary::Column::BnaUuid",
from = "Column::BnaId",
to = "super::summary::Column::BnaId",
on_update = "NoAction",
on_delete = "Cascade"
)]
Expand Down
6 changes: 3 additions & 3 deletions entity/src/entities/infrastructure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
#[sea_orm(table_name = "infrastructure")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub bna_uuid: Uuid,
pub bna_id: Uuid,
#[sea_orm(column_type = "Double", nullable)]
pub low_stress_miles: Option<f64>,
#[sea_orm(column_type = "Double", nullable)]
Expand All @@ -18,8 +18,8 @@ pub struct Model {
pub enum Relation {
#[sea_orm(
belongs_to = "super::summary::Entity",
from = "Column::BnaUuid",
to = "super::summary::Column::BnaUuid",
from = "Column::BnaId",
to = "super::summary::Column::BnaId",
on_update = "NoAction",
on_delete = "Cascade"
)]
Expand Down
6 changes: 3 additions & 3 deletions entity/src/entities/opportunity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
#[sea_orm(table_name = "opportunity")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub bna_uuid: Uuid,
pub bna_id: Uuid,
#[sea_orm(column_type = "Double", nullable)]
pub employment: Option<f64>,
#[sea_orm(column_type = "Double", nullable)]
Expand All @@ -24,8 +24,8 @@ pub struct Model {
pub enum Relation {
#[sea_orm(
belongs_to = "super::summary::Entity",
from = "Column::BnaUuid",
to = "super::summary::Column::BnaUuid",
from = "Column::BnaId",
to = "super::summary::Column::BnaId",
on_update = "NoAction",
on_delete = "Cascade"
)]
Expand Down
6 changes: 3 additions & 3 deletions entity/src/entities/recreation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
#[sea_orm(table_name = "recreation")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub bna_uuid: Uuid,
pub bna_id: Uuid,
#[sea_orm(column_type = "Double", nullable)]
pub community_centers: Option<f64>,
#[sea_orm(column_type = "Double", nullable)]
Expand All @@ -22,8 +22,8 @@ pub struct Model {
pub enum Relation {
#[sea_orm(
belongs_to = "super::summary::Entity",
from = "Column::BnaUuid",
to = "super::summary::Column::BnaUuid",
from = "Column::BnaId",
to = "super::summary::Column::BnaId",
on_update = "NoAction",
on_delete = "Cascade"
)]
Expand Down
4 changes: 2 additions & 2 deletions entity/src/entities/speed_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
#[sea_orm(table_name = "speed_limit")]
pub struct Model {
#[sea_orm(primary_key)]
pub speed_limit_id: i32,
pub id: i32,
pub city_id: Uuid,
pub created_at: TimeDateTimeWithTimeZone,
pub residential: i32,
Expand All @@ -18,7 +18,7 @@ pub enum Relation {
#[sea_orm(
belongs_to = "super::city::Entity",
from = "Column::CityId",
to = "super::city::Column::CityId",
to = "super::city::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/submission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct Model {
pub id: i32,
pub first_name: String,
pub last_name: String,
pub title: Option<String>,
pub occupation: Option<String>,
pub organization: Option<String>,
pub email: String,
pub country: String,
Expand Down
4 changes: 2 additions & 2 deletions entity/src/entities/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
#[sea_orm(table_name = "summary")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub bna_uuid: Uuid,
pub bna_id: Uuid,
pub city_id: Uuid,
pub created_at: TimeDateTimeWithTimeZone,
#[sea_orm(column_type = "Double")]
Expand All @@ -20,7 +20,7 @@ pub enum Relation {
#[sea_orm(
belongs_to = "super::city::Entity",
from = "Column::CityId",
to = "super::city::Column::CityId",
to = "super::city::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
Expand Down
4 changes: 2 additions & 2 deletions entity/src/wrappers/census.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct CensusPost {
impl IntoActiveModel<census::ActiveModel> for CensusPost {
fn into_active_model(self) -> census::ActiveModel {
census::ActiveModel {
census_id: ActiveValue::NotSet,
id: ActiveValue::NotSet,
city_id: ActiveValue::Set(self.city_id),
created_at: ActiveValue::NotSet,
fips_code: ActiveValue::Set(self.fips_code),
Expand All @@ -31,7 +31,7 @@ pub struct CensusPatch {
impl IntoActiveModel<census::ActiveModel> for CensusPatch {
fn into_active_model(self) -> census::ActiveModel {
census::ActiveModel {
census_id: ActiveValue::NotSet,
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),
Expand Down
4 changes: 2 additions & 2 deletions entity/src/wrappers/city.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct CityPost {
impl IntoActiveModel<city::ActiveModel> for CityPost {
fn into_active_model(self) -> city::ActiveModel {
city::ActiveModel {
city_id: ActiveValue::NotSet,
id: ActiveValue::NotSet,
country: ActiveValue::Set(self.country),
latitude: ActiveValue::Set(self.latitude),
longitude: ActiveValue::Set(self.longitude),
Expand Down Expand Up @@ -47,7 +47,7 @@ pub struct CityPatch {
impl IntoActiveModel<city::ActiveModel> for CityPatch {
fn into_active_model(self) -> city::ActiveModel {
city::ActiveModel {
city_id: ActiveValue::NotSet,
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),
Expand Down
24 changes: 13 additions & 11 deletions entity/src/wrappers/submission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
pub struct SubmissionPost {
pub first_name: String,
pub last_name: String,
pub title: Option<String>,
pub occupation: Option<String>,
pub organization: Option<String>,
pub email: String,
pub country: String,
Expand All @@ -23,7 +23,7 @@ impl IntoActiveModel<submission::ActiveModel> for SubmissionPost {
id: ActiveValue::NotSet,
first_name: ActiveValue::Set(self.first_name),
last_name: ActiveValue::Set(self.last_name),
title: ActiveValue::Set(self.title),
occupation: ActiveValue::Set(self.occupation),
organization: ActiveValue::Set(self.organization),
email: ActiveValue::Set(self.email),
country: ActiveValue::Set(self.country),
Expand All @@ -41,7 +41,7 @@ impl IntoActiveModel<submission::ActiveModel> for SubmissionPost {
pub struct SubmissionPatch {
pub first_name: Option<String>,
pub last_name: Option<String>,
pub title: Option<Option<String>>,
pub occupation: Option<Option<String>>,
pub organization: Option<Option<String>>,
pub email: Option<String>,
pub country: Option<String>,
Expand All @@ -60,7 +60,9 @@ impl IntoActiveModel<submission::ActiveModel> for SubmissionPatch {
.first_name
.map_or(ActiveValue::NotSet, ActiveValue::Set),
last_name: self.last_name.map_or(ActiveValue::NotSet, ActiveValue::Set),
title: self.title.map_or(ActiveValue::NotSet, ActiveValue::Set),
occupation: self
.occupation
.map_or(ActiveValue::NotSet, ActiveValue::Set),
organization: self
.organization
.map_or(ActiveValue::NotSet, ActiveValue::Set),
Expand All @@ -84,7 +86,7 @@ mod tests {
fn test_submission_post_into_active_model_full() {
let first_name = "John".to_string();
let last_name = "Doe".to_string();
let title = Some("Director".to_owned());
let occupation = Some("Director".to_owned());
let organization = Some("ACME".to_string());
let email = "[email protected]".to_string();
let country = "usa".to_string();
Expand All @@ -96,7 +98,7 @@ mod tests {
let wrapper = SubmissionPost {
first_name: first_name.clone(),
last_name: last_name.clone(),
title: title.clone(),
occupation: occupation.clone(),
organization: organization.clone(),
email: email.clone(),
country: country.clone(),
Expand All @@ -111,7 +113,7 @@ mod tests {
id: ActiveValue::NotSet,
first_name: ActiveValue::Set(first_name),
last_name: ActiveValue::Set(last_name),
title: ActiveValue::Set(title),
occupation: ActiveValue::Set(occupation),
organization: ActiveValue::Set(organization),
email: ActiveValue::Set(email),
country: ActiveValue::Set(country),
Expand Down Expand Up @@ -141,7 +143,7 @@ mod tests {
let wrapper = SubmissionPost {
first_name: first_name.clone(),
last_name: last_name.clone(),
title: title.clone(),
occupation: title.clone(),
organization: organization.clone(),
email: email.clone(),
country: country.clone(),
Expand All @@ -156,7 +158,7 @@ mod tests {
id: ActiveValue::NotSet,
first_name: ActiveValue::Set(first_name),
last_name: ActiveValue::Set(last_name),
title: ActiveValue::Set(title),
occupation: ActiveValue::Set(title),
organization: ActiveValue::Set(organization),
email: ActiveValue::Set(email),
country: ActiveValue::Set(country),
Expand All @@ -176,7 +178,7 @@ mod tests {
let wrapper = SubmissionPatch {
first_name: Some(first_name.clone()),
last_name: None,
title: None,
occupation: None,
organization: None,
email: None,
country: None,
Expand All @@ -191,7 +193,7 @@ mod tests {
id: ActiveValue::NotSet,
first_name: ActiveValue::Set(first_name),
last_name: ActiveValue::NotSet,
title: ActiveValue::NotSet,
occupation: ActiveValue::NotSet,
organization: ActiveValue::NotSet,
email: ActiveValue::NotSet,
country: ActiveValue::NotSet,
Expand Down
2 changes: 1 addition & 1 deletion examples/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async fn main() -> Result<(), Report> {
id: ActiveValue::NotSet,
first_name: ActiveValue::Set("Floyd".to_string()),
last_name: ActiveValue::Set("Martin".to_string()),
title: ActiveValue::Set(None),
occupation: ActiveValue::Set(None),
organization: ActiveValue::Set(Some("organization".to_string())),
email: ActiveValue::Set("[email protected]".to_string()),
country: ActiveValue::Set("usa".to_string()),
Expand Down
Loading

0 comments on commit 6ecad18

Please sign in to comment.