diff --git a/Readme.md b/Readme.md index 6fb1877..3c71fbc 100644 --- a/Readme.md +++ b/Readme.md @@ -3,8 +3,8 @@ by Franklin Blanco ### Todo's -- [ ] Add properties -- [ ] Add agents +- [x] Add properties +- [x] Add agents - [ ] Fetch them both - [ ] Delete, update - [ ] Admin panel functions diff --git a/sql/property_details/insert.sql b/sql/property_details/insert.sql index e6f65b8..6106695 100644 --- a/sql/property_details/insert.sql +++ b/sql/property_details/insert.sql @@ -3,7 +3,7 @@ INSERT INTO property_details ( meters, listing_type, photo_urls, - location_id, + location_id ) VALUES ( $1, $2, @@ -15,4 +15,4 @@ property_id, meters, listing_type as "listing_type: _", photo_urls as "photo_urls: _", -location_id \ No newline at end of file +location_id; \ No newline at end of file diff --git a/src/dao/agent.rs b/src/dao/agent.rs index 8b13789..cb64e0d 100644 --- a/src/dao/agent.rs +++ b/src/dao/agent.rs @@ -1 +1,40 @@ +use remax_types::domain::agent::Agent; +use sqlx::PgPool; +use uuid::Uuid; +pub async fn insert_agent( + conn: &PgPool, + agent: &Agent, +) -> Result { + sqlx::query_file_as!( + Agent, + "sql/agent/insert.sql", + agent.id, + agent.full_name, + agent.time_created + ) + .fetch_one(conn) + .await +} +pub async fn get_properties_with_ids( + conn: &PgPool, + ids: &Vec, +) -> Result, sqlx::error::Error> { + sqlx::query_file_as!(Agent, "sql/agent/fetch_with_ids.sql", ids) + .fetch_all(conn) + .await +} + +pub async fn update_agent( + conn: &PgPool, + agent: &Agent, +) -> Result { + sqlx::query_file_as!( + Agent, + "sql/agent/update.sql", + agent.full_name, + agent.last_updated + ) + .fetch_one(conn) + .await +} diff --git a/src/dao/contact_info.rs b/src/dao/contact_info.rs new file mode 100644 index 0000000..9870cb2 --- /dev/null +++ b/src/dao/contact_info.rs @@ -0,0 +1,44 @@ +use remax_types::domain::contact_info::ContactInformation; +use sqlx::PgPool; +use uuid::Uuid; + +pub async fn insert_contact_info( + conn: &PgPool, + contact_info: &ContactInformation, +) -> Result { + sqlx::query_file_as!( + ContactInformation, + "sql/contact_info/insert.sql", + contact_info.agent_id, + contact_info.phone_number, + contact_info.email, + contact_info.profile_picture_url, + contact_info.default_message + ) + .fetch_one(conn) + .await +} +pub async fn get_properties_with_ids( + conn: &PgPool, + ids: &Vec, +) -> Result, sqlx::error::Error> { + sqlx::query_file_as!(ContactInformation, "sql/contact_info/fetch_with_ids.sql", ids) + .fetch_all(conn) + .await +} + +pub async fn update_contact_info( + conn: &PgPool, + contact_info: &ContactInformation, +) -> Result { + sqlx::query_file_as!( + ContactInformation, + "sql/contact_info/update.sql", + contact_info.phone_number, + contact_info.email, + contact_info.profile_picture_url, + contact_info.default_message + ) + .fetch_one(conn) + .await +} diff --git a/src/dao/location.rs b/src/dao/location.rs new file mode 100644 index 0000000..a05e187 --- /dev/null +++ b/src/dao/location.rs @@ -0,0 +1,29 @@ +use remax_types::domain::location::Location; +use sqlx::PgPool; +use uuid::Uuid; + +pub async fn insert_location( + conn: &PgPool, + location: &Location, +) -> Result { + sqlx::query_file_as!( + Location, + "sql/location/insert.sql", + location.id, + location.country, + location.province, + location.city, + location.district, + location.google_maps_url + ) + .fetch_one(conn) + .await +} +pub async fn get_location_with_id( + conn: &PgPool, + id: &Uuid, +) -> Result, sqlx::error::Error> { + sqlx::query_file_as!(Location, "sql/location/get.sql", id) + .fetch_all(conn) + .await +} \ No newline at end of file diff --git a/src/dao/mod.rs b/src/dao/mod.rs index 343c9e2..b00be56 100644 --- a/src/dao/mod.rs +++ b/src/dao/mod.rs @@ -1,3 +1,6 @@ pub mod agent; pub mod main_dao; pub mod property; +pub mod location; +pub mod contact_info; +pub mod property_details; \ No newline at end of file diff --git a/src/dao/property_details.rs b/src/dao/property_details.rs new file mode 100644 index 0000000..db1de5a --- /dev/null +++ b/src/dao/property_details.rs @@ -0,0 +1,44 @@ +use remax_types::domain::property_details::PropertyDetails; +use sqlx::PgPool; +use uuid::Uuid; + +pub async fn insert_property_details( + conn: &PgPool, + property_details: &PropertyDetails, +) -> Result { + sqlx::query_file_as!( + PropertyDetails, + "sql/property_details/insert.sql", + property_details.property_id, + property_details.meters, + property_details.listing_type as _, + property_details.photo_urls as _, + property_details.location_id + ) + .fetch_one(conn) + .await +} +pub async fn get_properties_with_ids( + conn: &PgPool, + ids: &Vec, +) -> Result, sqlx::error::Error> { + sqlx::query_file_as!(PropertyDetails, "sql/property_details/fetch_with_ids.sql", ids) + .fetch_all(conn) + .await +} + +pub async fn update_property_details( + conn: &PgPool, + property_details: &PropertyDetails, +) -> Result { + sqlx::query_file_as!( + PropertyDetails, + "sql/property_details/update.sql", + property_details.meters, + property_details.listing_type as _, + property_details.photo_urls as _, + property_details.location_id + ) + .fetch_one(conn) + .await +}