From b7b6b6317381cdf87bfb3a183913431cc16024f2 Mon Sep 17 00:00:00 2001 From: Franklin Date: Thu, 4 May 2023 14:49:00 -0400 Subject: [PATCH] Cargo fmt --- src/dao/project.rs | 12 +++++-- src/dao/property.rs | 22 ++++++++---- src/dao/trackable.rs | 2 +- src/routes/click.rs | 5 ++- src/routes/project.rs | 34 +++++++++++++----- src/routes/property.rs | 78 +++++++++++++++++++++++++++++++---------- src/routes/realtor.rs | 48 +++++++++++++++++++------ src/routes/trackable.rs | 29 ++++++++++----- 8 files changed, 171 insertions(+), 59 deletions(-) diff --git a/src/dao/project.rs b/src/dao/project.rs index f28c1f4..d660b95 100644 --- a/src/dao/project.rs +++ b/src/dao/project.rs @@ -1,8 +1,11 @@ use realtor_lp_types::domain::project::Project; -use sqlx::{PgPool, Transaction, Postgres}; +use sqlx::{PgPool, Postgres, Transaction}; use uuid::Uuid; -pub async fn insert_project<'a>(transaction: &mut Transaction<'a, Postgres>, project: Project) -> Result { +pub async fn insert_project<'a>( + transaction: &mut Transaction<'a, Postgres>, + project: Project, +) -> Result { sqlx::query_file_as!( Project, "sql/project/insert.sql", @@ -45,7 +48,10 @@ pub async fn fetch_with_realtor_id( .await } -pub async fn update_project<'a>(transaction: &mut Transaction<'a, Postgres>, project: Project) -> Result { +pub async fn update_project<'a>( + transaction: &mut Transaction<'a, Postgres>, + project: Project, +) -> Result { sqlx::query_file_as!( Project, "sql/project/update.sql", diff --git a/src/dao/property.rs b/src/dao/property.rs index ddeda81..7a02e54 100644 --- a/src/dao/property.rs +++ b/src/dao/property.rs @@ -1,8 +1,11 @@ use realtor_lp_types::domain::property::Property; -use sqlx::{PgPool, Transaction, Postgres}; +use sqlx::{PgPool, Postgres, Transaction}; use uuid::Uuid; -pub async fn insert_property<'a>(transaction: &mut Transaction<'a, Postgres>, property: Property) -> Result { +pub async fn insert_property<'a>( + transaction: &mut Transaction<'a, Postgres>, + property: Property, +) -> Result { sqlx::query_file_as!( Property, "sql/property/insert.sql", @@ -39,12 +42,19 @@ pub async fn fetch_with_realtor_id( conn: &PgPool, realtor_id: &Uuid, ) -> Result, sqlx::Error> { - sqlx::query_file_as!(Property, "sql/property/fetch_with_realtor_id.sql", realtor_id) - .fetch_all(conn) - .await + sqlx::query_file_as!( + Property, + "sql/property/fetch_with_realtor_id.sql", + realtor_id + ) + .fetch_all(conn) + .await } -pub async fn update_property<'a>(transaction: &mut Transaction<'a, Postgres>, property: Property) -> Result { +pub async fn update_property<'a>( + transaction: &mut Transaction<'a, Postgres>, + property: Property, +) -> Result { sqlx::query_file_as!( Property, "sql/property/update.sql", diff --git a/src/dao/trackable.rs b/src/dao/trackable.rs index 8348523..a7177eb 100644 --- a/src/dao/trackable.rs +++ b/src/dao/trackable.rs @@ -1,5 +1,5 @@ use realtor_lp_types::domain::trackable::Trackable; -use sqlx::{Transaction, Postgres, PgPool}; +use sqlx::{PgPool, Postgres, Transaction}; use uuid::Uuid; pub async fn insert_trackable<'a>( diff --git a/src/routes/click.rs b/src/routes/click.rs index 00492d6..3a1cd90 100644 --- a/src/routes/click.rs +++ b/src/routes/click.rs @@ -2,11 +2,10 @@ use actix_web_utils::extensions::typed_response::TypedHttpResponse; use realtor_lp_types::{domain::click::Click, dto::payloads::click::ClickForCreationPayload}; use sqlx::PgPool; -use crate::{success, handle_tx, handle_db_write_op, dao}; - +use crate::{dao, handle_db_write_op, handle_tx, success}; pub async fn new_click(conn: &PgPool, click: ClickForCreationPayload) -> TypedHttpResponse<()> { let mut transaction = handle_tx!(conn.begin()); handle_db_write_op!(dao::click::insert_click(conn, click.into()), transaction); success!(()) -} \ No newline at end of file +} diff --git a/src/routes/project.rs b/src/routes/project.rs index e9a5f5c..785ca08 100644 --- a/src/routes/project.rs +++ b/src/routes/project.rs @@ -1,17 +1,33 @@ use actix_web_utils::extensions::typed_response::TypedHttpResponse; -use realtor_lp_types::{domain::project::Project, dto::payloads::project::ProjectForCreationPayload}; +use realtor_lp_types::{ + domain::project::Project, dto::payloads::project::ProjectForCreationPayload, +}; use sqlx::PgPool; use uuid::Uuid; -use crate::{success, handle_db_write_op, handle_tx, dao, handle_db_read_op, unwrap_or_not_found}; +use crate::{dao, handle_db_read_op, handle_db_write_op, handle_tx, success, unwrap_or_not_found}; - -pub async fn create_project(conn: &PgPool, project: ProjectForCreationPayload) -> TypedHttpResponse { - unwrap_or_not_found!(handle_db_read_op!(dao::realtor::get_realtor_with_id(conn, &project.realtor_id)), "Realtor"); +pub async fn create_project( + conn: &PgPool, + project: ProjectForCreationPayload, +) -> TypedHttpResponse { + unwrap_or_not_found!( + handle_db_read_op!(dao::realtor::get_realtor_with_id(conn, &project.realtor_id)), + "Realtor" + ); let mut transaction = handle_tx!(conn.begin()); - success!(handle_db_write_op!(dao::project::insert_project(&mut transaction, project.into()), transaction)); + success!(handle_db_write_op!( + dao::project::insert_project(&mut transaction, project.into()), + transaction + )); } -pub async fn fetch_realtor_projects(conn: &PgPool, realtor_id: Uuid) -> TypedHttpResponse> { - success!(handle_db_read_op!(dao::project::fetch_with_realtor_id(conn, &realtor_id))) -} \ No newline at end of file +pub async fn fetch_realtor_projects( + conn: &PgPool, + realtor_id: Uuid, +) -> TypedHttpResponse> { + success!(handle_db_read_op!(dao::project::fetch_with_realtor_id( + conn, + &realtor_id + ))) +} diff --git a/src/routes/property.rs b/src/routes/property.rs index b0811cc..5a18d39 100644 --- a/src/routes/property.rs +++ b/src/routes/property.rs @@ -1,44 +1,86 @@ use actix_web_utils::extensions::typed_response::TypedHttpResponse; use err::MessageResource; -use realtor_lp_types::{dto::payloads::property::PropertyForCreationPayload, domain::property::Property}; +use realtor_lp_types::{ + domain::property::Property, dto::payloads::property::PropertyForCreationPayload, +}; use sqlx::PgPool; use uuid::Uuid; -use crate::{handle_tx, handle_db_write_op, dao, success, unwrap_or_not_found, handle_db_read_op}; +use crate::{dao, handle_db_read_op, handle_db_write_op, handle_tx, success, unwrap_or_not_found}; - -pub async fn create_property(conn: &PgPool, property: PropertyForCreationPayload) -> TypedHttpResponse { +pub async fn create_property( + conn: &PgPool, + property: PropertyForCreationPayload, +) -> TypedHttpResponse { let mut transaction = handle_tx!(conn.begin()); - let realtor = unwrap_or_not_found!(handle_db_read_op!(dao::realtor::get_realtor_with_id(conn, &property.realtor_id)), "Realtor"); + let realtor = unwrap_or_not_found!( + handle_db_read_op!(dao::realtor::get_realtor_with_id( + conn, + &property.realtor_id + )), + "Realtor" + ); // Check for project existing match property.project_id { Some(project_id) => { - let project = unwrap_or_not_found!(handle_db_read_op!(dao::project::get_project_with_id(conn, &project_id)), "Project"); + let project = unwrap_or_not_found!( + handle_db_read_op!(dao::project::get_project_with_id(conn, &project_id)), + "Project" + ); if project.realtor_id != realtor.id { - return TypedHttpResponse::return_standard_error(400, MessageResource::new_from_str("Realtor Id in project does not match realtor id in property.")) + return TypedHttpResponse::return_standard_error( + 400, + MessageResource::new_from_str( + "Realtor Id in project does not match realtor id in property.", + ), + ); } - }, - None => {}, + } + None => {} }; - success!(handle_db_write_op!(dao::property::insert_property(&mut transaction, property.into()), transaction)) + success!(handle_db_write_op!( + dao::property::insert_property(&mut transaction, property.into()), + transaction + )) } -pub async fn udpate_property(conn: &PgPool, property_id: Uuid, property: PropertyForCreationPayload) -> TypedHttpResponse { +pub async fn udpate_property( + conn: &PgPool, + property_id: Uuid, + property: PropertyForCreationPayload, +) -> TypedHttpResponse { let mut transaction = handle_tx!(conn.begin()); - let realtor = unwrap_or_not_found!(handle_db_read_op!(dao::realtor::get_realtor_with_id(conn, &property.realtor_id)), "Realtor"); + let realtor = unwrap_or_not_found!( + handle_db_read_op!(dao::realtor::get_realtor_with_id( + conn, + &property.realtor_id + )), + "Realtor" + ); // Check for project existing match property.project_id { Some(project_id) => { - let project = unwrap_or_not_found!(handle_db_read_op!(dao::project::get_project_with_id(conn, &project_id)), "Project"); + let project = unwrap_or_not_found!( + handle_db_read_op!(dao::project::get_project_with_id(conn, &project_id)), + "Project" + ); if project.realtor_id != realtor.id { - return TypedHttpResponse::return_standard_error(400, MessageResource::new_from_str("Realtor Id in project does not match realtor id in property.")) + return TypedHttpResponse::return_standard_error( + 400, + MessageResource::new_from_str( + "Realtor Id in project does not match realtor id in property.", + ), + ); } - }, - None => {}, + } + None => {} }; let mut property_insertable: Property = property.into(); property_insertable.id = property_id; - success!(handle_db_write_op!(dao::property::update_property(&mut transaction, property_insertable), transaction)) -} \ No newline at end of file + success!(handle_db_write_op!( + dao::property::update_property(&mut transaction, property_insertable), + transaction + )) +} diff --git a/src/routes/realtor.rs b/src/routes/realtor.rs index eb16feb..51b0a96 100644 --- a/src/routes/realtor.rs +++ b/src/routes/realtor.rs @@ -1,27 +1,53 @@ use actix_web_utils::extensions::typed_response::TypedHttpResponse; -use realtor_lp_types::{domain::realtor::Realtor, dto::payloads::realtor::RealtorForCreationPayload}; +use realtor_lp_types::{ + domain::realtor::Realtor, dto::payloads::realtor::RealtorForCreationPayload, +}; use sqlx::PgPool; use uuid::Uuid; -use crate::{success, handle_tx, dao, handle_db_write_op, handle_db_read_op, unwrap_or_not_found}; +use crate::{dao, handle_db_read_op, handle_db_write_op, handle_tx, success, unwrap_or_not_found}; - -pub async fn new_realtor_profile(conn: &PgPool, realtor: RealtorForCreationPayload) -> TypedHttpResponse { +pub async fn new_realtor_profile( + conn: &PgPool, + realtor: RealtorForCreationPayload, +) -> TypedHttpResponse { let mut transaction = handle_tx!(conn.begin()); - success!(handle_db_write_op!(dao::realtor::insert_realtor(conn, realtor.into()), transaction)); + success!(handle_db_write_op!( + dao::realtor::insert_realtor(conn, realtor.into()), + transaction + )); } -pub async fn update_realtor_profile(conn: &PgPool, realtor_id: Uuid, realtor: RealtorForCreationPayload) -> TypedHttpResponse { +pub async fn update_realtor_profile( + conn: &PgPool, + realtor_id: Uuid, + realtor: RealtorForCreationPayload, +) -> TypedHttpResponse { let mut transaction = handle_tx!(conn.begin()); let mut realtor_insertable: Realtor = realtor.into(); realtor_insertable.id = realtor_id; - success!(handle_db_write_op!(dao::realtor::update_realtor(conn, realtor_insertable), transaction)); + success!(handle_db_write_op!( + dao::realtor::update_realtor(conn, realtor_insertable), + transaction + )); } -pub async fn get_realtor_by_shortcode(conn: &PgPool, realtor_shortcode: String,) -> TypedHttpResponse { - success!(unwrap_or_not_found!(handle_db_read_op!(dao::realtor::get_realtor_with_shortcode(conn, &realtor_shortcode)), "Realtors")) +pub async fn get_realtor_by_shortcode( + conn: &PgPool, + realtor_shortcode: String, +) -> TypedHttpResponse { + success!(unwrap_or_not_found!( + handle_db_read_op!(dao::realtor::get_realtor_with_shortcode( + conn, + &realtor_shortcode + )), + "Realtors" + )) } pub async fn get_realtor_with_id(conn: &PgPool, realtor_id: Uuid) -> TypedHttpResponse { - success!(unwrap_or_not_found!(handle_db_read_op!(dao::realtor::get_realtor_with_id(conn, &realtor_id)), "Realtors")) -} \ No newline at end of file + success!(unwrap_or_not_found!( + handle_db_read_op!(dao::realtor::get_realtor_with_id(conn, &realtor_id)), + "Realtors" + )) +} diff --git a/src/routes/trackable.rs b/src/routes/trackable.rs index a2264bf..46a44c9 100644 --- a/src/routes/trackable.rs +++ b/src/routes/trackable.rs @@ -1,17 +1,30 @@ use actix_web_utils::extensions::typed_response::TypedHttpResponse; -use realtor_lp_types::{domain::trackable::Trackable, dto::payloads::trackable::TrackableForCreationPayload}; +use realtor_lp_types::{ + domain::trackable::Trackable, dto::payloads::trackable::TrackableForCreationPayload, +}; use sqlx::PgPool; use uuid::Uuid; -use crate::{dao, success, handle_tx, handle_db_write_op, handle_db_read_op, unwrap_or_not_found}; +use crate::{dao, handle_db_read_op, handle_db_write_op, handle_tx, success, unwrap_or_not_found}; - -pub async fn create_trackable_profile(conn: &PgPool, trackable: TrackableForCreationPayload) -> TypedHttpResponse { +pub async fn create_trackable_profile( + conn: &PgPool, + trackable: TrackableForCreationPayload, +) -> TypedHttpResponse { let mut transaction = handle_tx!(conn.begin()); - let persisted_trackable = handle_db_write_op!(dao::trackable::insert_trackable(&mut transaction, trackable.into()), transaction); + let persisted_trackable = handle_db_write_op!( + dao::trackable::insert_trackable(&mut transaction, trackable.into()), + transaction + ); success!(persisted_trackable) } -pub async fn validate_trackable_id(conn: &PgPool, trackable_id: Uuid) -> TypedHttpResponse { - success!(unwrap_or_not_found!(handle_db_read_op!(dao::trackable::get_trackable_with_id(conn, &trackable_id)), "Trackables")) -} \ No newline at end of file +pub async fn validate_trackable_id( + conn: &PgPool, + trackable_id: Uuid, +) -> TypedHttpResponse { + success!(unwrap_or_not_found!( + handle_db_read_op!(dao::trackable::get_trackable_with_id(conn, &trackable_id)), + "Trackables" + )) +}