Set todos

This commit is contained in:
Franklin 2023-03-10 07:20:59 -04:00
parent 5e0e8e7b20
commit 61b547d7a0
6 changed files with 124 additions and 16 deletions

View File

@ -0,0 +1 @@
SELECT * FROM location WHERE id = ANY($1);

View File

@ -311,6 +311,56 @@
},
"query": "INSERT INTO agent (\n id, full_name, time_created, last_updated\n) VALUES (\n $1, $2, $3, $3\n) RETURNING *"
},
"68da2e3f3ab23e76b332a9882d267deb63809de4f5dcf4c05616de9d38fab21f": {
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Uuid"
},
{
"name": "country",
"ordinal": 1,
"type_info": "Varchar"
},
{
"name": "province",
"ordinal": 2,
"type_info": "Varchar"
},
{
"name": "city",
"ordinal": 3,
"type_info": "Varchar"
},
{
"name": "district",
"ordinal": 4,
"type_info": "Varchar"
},
{
"name": "google_maps_url",
"ordinal": 5,
"type_info": "Text"
}
],
"nullable": [
false,
false,
false,
false,
true,
true
],
"parameters": {
"Left": [
"UuidArray"
]
}
},
"query": "SELECT * FROM location WHERE id = ANY($1);"
},
"75508bc7b114d6f9915cadf9708c376d2ca1a6dcdd6bff24b1a717cba0ec2fca": {
"describe": {
"columns": [

View File

@ -19,6 +19,16 @@ pub async fn insert_location(
.fetch_one(conn)
.await
}
pub async fn get_locations_with_ids(
conn: &PgPool,
ids: &Vec<Uuid>,
) -> Result<Vec<Location>, sqlx::error::Error> {
sqlx::query_file_as!(Location, "sql/location/fetch_with_ids.sql", ids)
.fetch_all(conn)
.await
}
pub async fn get_location_with_id(
conn: &PgPool,
id: &Uuid,

View File

@ -1,6 +1,6 @@
use actix_web_utils::extensions::typed_response::TypedHttpResponse;
use remax_types::{
domain::{location::Location, contact_info::ContactInformation},
domain::{contact_info::ContactInformation, location::Location},
dto::{
agent::AgentContainer,
payload::{
@ -56,7 +56,6 @@ pub async fn create_new_location(
success!(persisted_location)
}
/// Needs to create a Property, a Property Details
/// Create or reference an existing Location
/// and an Agent
@ -96,36 +95,62 @@ pub async fn create_new_property(
})
}
//
// Update Methods
//
pub async fn update_agent_info(conn: &PgPool, update_agent_payload: UpdateAgentPayload) -> TypedHttpResponse<ContactInformation> {
pub async fn update_agent_info(
conn: &PgPool,
update_agent_payload: UpdateAgentPayload,
) -> TypedHttpResponse<ContactInformation> {
let mut tx = handle_tx!(conn.begin());
let mut persisted_contact_infos = handle_db_read_op!(dao::contact_info::get_contact_infos_with_ids(conn, &vec![update_agent_payload.id]));
let persisted_contact_info = unwrap_or_not_found!(persisted_contact_infos.first_mut(), "agent contact infos");
let mut persisted_contact_infos = handle_db_read_op!(
dao::contact_info::get_contact_infos_with_ids(conn, &vec![update_agent_payload.id])
);
let persisted_contact_info =
unwrap_or_not_found!(persisted_contact_infos.first_mut(), "agent contact infos");
update_agent_payload.update_contact_info(persisted_contact_info);
let updated_contact_info = handle_db_write_op!(dao::contact_info::update_contact_info(&mut tx, persisted_contact_info), tx);
let updated_contact_info = handle_db_write_op!(
dao::contact_info::update_contact_info(&mut tx, persisted_contact_info),
tx
);
handle_tx!(tx.commit());
success!(updated_contact_info)
}
pub async fn update_listing(conn: &PgPool, update_property_payload: UpdateListingPayload) -> TypedHttpResponse<PropertyWithDetails> {
pub async fn update_listing(
conn: &PgPool,
update_property_payload: UpdateListingPayload,
) -> TypedHttpResponse<PropertyWithDetails> {
let mut tx = handle_tx!(conn.begin());
let mut persisted_properties = handle_db_read_op!(dao::property::get_properties_with_ids(conn, &vec![update_property_payload.property_id]));
let mut persisted_properties_details = handle_db_read_op!(dao::property_details::get_properties_with_ids(conn, &vec![update_property_payload.property_id]));
let mut persisted_properties = handle_db_read_op!(dao::property::get_properties_with_ids(
conn,
&vec![update_property_payload.property_id]
));
let mut persisted_properties_details =
handle_db_read_op!(dao::property_details::get_properties_with_ids(
conn,
&vec![update_property_payload.property_id]
));
let persisted_property = unwrap_or_not_found!(persisted_properties.first_mut(), "properties");
let persisted_property_details = unwrap_or_not_found!(persisted_properties_details.first_mut(), "property_details");
let persisted_property_details =
unwrap_or_not_found!(persisted_properties_details.first_mut(), "property_details");
update_property_payload.update_listing(persisted_property, persisted_property_details);
let updated_property = handle_db_write_op!(dao::property::update_property(&mut tx, persisted_property), tx);
let updated_property_details = handle_db_write_op!(dao::property_details::update_property_details(&mut tx, persisted_property_details), tx);
let updated_property = handle_db_write_op!(
dao::property::update_property(&mut tx, persisted_property),
tx
);
let updated_property_details = handle_db_write_op!(
dao::property_details::update_property_details(&mut tx, persisted_property_details),
tx
);
handle_tx!(tx.commit());
success!(PropertyWithDetails {
property: updated_property, details: updated_property_details
property: updated_property,
details: updated_property_details
})
}

View File

@ -1 +1,2 @@
pub mod admin;
pub mod read;

21
src/service/read.rs Normal file
View File

@ -0,0 +1,21 @@
// TODO: Most important method: Get First page of property listings (Filters)
// TODO: Get individual property listing with all the info (contact, location, property, details)
// TODO: Get all agents
use actix_web_utils::extensions::typed_response::TypedHttpResponse;
use remax_types::{
domain::agent::Agent,
dto::property::{ListingContainer, PropertyContainer},
};
pub async fn get_property_listings_paged() -> TypedHttpResponse<PropertyContainer> {
todo!()
}
pub async fn get_listing_container() -> TypedHttpResponse<ListingContainer> {
todo!()
}
pub async fn get_all_agents() -> TypedHttpResponse<Vec<Agent>> {
todo!()
}