diff --git a/migrations/4_unit.sql b/migrations/4_unit.sql index 3428ef5..ca4d0c4 100644 --- a/migrations/4_unit.sql +++ b/migrations/4_unit.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS "unit" ( price_usd FLOAT8 NOT NULL, unit_type VARCHAR NOT NULL, rooms SMALLINT NOT NULL, - bathrooms SMALLINT NOT NULL, + bathrooms FLOAT4 NOT NULL, area FLOAT4 NOT NULL, description TEXT NOT NULL, media TEXT NOT NULL, diff --git a/sql/project/fetch_with_filters_paged.sql b/sql/project/fetch_with_filters_paged.sql index 5ec4569..e5439ce 100644 --- a/sql/project/fetch_with_filters_paged.sql +++ b/sql/project/fetch_with_filters_paged.sql @@ -4,7 +4,7 @@ SELECT p.project_type as "project_type: _", p.project_condition as "project_condition: _", l.city, - (SELECT (SELECT u.price_usd FROM unit u WHERE u.project_id = p.id ORDER BY u.price_usd DESC LIMIT 1)) as starts_from, + (SELECT (SELECT u.price_usd FROM unit u WHERE u.project_id = p.id ORDER BY u.price_usd ASC LIMIT 1)) as starts_from, l.district, p.finish_date, p.media as "media: _", diff --git a/sqlx-data.json b/sqlx-data.json index 053138e..fc1f038 100644 --- a/sqlx-data.json +++ b/sqlx-data.json @@ -546,86 +546,6 @@ }, "query": "INSERT INTO agent (\n id, shortcode, full_name, credential, credential_type, profile_picture_url, time_created, last_updated\n) VALUES (\n $1, $2, $3, $4, $5, $6, $7, $7\n) RETURNING\nid,\nshortcode,\nfull_name,\ncredential,\ncredential_type as \"credential_type: _\",\nprofile_picture_url,\ntime_created,\nlast_updated;" }, - "919dc414e70785bed4b999412b2ce5c46cb07e4aefb6a8c74bde23fcca9a4759": { - "describe": { - "columns": [ - { - "name": "id", - "ordinal": 0, - "type_info": "Uuid" - }, - { - "name": "project_state: _", - "ordinal": 1, - "type_info": "Varchar" - }, - { - "name": "project_type: _", - "ordinal": 2, - "type_info": "Varchar" - }, - { - "name": "project_condition: _", - "ordinal": 3, - "type_info": "Varchar" - }, - { - "name": "city", - "ordinal": 4, - "type_info": "Varchar" - }, - { - "name": "starts_from", - "ordinal": 5, - "type_info": "Float8" - }, - { - "name": "district", - "ordinal": 6, - "type_info": "Varchar" - }, - { - "name": "finish_date", - "ordinal": 7, - "type_info": "Timestamp" - }, - { - "name": "media: _", - "ordinal": 8, - "type_info": "Text" - }, - { - "name": "admin_tag", - "ordinal": 9, - "type_info": "Varchar" - } - ], - "nullable": [ - false, - false, - false, - false, - false, - null, - false, - false, - false, - true - ], - "parameters": { - "Left": [ - "Text", - "Text", - "Text", - "Text", - "Text", - "Int2", - "Int8" - ] - } - }, - "query": "SELECT \n p.id,\n p.project_state as \"project_state: _\",\n p.project_type as \"project_type: _\",\n p.project_condition as \"project_condition: _\",\n l.city,\n (SELECT (SELECT u.price_usd FROM unit u WHERE u.project_id = p.id ORDER BY u.price_usd DESC LIMIT 1)) as starts_from,\n l.district,\n p.finish_date,\n p.media as \"media: _\",\n p.admin_tag\nFROM project p, location l\nWHERE p.location_id = l.id\n-- Filters here:\nAND (LOWER(l.city) LIKE '%' || LOWER($1) || '%' OR $1 IS null) -- City Filter\nAND (LOWER(l.district) LIKE '%' || LOWER($2) || '%' OR $2 IS null) -- District Filter\nAND (p.project_type = $3 OR $3 IS null) -- ProjectType\nAND (p.project_condition = $4 OR $4 IS null) -- ProjectCondition\nAND (p.project_state = $5 OR $5 IS null) -- ProjectState\nAND ((SELECT COUNT(*) FROM unit u WHERE u.project_id = p.id AND u.rooms = $6) > 0 OR $6 IS NULL)\n-- End of filters\nORDER BY p.time_created DESC\nLIMIT 50 OFFSET $7;" - }, "924abcf88270de74ab6524fbd4247b2c23ab96b4569c8b81ff6b0e1d7dacada7": { "describe": { "columns": [ @@ -1541,5 +1461,85 @@ } }, "query": "INSERT INTO unit (\n id,\n project_id,\n price_usd,\n unit_type,\n rooms,\n bathrooms,\n area,\n description,\n media,\n admin_tag,\n time_created,\n last_updated\n) VALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6,\n $7,\n $8,\n $9,\n $10,\n $11,\n $11\n)\nRETURNING \n id,\n project_id,\n price_usd,\n unit_type as \"unit_type: _\",\n rooms,\n bathrooms,\n area,\n description,\n media as \"media: _\",\n admin_tag,\n time_created,\n last_updated;" + }, + "f31a7e8287470f8e6328ccf6a8c73c2f476ebcf976b0f70944c2a80c1bfaa246": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "project_state: _", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "project_type: _", + "ordinal": 2, + "type_info": "Varchar" + }, + { + "name": "project_condition: _", + "ordinal": 3, + "type_info": "Varchar" + }, + { + "name": "city", + "ordinal": 4, + "type_info": "Varchar" + }, + { + "name": "starts_from", + "ordinal": 5, + "type_info": "Float8" + }, + { + "name": "district", + "ordinal": 6, + "type_info": "Varchar" + }, + { + "name": "finish_date", + "ordinal": 7, + "type_info": "Timestamp" + }, + { + "name": "media: _", + "ordinal": 8, + "type_info": "Text" + }, + { + "name": "admin_tag", + "ordinal": 9, + "type_info": "Varchar" + } + ], + "nullable": [ + false, + false, + false, + false, + false, + null, + false, + false, + false, + true + ], + "parameters": { + "Left": [ + "Text", + "Text", + "Text", + "Text", + "Text", + "Int2", + "Int8" + ] + } + }, + "query": "SELECT \n p.id,\n p.project_state as \"project_state: _\",\n p.project_type as \"project_type: _\",\n p.project_condition as \"project_condition: _\",\n l.city,\n (SELECT (SELECT u.price_usd FROM unit u WHERE u.project_id = p.id ORDER BY u.price_usd ASC LIMIT 1)) as starts_from,\n l.district,\n p.finish_date,\n p.media as \"media: _\",\n p.admin_tag\nFROM project p, location l\nWHERE p.location_id = l.id\n-- Filters here:\nAND (LOWER(l.city) LIKE '%' || LOWER($1) || '%' OR $1 IS null) -- City Filter\nAND (LOWER(l.district) LIKE '%' || LOWER($2) || '%' OR $2 IS null) -- District Filter\nAND (p.project_type = $3 OR $3 IS null) -- ProjectType\nAND (p.project_condition = $4 OR $4 IS null) -- ProjectCondition\nAND (p.project_state = $5 OR $5 IS null) -- ProjectState\nAND ((SELECT COUNT(*) FROM unit u WHERE u.project_id = p.id AND u.rooms = $6) > 0 OR $6 IS NULL)\n-- End of filters\nORDER BY p.time_created DESC\nLIMIT 50 OFFSET $7;" } } \ No newline at end of file diff --git a/src/routes/read.rs b/src/routes/read.rs index 2131bb6..8674514 100644 --- a/src/routes/read.rs +++ b/src/routes/read.rs @@ -26,6 +26,7 @@ use uuid::Uuid; use crate::{services, utils::visit::store_visit_concurrent}; + #[get("/agent")] pub async fn get_all_agents(db_conn: web::Data>) -> TypedHttpResponse> { services::read::get_all_agents(&db_conn).await diff --git a/src/utils/macros.rs b/src/utils/macros.rs index ee0443b..91dd47e 100644 --- a/src/utils/macros.rs +++ b/src/utils/macros.rs @@ -56,7 +56,7 @@ macro_rules! unwrap_or_not_found { }; } -/// This macro does the authentication needed for all the admin routes. give it a user and password as params. +/// This macro does the authentication needed for all the admin routes. #[macro_export] macro_rules! auth { ($request:expr) => {