Cargo fmt

This commit is contained in:
Franklin 2023-05-04 14:49:00 -04:00
parent 96f018301e
commit b7b6b63173
8 changed files with 171 additions and 59 deletions

View File

@ -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<Project, sqlx::Error> {
pub async fn insert_project<'a>(
transaction: &mut Transaction<'a, Postgres>,
project: Project,
) -> Result<Project, sqlx::Error> {
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<Project, sqlx::Error> {
pub async fn update_project<'a>(
transaction: &mut Transaction<'a, Postgres>,
project: Project,
) -> Result<Project, sqlx::Error> {
sqlx::query_file_as!(
Project,
"sql/project/update.sql",

View File

@ -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<Property, sqlx::Error> {
pub async fn insert_property<'a>(
transaction: &mut Transaction<'a, Postgres>,
property: Property,
) -> Result<Property, sqlx::Error> {
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<Vec<Property>, sqlx::Error> {
sqlx::query_file_as!(Property, "sql/property/fetch_with_realtor_id.sql", realtor_id)
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<Property, sqlx::Error> {
pub async fn update_property<'a>(
transaction: &mut Transaction<'a, Postgres>,
property: Property,
) -> Result<Property, sqlx::Error> {
sqlx::query_file_as!(
Property,
"sql/property/update.sql",

View File

@ -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>(

View File

@ -2,8 +2,7 @@ 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());

View File

@ -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<Project> {
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<Project> {
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<Vec<Project>> {
success!(handle_db_read_op!(dao::project::fetch_with_realtor_id(conn, &realtor_id)))
pub async fn fetch_realtor_projects(
conn: &PgPool,
realtor_id: Uuid,
) -> TypedHttpResponse<Vec<Project>> {
success!(handle_db_read_op!(dao::project::fetch_with_realtor_id(
conn,
&realtor_id
)))
}

View File

@ -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<Property> {
pub async fn create_property(
conn: &PgPool,
property: PropertyForCreationPayload,
) -> TypedHttpResponse<Property> {
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<Property> {
pub async fn udpate_property(
conn: &PgPool,
property_id: Uuid,
property: PropertyForCreationPayload,
) -> TypedHttpResponse<Property> {
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))
success!(handle_db_write_op!(
dao::property::update_property(&mut transaction, property_insertable),
transaction
))
}

View File

@ -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<Realtor> {
pub async fn new_realtor_profile(
conn: &PgPool,
realtor: RealtorForCreationPayload,
) -> TypedHttpResponse<Realtor> {
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<Realtor> {
pub async fn update_realtor_profile(
conn: &PgPool,
realtor_id: Uuid,
realtor: RealtorForCreationPayload,
) -> TypedHttpResponse<Realtor> {
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<Realtor> {
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<Realtor> {
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<Realtor> {
success!(unwrap_or_not_found!(handle_db_read_op!(dao::realtor::get_realtor_with_id(conn, &realtor_id)), "Realtors"))
success!(unwrap_or_not_found!(
handle_db_read_op!(dao::realtor::get_realtor_with_id(conn, &realtor_id)),
"Realtors"
))
}

View File

@ -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<Trackable> {
pub async fn create_trackable_profile(
conn: &PgPool,
trackable: TrackableForCreationPayload,
) -> TypedHttpResponse<Trackable> {
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<Trackable> {
success!(unwrap_or_not_found!(handle_db_read_op!(dao::trackable::get_trackable_with_id(conn, &trackable_id)), "Trackables"))
pub async fn validate_trackable_id(
conn: &PgPool,
trackable_id: Uuid,
) -> TypedHttpResponse<Trackable> {
success!(unwrap_or_not_found!(
handle_db_read_op!(dao::trackable::get_trackable_with_id(conn, &trackable_id)),
"Trackables"
))
}