From 5f878f04a9c69fbc4d3d304f9f6219c091a947e9 Mon Sep 17 00:00:00 2001 From: Franklin Date: Thu, 11 May 2023 11:31:58 -0400 Subject: [PATCH] Added cards to property filter --- migrations/1_realtor.sql | 1 + sql/property/fetch_with_realtor_id_paged.sql | 2 +- sql/realtor/insert.sql | 4 +- sql/realtor/update.sql | 7 +- sqlx-data.json | 668 ++++++++++--------- src/dao/realtor.rs | 2 + src/routes/property.rs | 4 +- src/services/property.rs | 33 +- 8 files changed, 387 insertions(+), 334 deletions(-) diff --git a/migrations/1_realtor.sql b/migrations/1_realtor.sql index c8d5913..27c10ce 100644 --- a/migrations/1_realtor.sql +++ b/migrations/1_realtor.sql @@ -5,6 +5,7 @@ CREATE TABLE IF NOT EXISTS "realtor" ( phone_number VARCHAR NOT NULL, email VARCHAR, profile_picture_url VARCHAR NOT NULL, + banner_picture_url VARCHAR, show_projects boolean NOT NULL, shortcode VARCHAR NOT NULL, remax_agent_id INT, diff --git a/sql/property/fetch_with_realtor_id_paged.sql b/sql/property/fetch_with_realtor_id_paged.sql index 3efc08c..73f27ce 100644 --- a/sql/property/fetch_with_realtor_id_paged.sql +++ b/sql/property/fetch_with_realtor_id_paged.sql @@ -33,5 +33,5 @@ AND (p.parking_spots = $11 OR $11 IS null) -- Parking spots amount AND (pa.price <= $12 OR $12 IS null) -- Price Less than AND (pa.price >= $13 OR $13 IS null) -- Price Greater than -- END OF FILTERS -ORDER BY p.time_created DESC +ORDER BY p.order_index DESC LIMIT 25 OFFSET $2; \ No newline at end of file diff --git a/sql/realtor/insert.sql b/sql/realtor/insert.sql index 3354524..a1c83d2 100644 --- a/sql/realtor/insert.sql +++ b/sql/realtor/insert.sql @@ -1,5 +1,5 @@ INSERT INTO realtor ( - id, name, bio, phone_number, email, profile_picture_url, show_projects, shortcode, remax_agent_id, time_created, last_updated + id, name, bio, phone_number, email, profile_picture_url, banner_picture_url, show_projects, shortcode, remax_agent_id, time_created, last_updated ) VALUES ( - $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $10 + $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $11 ) RETURNING *; \ No newline at end of file diff --git a/sql/realtor/update.sql b/sql/realtor/update.sql index 8a3b0a6..51e68b1 100644 --- a/sql/realtor/update.sql +++ b/sql/realtor/update.sql @@ -4,8 +4,9 @@ UPDATE realtor SET phone_number = $4, email = $5, profile_picture_url = $6, - show_projects = $7, - remax_agent_id = $8, - last_updated = $9 + banner_picture_url = $7, + show_projects = $8, + remax_agent_id = $9, + last_updated = $10 WHERE id = $1 RETURNING *; \ No newline at end of file diff --git a/sqlx-data.json b/sqlx-data.json index d9c6bac..95d48b7 100644 --- a/sqlx-data.json +++ b/sqlx-data.json @@ -116,6 +116,101 @@ }, "query": "SELECT \n id,\n title,\n description,\n realtor_id,\n media as \"media: _\",\n project_condition as \"project_condition: _\",\n project_type as \"project_type: _\",\n project_state as \"project_state: _\",\n country,\n city, \n district,\n admin_tag,\n floors,\n finish_date,\n order_index,\n time_created,\n last_updated\nFROM project WHERE id = $1;\n" }, + "1baab5ac461f9543430bd85a600a5af1df45bcd93746eba8219ebcd1efcc56d4": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "name", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "bio", + "ordinal": 2, + "type_info": "Varchar" + }, + { + "name": "phone_number", + "ordinal": 3, + "type_info": "Varchar" + }, + { + "name": "email", + "ordinal": 4, + "type_info": "Varchar" + }, + { + "name": "profile_picture_url", + "ordinal": 5, + "type_info": "Varchar" + }, + { + "name": "banner_picture_url", + "ordinal": 6, + "type_info": "Varchar" + }, + { + "name": "show_projects", + "ordinal": 7, + "type_info": "Bool" + }, + { + "name": "shortcode", + "ordinal": 8, + "type_info": "Varchar" + }, + { + "name": "remax_agent_id", + "ordinal": 9, + "type_info": "Int4" + }, + { + "name": "time_created", + "ordinal": 10, + "type_info": "Timestamptz" + }, + { + "name": "last_updated", + "ordinal": 11, + "type_info": "Timestamptz" + } + ], + "nullable": [ + false, + false, + false, + false, + true, + false, + true, + false, + false, + true, + false, + false + ], + "parameters": { + "Left": [ + "Uuid", + "Varchar", + "Varchar", + "Varchar", + "Varchar", + "Varchar", + "Varchar", + "Bool", + "Int4", + "Timestamptz" + ] + } + }, + "query": "UPDATE realtor SET\n name = $2,\n bio = $3,\n phone_number = $4,\n email = $5,\n profile_picture_url = $6,\n banner_picture_url = $7,\n show_projects = $8,\n remax_agent_id = $9,\n last_updated = $10\nWHERE id = $1\nRETURNING *;" + }, "1de871eb06903280d3be4e4ef8f67cde596807784e726ff62d03c2c9f6d6ba76": { "describe": { "columns": [ @@ -150,28 +245,33 @@ "type_info": "Varchar" }, { - "name": "show_projects", + "name": "banner_picture_url", "ordinal": 6, + "type_info": "Varchar" + }, + { + "name": "show_projects", + "ordinal": 7, "type_info": "Bool" }, { "name": "shortcode", - "ordinal": 7, + "ordinal": 8, "type_info": "Varchar" }, { "name": "remax_agent_id", - "ordinal": 8, + "ordinal": 9, "type_info": "Int4" }, { "name": "time_created", - "ordinal": 9, + "ordinal": 10, "type_info": "Timestamptz" }, { "name": "last_updated", - "ordinal": 10, + "ordinal": 11, "type_info": "Timestamptz" } ], @@ -182,6 +282,7 @@ false, true, false, + true, false, false, true, @@ -250,95 +351,6 @@ }, "query": "UPDATE property_arrangement SET \n price = $2,\n currency = $3,\n arrangement = $4,\n last_updated = $5\nWHERE property_id = $1\nRETURNING \n property_id,\n price,\n currency,\n arrangement as \"arrangement: _\",\n time_created,\n last_updated;" }, - "2482798d8601fd41678197770bf51af67cd962d210ff65b9236f24f0425d7341": { - "describe": { - "columns": [ - { - "name": "id", - "ordinal": 0, - "type_info": "Uuid" - }, - { - "name": "name", - "ordinal": 1, - "type_info": "Varchar" - }, - { - "name": "bio", - "ordinal": 2, - "type_info": "Varchar" - }, - { - "name": "phone_number", - "ordinal": 3, - "type_info": "Varchar" - }, - { - "name": "email", - "ordinal": 4, - "type_info": "Varchar" - }, - { - "name": "profile_picture_url", - "ordinal": 5, - "type_info": "Varchar" - }, - { - "name": "show_projects", - "ordinal": 6, - "type_info": "Bool" - }, - { - "name": "shortcode", - "ordinal": 7, - "type_info": "Varchar" - }, - { - "name": "remax_agent_id", - "ordinal": 8, - "type_info": "Int4" - }, - { - "name": "time_created", - "ordinal": 9, - "type_info": "Timestamptz" - }, - { - "name": "last_updated", - "ordinal": 10, - "type_info": "Timestamptz" - } - ], - "nullable": [ - false, - false, - false, - false, - true, - false, - false, - false, - true, - false, - false - ], - "parameters": { - "Left": [ - "Uuid", - "Varchar", - "Varchar", - "Varchar", - "Varchar", - "Varchar", - "Bool", - "Varchar", - "Int4", - "Timestamptz" - ] - } - }, - "query": "INSERT INTO realtor (\n id, name, bio, phone_number, email, profile_picture_url, show_projects, shortcode, remax_agent_id, time_created, last_updated\n) VALUES (\n $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $10\n) RETURNING *;" - }, "3acc0efdfdf6fd4e86b0f197cd27b7378507b82915127b76a6cf76a8f7cb5618": { "describe": { "columns": [ @@ -526,6 +538,102 @@ }, "query": "INSERT INTO project (\n id,\n title,\n description,\n realtor_id,\n media,\n project_condition,\n project_type,\n project_state,\n country,\n city, \n district,\n admin_tag,\n floors,\n finish_date,\n order_index,\n time_created,\n last_updated\n) VALUES (\n $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $16\n) RETURNING \n id,\n title,\n description,\n realtor_id,\n media as \"media: _\",\n project_condition as \"project_condition: _\",\n project_type as \"project_type: _\",\n project_state as \"project_state: _\",\n country,\n city, \n district,\n admin_tag,\n floors,\n finish_date,\n order_index,\n time_created,\n last_updated;" }, + "50f49e1256fe439b399167515eeb39423ab0618637d12c2b471e9aec9374286e": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "name", + "ordinal": 1, + "type_info": "Varchar" + }, + { + "name": "bio", + "ordinal": 2, + "type_info": "Varchar" + }, + { + "name": "phone_number", + "ordinal": 3, + "type_info": "Varchar" + }, + { + "name": "email", + "ordinal": 4, + "type_info": "Varchar" + }, + { + "name": "profile_picture_url", + "ordinal": 5, + "type_info": "Varchar" + }, + { + "name": "banner_picture_url", + "ordinal": 6, + "type_info": "Varchar" + }, + { + "name": "show_projects", + "ordinal": 7, + "type_info": "Bool" + }, + { + "name": "shortcode", + "ordinal": 8, + "type_info": "Varchar" + }, + { + "name": "remax_agent_id", + "ordinal": 9, + "type_info": "Int4" + }, + { + "name": "time_created", + "ordinal": 10, + "type_info": "Timestamptz" + }, + { + "name": "last_updated", + "ordinal": 11, + "type_info": "Timestamptz" + } + ], + "nullable": [ + false, + false, + false, + false, + true, + false, + true, + false, + false, + true, + false, + false + ], + "parameters": { + "Left": [ + "Uuid", + "Varchar", + "Varchar", + "Varchar", + "Varchar", + "Varchar", + "Varchar", + "Bool", + "Varchar", + "Int4", + "Timestamptz" + ] + } + }, + "query": "INSERT INTO realtor (\n id, name, bio, phone_number, email, profile_picture_url, banner_picture_url, show_projects, shortcode, remax_agent_id, time_created, last_updated\n) VALUES (\n $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $11\n) RETURNING *;" + }, "5356455cba4a2740f833ca895e41fa120164a7e1fad9edb367aa680a2353ee02": { "describe": { "columns": [ @@ -1009,6 +1117,140 @@ }, "query": "SELECT \n id,\n title,\n description,\n realtor_id,\n media as \"media: _\",\n project_condition as \"project_condition: _\",\n project_type as \"project_type: _\",\n project_state as \"project_state: _\",\n country,\n city,\n district,\n admin_tag,\n floors,\n finish_date,\n order_index,\n time_created,\n last_updated\nFROM project WHERE realtor_id = $1;" }, + "92abeebdeb9a2de864c868eccba9669958a01ce3a485355f22bf20357f001d61": { + "describe": { + "columns": [ + { + "name": "id", + "ordinal": 0, + "type_info": "Uuid" + }, + { + "name": "project_id", + "ordinal": 1, + "type_info": "Uuid" + }, + { + "name": "realtor_id", + "ordinal": 2, + "type_info": "Uuid" + }, + { + "name": "media: _", + "ordinal": 3, + "type_info": "Text" + }, + { + "name": "property_type: _", + "ordinal": 4, + "type_info": "Varchar" + }, + { + "name": "property_sale_type: _", + "ordinal": 5, + "type_info": "Varchar" + }, + { + "name": "country", + "ordinal": 6, + "type_info": "Varchar" + }, + { + "name": "city", + "ordinal": 7, + "type_info": "Varchar" + }, + { + "name": "district", + "ordinal": 8, + "type_info": "Varchar" + }, + { + "name": "order_index", + "ordinal": 9, + "type_info": "Int4" + }, + { + "name": "thumbnail_format: _", + "ordinal": 10, + "type_info": "Varchar" + }, + { + "name": "rooms", + "ordinal": 11, + "type_info": "Int2" + }, + { + "name": "bathrooms", + "ordinal": 12, + "type_info": "Float4" + }, + { + "name": "area", + "ordinal": 13, + "type_info": "Float4" + }, + { + "name": "parking_spots", + "ordinal": 14, + "type_info": "Int2" + }, + { + "name": "admin_tag", + "ordinal": 15, + "type_info": "Varchar" + }, + { + "name": "time_created", + "ordinal": 16, + "type_info": "Timestamptz" + }, + { + "name": "last_updated", + "ordinal": 17, + "type_info": "Timestamptz" + } + ], + "nullable": [ + false, + true, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + true, + false, + false + ], + "parameters": { + "Left": [ + "Uuid", + "Int8", + "Text", + "Text", + "Text", + "Text", + "Text", + "Int2", + "Float4", + "Float4", + "Int2", + "Float8", + "Float8" + ] + } + }, + "query": "SELECT \n p.id,\n p.project_id,\n p.realtor_id,\n p.media as \"media: _\",\n p.property_type as \"property_type: _\",\n p.property_sale_type as \"property_sale_type: _\",\n p.country,\n p.city,\n p.district,\n p.order_index,\n p.thumbnail_format as \"thumbnail_format: _\",\n p.rooms,\n p.bathrooms,\n p.area,\n p.parking_spots,\n p.admin_tag,\n p.time_created,\n p.last_updated\nFROM property p, property_arrangement pa\nWHERE p.realtor_id = $1\nAND pa.property_id = p.id\n-- FILTERS\nAND (pa.arrangement = $3 OR $3 IS null) -- Arrangement\nAND (p.property_type = $4 OR $4 IS null) -- Property Type\nAND (p.country = $5 OR $5 IS null) -- Country\nAND (p.city = $6 OR $6 IS null) -- City\nAND (p.district = $7 OR $7 IS null) -- District\nAND (p.rooms = $8 OR $8 IS null) -- Room amount\nAND (p.bathrooms = $9 OR $9 IS null) -- Bathroom amount\nAND (p.area >= $10 OR $10 IS null) -- Area greater than\nAND (p.parking_spots = $11 OR $11 IS null) -- Parking spots amount\nAND (pa.price <= $12 OR $12 IS null) -- Price Less than\nAND (pa.price >= $13 OR $13 IS null) -- Price Greater than\n-- END OF FILTERS\nORDER BY p.order_index DESC\nLIMIT 25 OFFSET $2;" + }, "a335033d78f1a2211afed07daff01d72152d05ad78fe068d62a42d3f08c83207": { "describe": { "columns": [ @@ -1435,228 +1677,6 @@ }, "query": "UPDATE property SET\n project_id = $2,\n realtor_id = $3,\n media = $4,\n property_type = $5,\n property_sale_type = $6,\n country = $7,\n city = $8,\n district = $9,\n order_index = $10,\n thumbnail_format = $11,\n rooms = $12,\n bathrooms = $13,\n area = $14,\n parking_spots = $15,\n admin_tag = $16,\n last_updated = $17\nWHERE id = $1\nRETURNING \n id,\n project_id,\n realtor_id,\n media as \"media: _\",\n property_type as \"property_type: _\",\n property_sale_type as \"property_sale_type: _\",\n country,\n city,\n district,\n order_index,\n thumbnail_format as \"thumbnail_format: _\",\n rooms,\n bathrooms,\n area,\n parking_spots,\n admin_tag,\n time_created,\n last_updated;" }, - "c571a9279bdcec6420fd1f80d8777832d13e135353a3d40aaf9549c5e80eccab": { - "describe": { - "columns": [ - { - "name": "id", - "ordinal": 0, - "type_info": "Uuid" - }, - { - "name": "name", - "ordinal": 1, - "type_info": "Varchar" - }, - { - "name": "bio", - "ordinal": 2, - "type_info": "Varchar" - }, - { - "name": "phone_number", - "ordinal": 3, - "type_info": "Varchar" - }, - { - "name": "email", - "ordinal": 4, - "type_info": "Varchar" - }, - { - "name": "profile_picture_url", - "ordinal": 5, - "type_info": "Varchar" - }, - { - "name": "show_projects", - "ordinal": 6, - "type_info": "Bool" - }, - { - "name": "shortcode", - "ordinal": 7, - "type_info": "Varchar" - }, - { - "name": "remax_agent_id", - "ordinal": 8, - "type_info": "Int4" - }, - { - "name": "time_created", - "ordinal": 9, - "type_info": "Timestamptz" - }, - { - "name": "last_updated", - "ordinal": 10, - "type_info": "Timestamptz" - } - ], - "nullable": [ - false, - false, - false, - false, - true, - false, - false, - false, - true, - false, - false - ], - "parameters": { - "Left": [ - "Uuid", - "Varchar", - "Varchar", - "Varchar", - "Varchar", - "Varchar", - "Bool", - "Int4", - "Timestamptz" - ] - } - }, - "query": "UPDATE realtor SET\n name = $2,\n bio = $3,\n phone_number = $4,\n email = $5,\n profile_picture_url = $6,\n show_projects = $7,\n remax_agent_id = $8,\n last_updated = $9\nWHERE id = $1\nRETURNING *;" - }, - "ca31c99797615d66e383432403a6c8baab4907ebad96944d38075a8917e1c4e9": { - "describe": { - "columns": [ - { - "name": "id", - "ordinal": 0, - "type_info": "Uuid" - }, - { - "name": "project_id", - "ordinal": 1, - "type_info": "Uuid" - }, - { - "name": "realtor_id", - "ordinal": 2, - "type_info": "Uuid" - }, - { - "name": "media: _", - "ordinal": 3, - "type_info": "Text" - }, - { - "name": "property_type: _", - "ordinal": 4, - "type_info": "Varchar" - }, - { - "name": "property_sale_type: _", - "ordinal": 5, - "type_info": "Varchar" - }, - { - "name": "country", - "ordinal": 6, - "type_info": "Varchar" - }, - { - "name": "city", - "ordinal": 7, - "type_info": "Varchar" - }, - { - "name": "district", - "ordinal": 8, - "type_info": "Varchar" - }, - { - "name": "order_index", - "ordinal": 9, - "type_info": "Int4" - }, - { - "name": "thumbnail_format: _", - "ordinal": 10, - "type_info": "Varchar" - }, - { - "name": "rooms", - "ordinal": 11, - "type_info": "Int2" - }, - { - "name": "bathrooms", - "ordinal": 12, - "type_info": "Float4" - }, - { - "name": "area", - "ordinal": 13, - "type_info": "Float4" - }, - { - "name": "parking_spots", - "ordinal": 14, - "type_info": "Int2" - }, - { - "name": "admin_tag", - "ordinal": 15, - "type_info": "Varchar" - }, - { - "name": "time_created", - "ordinal": 16, - "type_info": "Timestamptz" - }, - { - "name": "last_updated", - "ordinal": 17, - "type_info": "Timestamptz" - } - ], - "nullable": [ - false, - true, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - true, - false, - false - ], - "parameters": { - "Left": [ - "Uuid", - "Int8", - "Text", - "Text", - "Text", - "Text", - "Text", - "Int2", - "Float4", - "Float4", - "Int2", - "Float8", - "Float8" - ] - } - }, - "query": "SELECT \n p.id,\n p.project_id,\n p.realtor_id,\n p.media as \"media: _\",\n p.property_type as \"property_type: _\",\n p.property_sale_type as \"property_sale_type: _\",\n p.country,\n p.city,\n p.district,\n p.order_index,\n p.thumbnail_format as \"thumbnail_format: _\",\n p.rooms,\n p.bathrooms,\n p.area,\n p.parking_spots,\n p.admin_tag,\n p.time_created,\n p.last_updated\nFROM property p, property_arrangement pa\nWHERE p.realtor_id = $1\nAND pa.property_id = p.id\n-- FILTERS\nAND (pa.arrangement = $3 OR $3 IS null) -- Arrangement\nAND (p.property_type = $4 OR $4 IS null) -- Property Type\nAND (p.country = $5 OR $5 IS null) -- Country\nAND (p.city = $6 OR $6 IS null) -- City\nAND (p.district = $7 OR $7 IS null) -- District\nAND (p.rooms = $8 OR $8 IS null) -- Room amount\nAND (p.bathrooms = $9 OR $9 IS null) -- Bathroom amount\nAND (p.area >= $10 OR $10 IS null) -- Area greater than\nAND (p.parking_spots = $11 OR $11 IS null) -- Parking spots amount\nAND (pa.price <= $12 OR $12 IS null) -- Price Less than\nAND (pa.price >= $13 OR $13 IS null) -- Price Greater than\n-- END OF FILTERS\nORDER BY p.time_created DESC\nLIMIT 25 OFFSET $2;" - }, "e9fb0b1fe0e33d2a8aa4bc20be141a9f4bcd68d1c69af1dce93c43c8ba96ebc1": { "describe": { "columns": [ @@ -1795,28 +1815,33 @@ "type_info": "Varchar" }, { - "name": "show_projects", + "name": "banner_picture_url", "ordinal": 6, + "type_info": "Varchar" + }, + { + "name": "show_projects", + "ordinal": 7, "type_info": "Bool" }, { "name": "shortcode", - "ordinal": 7, + "ordinal": 8, "type_info": "Varchar" }, { "name": "remax_agent_id", - "ordinal": 8, + "ordinal": 9, "type_info": "Int4" }, { "name": "time_created", - "ordinal": 9, + "ordinal": 10, "type_info": "Timestamptz" }, { "name": "last_updated", - "ordinal": 10, + "ordinal": 11, "type_info": "Timestamptz" } ], @@ -1827,6 +1852,7 @@ false, true, false, + true, false, false, true, diff --git a/src/dao/realtor.rs b/src/dao/realtor.rs index 037805e..3b9d8e2 100644 --- a/src/dao/realtor.rs +++ b/src/dao/realtor.rs @@ -12,6 +12,7 @@ pub async fn insert_realtor(conn: &PgPool, realtor: Realtor) -> Result Result>, path_vars: Path<(Uuid, i64)>, query_params: web::Query>, -) -> TypedHttpResponse> { +) -> TypedHttpResponse> { let filters = parse_params_into_filters(query_params.0); services::property::fetch_realtor_properties_paged(&conn, path_vars.0, path_vars.1, filters) .await diff --git a/src/services/property.rs b/src/services/property.rs index 0511763..0fe8613 100644 --- a/src/services/property.rs +++ b/src/services/property.rs @@ -1,10 +1,10 @@ -use std::sync::Arc; +use std::{sync::Arc, collections::HashMap}; use actix_web_utils::extensions::typed_response::TypedHttpResponse; use err::MessageResource; use realtor_lp_types::{ - domain::property::Property, - dto::{filter::Filter, payloads::property::PropertyForCreationPayload}, + domain::{property::Property, price::PropertyPrice}, + dto::{filter::Filter, payloads::property::PropertyForCreationPayload, property_card::PropertyCard}, }; use sqlx::PgPool; use uuid::Uuid; @@ -93,12 +93,35 @@ pub async fn fetch_realtor_properties_paged( realtor_id: Uuid, page: i64, filters: Vec, -) -> TypedHttpResponse> { +) -> TypedHttpResponse> { let mut all_properties_filtered = handle_db_read_op!( dao::property::fetch_with_realtor_id_paged(conn, &realtor_id, &filters, &page) ); all_properties_filtered .iter_mut() .for_each(|property| property.admin_tag = None); // Remove admin tag for all - success!(all_properties_filtered) + + let mut property_ids: Vec = all_properties_filtered.iter().map(|property| property.id).collect(); + let arrangements = handle_db_read_op!(dao::property_arrangement::fetch_arrangements_with_property_ids(conn, &property_ids)); + let mut property_cards = Vec::new(); + let mut property_map: HashMap> = HashMap::new(); + for arrangement in arrangements { + if let Some(property_prices) = property_map.get_mut(&arrangement.property_id) { + property_prices.push(arrangement); + } else { + property_map.insert(arrangement.property_id, Vec::from([arrangement])); + } + } + property_ids.reverse(); + for (index, property_id) in property_ids.into_iter().enumerate() { + property_cards.push(PropertyCard { + property: all_properties_filtered.remove(index), + arrangements: match property_map.remove(&property_id) { + Some(arrangements) => arrangements, + None => Vec::new(), + } + }) + } + + success!(property_cards) }