From 2e5e47c2be4a9d2e4c89a4a0d6cd9e69518d0c1e Mon Sep 17 00:00:00 2001 From: Franklin Date: Mon, 8 May 2023 13:22:36 -0400 Subject: [PATCH] Changed property queries, dao, and added proeprty_arrangemenet table --- migrations/2_property.sql | 9 ++++++--- migrations/7_property_arrangement.sql | 8 ++++++++ sql/project/fetch_with_realtor_id.sql | 4 ++-- ..._id.sql => fetch_with_realtor_id_paged.sql} | 8 ++++++-- sql/property/get_with_id.sql | 4 +++- sql/property/insert.sql | 10 +++++++--- sql/property/update.sql | 18 +++++++++++------- .../get_with_property_id.sql | 9 +++++++++ sql/property_arrangement/insert.sql | 16 ++++++++++++++++ sql/property_arrangement/update.sql | 13 +++++++++++++ src/dao/property.rs | 17 ++++++++++++----- src/main.rs | 1 - src/routes/property.rs | 12 ++++++++++++ src/services/click.rs | 1 - src/services/mod.rs | 6 ------ src/services/project.rs | 1 - src/services/property.rs | 1 - src/services/realtor.rs | 1 - src/services/trackable.rs | 1 - src/services/view.rs | 1 - 20 files changed, 105 insertions(+), 36 deletions(-) create mode 100644 migrations/7_property_arrangement.sql rename sql/property/{fetch_with_realtor_id.sql => fetch_with_realtor_id_paged.sql} (63%) create mode 100644 sql/property_arrangement/get_with_property_id.sql create mode 100644 sql/property_arrangement/insert.sql create mode 100644 sql/property_arrangement/update.sql delete mode 100644 src/services/click.rs delete mode 100644 src/services/mod.rs delete mode 100644 src/services/project.rs delete mode 100644 src/services/property.rs delete mode 100644 src/services/realtor.rs delete mode 100644 src/services/trackable.rs delete mode 100644 src/services/view.rs diff --git a/migrations/2_property.sql b/migrations/2_property.sql index 7d5b6a1..7521e33 100644 --- a/migrations/2_property.sql +++ b/migrations/2_property.sql @@ -5,13 +5,16 @@ CREATE TABLE IF NOT EXISTS "property" ( media TEXT NOT NULL, property_type VARCHAR NOT NULL, property_sale_type VARCHAR NOT NULL, - country VARCHAR, - city VARCHAR, - district VARCHAR, + country VARCHAR NOT NULL, + city VARCHAR NOT NULL, + district VARCHAR NOT NULL, + order_index INT NOT NULL, + thumbnail_format VARCHAR NOT NULL, price_usd FLOAT8 NOT NULL, rooms SMALLINT NOT NULL, bathrooms FLOAT4 NOT NULL, area FLOAT4 NOT NULL, + parking_spots SMALLINT NOT NULL, admin_tag VARCHAR, time_created TIMESTAMPTZ NOT NULL, last_updated TIMESTAMPTZ NOT NULL diff --git a/migrations/7_property_arrangement.sql b/migrations/7_property_arrangement.sql new file mode 100644 index 0000000..1b6f0cf --- /dev/null +++ b/migrations/7_property_arrangement.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS "property_arrangement" ( + property_id UUID PRIMARY KEY, + price_usd FLOAT8 NOT NULL, + currency VARCHAR NOT NULL, + arrangement VARCHAR NOT NULL, + time_created TIMESTAMPTZ NOT NULL, + last_updated TIMESTAMPTZ NOT NULL +); \ No newline at end of file diff --git a/sql/project/fetch_with_realtor_id.sql b/sql/project/fetch_with_realtor_id.sql index 54857fc..6fec54d 100644 --- a/sql/project/fetch_with_realtor_id.sql +++ b/sql/project/fetch_with_realtor_id.sql @@ -8,7 +8,7 @@ SELECT project_type as "project_type: _", project_state as "project_state: _", country, - city, + city, district, admin_tag, floors, @@ -16,4 +16,4 @@ SELECT order_index, time_created, last_updated -FROM project WHERE realtor_id = $1; +FROM project WHERE realtor_id = $1; \ No newline at end of file diff --git a/sql/property/fetch_with_realtor_id.sql b/sql/property/fetch_with_realtor_id_paged.sql similarity index 63% rename from sql/property/fetch_with_realtor_id.sql rename to sql/property/fetch_with_realtor_id_paged.sql index 4731e5d..cf64cbd 100644 --- a/sql/property/fetch_with_realtor_id.sql +++ b/sql/property/fetch_with_realtor_id_paged.sql @@ -8,11 +8,15 @@ SELECT country, city, district, - price_usd, + order_index, + thumbnail_format as "thumbnail_format: _", rooms, bathrooms, area, + parking_spots, admin_tag, time_created, last_updated -FROM property WHERE realtor_id = $1; \ No newline at end of file +FROM property WHERE realtor_id = $1 +ORDER BY time_created DESC +LIMIT 25 OFFSET $2; \ No newline at end of file diff --git a/sql/property/get_with_id.sql b/sql/property/get_with_id.sql index 3076207..4e0ff1e 100644 --- a/sql/property/get_with_id.sql +++ b/sql/property/get_with_id.sql @@ -8,10 +8,12 @@ SELECT country, city, district, - price_usd, + order_index, + thumbnail_format as "thumbnail_format: _", rooms, bathrooms, area, + parking_spots, admin_tag, time_created, last_updated diff --git a/sql/property/insert.sql b/sql/property/insert.sql index f294a09..2754fe7 100644 --- a/sql/property/insert.sql +++ b/sql/property/insert.sql @@ -8,15 +8,17 @@ INSERT INTO property ( country, city, district, - price_usd, + order_index, + thumbnail_format, rooms, bathrooms, area, + parking_spots, admin_tag, time_created, last_updated ) VALUES ( - $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $15 + $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $17 ) RETURNING id, project_id, @@ -27,10 +29,12 @@ INSERT INTO property ( country, city, district, - price_usd, + order_index, + thumbnail_format as "thumbnail_format: _", rooms, bathrooms, area, + parking_spots, admin_tag, time_created, last_updated; \ No newline at end of file diff --git a/sql/property/update.sql b/sql/property/update.sql index 450cae5..338fce3 100644 --- a/sql/property/update.sql +++ b/sql/property/update.sql @@ -7,12 +7,14 @@ UPDATE property SET country = $7, city = $8, district = $9, - price_usd = $10, - rooms = $11, - bathrooms = $12, - area = $13, - admin_tag = $14, - last_updated = $15 + order_index = $10, + thumbnail_format = $11, + rooms = $12, + bathrooms = $13, + area = $14, + parking_spots = $15, + admin_tag = $16, + last_updated = $17 WHERE id = $1 RETURNING id, @@ -24,10 +26,12 @@ RETURNING country, city, district, - price_usd, + order_index, + thumbnail_format as "thumbnail_format: _", rooms, bathrooms, area, + parking_spots, admin_tag, time_created, last_updated; \ No newline at end of file diff --git a/sql/property_arrangement/get_with_property_id.sql b/sql/property_arrangement/get_with_property_id.sql new file mode 100644 index 0000000..1869929 --- /dev/null +++ b/sql/property_arrangement/get_with_property_id.sql @@ -0,0 +1,9 @@ +SELECT + property_id, + price_usd, + currency, + arrangement as "arrangement: _", + time_created, + last_updated +FROM property_arrangement +WHERE property_id = $1; \ No newline at end of file diff --git a/sql/property_arrangement/insert.sql b/sql/property_arrangement/insert.sql new file mode 100644 index 0000000..c8cc1c2 --- /dev/null +++ b/sql/property_arrangement/insert.sql @@ -0,0 +1,16 @@ +INSERT INTO property_arrangement ( + property_id, + price_usd, + currency, + arrangement, + time_created, + last_updated +) VALUES ( + $1, $2, $3, $4, $5, $5 +) RETURNING + property_id, + price_usd, + currency, + arrangement as "arrangement: _", + time_created, + last_updated; \ No newline at end of file diff --git a/sql/property_arrangement/update.sql b/sql/property_arrangement/update.sql new file mode 100644 index 0000000..bdd235d --- /dev/null +++ b/sql/property_arrangement/update.sql @@ -0,0 +1,13 @@ +UPDATE property_arrangement SET + price_usd = $2, + currency = $3, + arrangement = $4, + last_updated = $5 +WHERE property_id = $1 +RETURNING + property_id, + price_usd, + currency, + arrangement as "arrangement: _", + time_created, + last_updated; \ No newline at end of file diff --git a/src/dao/property.rs b/src/dao/property.rs index 7a02e54..4393b3a 100644 --- a/src/dao/property.rs +++ b/src/dao/property.rs @@ -18,10 +18,12 @@ pub async fn insert_property<'a>( property.country, property.city, property.district, - property.price_usd, + property.order_index, + property.thumbnail_format as _, property.rooms, property.bathrooms, property.area, + property.parking_spots, property.admin_tag, property.time_created ) @@ -38,14 +40,17 @@ pub async fn get_property_with_id( .await } -pub async fn fetch_with_realtor_id( +pub async fn fetch_with_realtor_id_paged( conn: &PgPool, realtor_id: &Uuid, + page: &i64, ) -> Result, sqlx::Error> { + let offset = (page - 1) * 25; sqlx::query_file_as!( Property, - "sql/property/fetch_with_realtor_id.sql", - realtor_id + "sql/property/fetch_with_realtor_id_paged.sql", + realtor_id, + offset ) .fetch_all(conn) .await @@ -67,10 +72,12 @@ pub async fn update_property<'a>( property.country, property.city, property.district, - property.price_usd, + property.order_index, + property.thumbnail_format as _, property.rooms, property.bathrooms, property.area, + property.parking_spots, property.admin_tag, property.last_updated ) diff --git a/src/main.rs b/src/main.rs index 4aa3a4d..00abeff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,6 @@ use dao::main_dao; mod dao; mod routes; -mod services; mod utils; #[tokio::main] diff --git a/src/routes/property.rs b/src/routes/property.rs index 5a18d39..72de7b9 100644 --- a/src/routes/property.rs +++ b/src/routes/property.rs @@ -1,3 +1,6 @@ +use std::sync::Arc; + +use actix_web::{web::{Path, Data}, get}; use actix_web_utils::extensions::typed_response::TypedHttpResponse; use err::MessageResource; use realtor_lp_types::{ @@ -84,3 +87,12 @@ pub async fn udpate_property( transaction )) } + +#[get("/properties/{realtor_id}/{page}")] +pub async fn fetch_realtor_properties_paged( + conn: Data>, + path_vars: Path<(Uuid, i64)>, +) -> TypedHttpResponse> { + + success!(Default::default()) +} \ No newline at end of file diff --git a/src/services/click.rs b/src/services/click.rs deleted file mode 100644 index 8b13789..0000000 --- a/src/services/click.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/services/mod.rs b/src/services/mod.rs deleted file mode 100644 index d7b1331..0000000 --- a/src/services/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -pub mod click; -pub mod project; -pub mod property; -pub mod realtor; -pub mod trackable; -pub mod view; diff --git a/src/services/project.rs b/src/services/project.rs deleted file mode 100644 index 8b13789..0000000 --- a/src/services/project.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/services/property.rs b/src/services/property.rs deleted file mode 100644 index 8b13789..0000000 --- a/src/services/property.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/services/realtor.rs b/src/services/realtor.rs deleted file mode 100644 index 8b13789..0000000 --- a/src/services/realtor.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/services/trackable.rs b/src/services/trackable.rs deleted file mode 100644 index 8b13789..0000000 --- a/src/services/trackable.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/services/view.rs b/src/services/view.rs deleted file mode 100644 index 8b13789..0000000 --- a/src/services/view.rs +++ /dev/null @@ -1 +0,0 @@ -