Updated read route to return a projectCardDto more accurately sending to the frontend the location and the project details that need to be shown on a card

This commit is contained in:
Franklin 2023-03-24 08:38:31 -04:00
parent 5b86984645
commit 3558d6d184
6 changed files with 142 additions and 187 deletions

108
Cargo.lock generated
View File

@ -543,7 +543,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"scratch", "scratch",
"syn 2.0.2", "syn 2.0.8",
] ]
[[package]] [[package]]
@ -560,7 +560,7 @@ checksum = "631569015d0d8d54e6c241733f944042623ab6df7bc3be7466874b05fcdb1c5f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.2", "syn 2.0.8",
] ]
[[package]] [[package]]
@ -615,31 +615,20 @@ checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]] [[package]]
name = "dotenvy" name = "dotenvy"
version = "0.15.6" version = "0.15.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03d8c417d7a8cb362e0c37e5d815f5eb7c37f79ff93707329d5a194e42e54ca0" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
[[package]]
name = "dotenvy_codegen_impl"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e05611d49f33180c6989e426b1d63a5ac0651307f0459321b67b38cd9861d050"
dependencies = [
"dotenvy",
"proc-macro-hack",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "dotenvy_macro" name = "dotenvy_macro"
version = "0.15.1" version = "0.15.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f559fff643c8f40279ab9bc50dd3734c22efc1f386972995f52892fe414722a7" checksum = "cb0235d912a8c749f4e0c9f18ca253b4c28cfefc1d2518096016d6e3230b6424"
dependencies = [ dependencies = [
"dotenvy_codegen_impl", "dotenvy",
"proc-macro-hack", "proc-macro2",
"quote",
"syn 1.0.109",
] ]
[[package]] [[package]]
@ -942,16 +931,16 @@ dependencies = [
[[package]] [[package]]
name = "iana-time-zone" name = "iana-time-zone"
version = "0.1.53" version = "0.1.54"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" checksum = "0c17cc76786e99f8d2f055c11159e7f0091c42474dcc3189fbab96072e873e6d"
dependencies = [ dependencies = [
"android_system_properties", "android_system_properties",
"core-foundation-sys", "core-foundation-sys",
"iana-time-zone-haiku", "iana-time-zone-haiku",
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
"winapi", "windows",
] ]
[[package]] [[package]]
@ -1144,9 +1133,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]] [[package]]
name = "mime" name = "mime"
version = "0.3.16" version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
[[package]] [[package]]
name = "minimal-lexical" name = "minimal-lexical"
@ -1351,17 +1340,11 @@ version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro-hack"
version = "0.5.20+deprecated"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.52" version = "1.0.53"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" checksum = "ba466839c78239c09faf015484e5cc04860f88242cff4d03eb038f04b4699b73"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -1427,9 +1410,9 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.7.1" version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" checksum = "cce168fea28d3e05f158bda4576cf0c844d5045bc2cc3620fa0292ed5bb5814c"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"memchr", "memchr",
@ -1438,15 +1421,15 @@ dependencies = [
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.6.28" version = "0.6.29"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]] [[package]]
name = "reqwest" name = "reqwest"
version = "0.11.14" version = "0.11.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21eed90ec8570952d53b772ecf8f206aa1ec9a3d76b2521c56c42973f2d91ee9" checksum = "0ba30cc2c0cd02af1222ed216ba659cdb2f879dfe3181852fe7c50b1d0005949"
dependencies = [ dependencies = [
"base64 0.21.0", "base64 0.21.0",
"bytes", "bytes",
@ -1562,22 +1545,22 @@ checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.157" version = "1.0.158"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "707de5fcf5df2b5788fca98dd7eab490bc2fd9b7ef1404defc462833b83f25ca" checksum = "771d4d9c4163ee138805e12c710dd365e4f44be8be0503cb1bb9eb989425d9c9"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.157" version = "1.0.158"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78997f4555c22a7971214540c4a661291970619afd56de19f77e0de86296e1e5" checksum = "e801c1712f48475582b7696ac71e0ca34ebb30e09338425384269d9717c62cad"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.2", "syn 2.0.8",
] ]
[[package]] [[package]]
@ -1684,9 +1667,9 @@ dependencies = [
[[package]] [[package]]
name = "sqlx" name = "sqlx"
version = "0.6.2" version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9249290c05928352f71c077cc44a464d880c63f26f7534728cca008e135c0428" checksum = "f8de3b03a925878ed54a954f621e64bf55a3c1bd29652d0d1a17830405350188"
dependencies = [ dependencies = [
"sqlx-core", "sqlx-core",
"sqlx-macros", "sqlx-macros",
@ -1694,9 +1677,9 @@ dependencies = [
[[package]] [[package]]
name = "sqlx-core" name = "sqlx-core"
version = "0.6.2" version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcbc16ddba161afc99e14d1713a453747a2b07fc097d2009f4c300ec99286105" checksum = "fa8241483a83a3f33aa5fff7e7d9def398ff9990b2752b6c6112b83c6d246029"
dependencies = [ dependencies = [
"ahash 0.7.6", "ahash 0.7.6",
"atoi", "atoi",
@ -1749,9 +1732,9 @@ dependencies = [
[[package]] [[package]]
name = "sqlx-macros" name = "sqlx-macros"
version = "0.6.2" version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b850fa514dc11f2ee85be9d055c512aa866746adfacd1cb42d867d68e6a5b0d9" checksum = "9966e64ae989e7e575b19d7265cb79d7fc3cbbdf179835cb0d716f294c2049c9"
dependencies = [ dependencies = [
"dotenvy", "dotenvy",
"either", "either",
@ -1771,9 +1754,9 @@ dependencies = [
[[package]] [[package]]
name = "sqlx-rt" name = "sqlx-rt"
version = "0.6.2" version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24c5b2d25fa654cc5f841750b8e1cdedbe21189bf9a9382ee90bfa9dd3562396" checksum = "804d3f245f894e61b1e6263c84b23ca675d96753b5abfd5cc8597d86806e8024"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"tokio", "tokio",
@ -1809,9 +1792,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.2" version = "2.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59d3276aee1fa0c33612917969b5172b5be2db051232a6e4826f1a1a9191b045" checksum = "bcc02725fd69ab9f26eab07fad303e2497fad6fb9eba4f96c4d1687bdf704ad9"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1844,7 +1827,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.2", "syn 2.0.8",
] ]
[[package]] [[package]]
@ -2008,9 +1991,9 @@ checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
[[package]] [[package]]
name = "unicode-bidi" name = "unicode-bidi"
version = "0.3.12" version = "0.3.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d502c968c6a838ead8e69b2ee18ec708802f99db92a0d156705ec9ef801993b" checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
@ -2249,6 +2232,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdacb41e6a96a052c6cb63a144f24900236121c6f63f4f8219fef5977ecb0c25"
dependencies = [
"windows-targets",
]
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.45.0" version = "0.45.0"

View File

@ -3,16 +3,10 @@ SELECT
p.project_state as "project_state: _", p.project_state as "project_state: _",
p.project_type as "project_type: _", p.project_type as "project_type: _",
p.project_condition as "project_condition: _", p.project_condition as "project_condition: _",
p.agent_id, l.city,
p.location_id, l.district,
p.title,
p.description,
p.admin_tag,
p.finish_date, p.finish_date,
p.floors, p.media as "media: _"
p.media as "media: _",
p.time_created,
p.last_updated
FROM project p, location l FROM project p, location l
WHERE p.location_id = l.id WHERE p.location_id = l.id
-- Filters here: -- Filters here:

View File

@ -166,109 +166,6 @@
}, },
"query": "DELETE FROM location where id = $1;" "query": "DELETE FROM location where id = $1;"
}, },
"444248a6ee54ce3f8345077330be191e04cc9bdf31feba0e661efab1acf21716": {
"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": "agent_id",
"ordinal": 4,
"type_info": "Uuid"
},
{
"name": "location_id",
"ordinal": 5,
"type_info": "Uuid"
},
{
"name": "title",
"ordinal": 6,
"type_info": "Varchar"
},
{
"name": "description",
"ordinal": 7,
"type_info": "Text"
},
{
"name": "admin_tag",
"ordinal": 8,
"type_info": "Varchar"
},
{
"name": "finish_date",
"ordinal": 9,
"type_info": "Timestamp"
},
{
"name": "floors",
"ordinal": 10,
"type_info": "Int2"
},
{
"name": "media: _",
"ordinal": 11,
"type_info": "Text"
},
{
"name": "time_created",
"ordinal": 12,
"type_info": "Timestamptz"
},
{
"name": "last_updated",
"ordinal": 13,
"type_info": "Timestamptz"
}
],
"nullable": [
false,
false,
false,
false,
false,
false,
true,
false,
true,
false,
false,
false,
false,
false
],
"parameters": {
"Left": [
"Text",
"Text",
"Text",
"Text",
"Text",
"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 p.agent_id,\n p.location_id,\n p.title,\n p.description,\n p.admin_tag,\n p.finish_date,\n p.floors,\n p.media as \"media: _\",\n p.time_created,\n p.last_updated\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\n-- End of filters\nORDER BY p.time_created DESC\nLIMIT 50 OFFSET $6;"
},
"4ef2f2177dd00503913e281cf97bd922bcdc4b30ed834505eb8ea9a396f73331": { "4ef2f2177dd00503913e281cf97bd922bcdc4b30ed834505eb8ea9a396f73331": {
"describe": { "describe": {
"columns": [], "columns": [],
@ -293,6 +190,73 @@
}, },
"query": "DELETE FROM unit WHERE id = $1;" "query": "DELETE FROM unit WHERE id = $1;"
}, },
"7d674df64d815d97c15a4bb2b84fb4ab7f4289904d6fb8cf9537a1ec848d926c": {
"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": "district",
"ordinal": 5,
"type_info": "Varchar"
},
{
"name": "finish_date",
"ordinal": 6,
"type_info": "Timestamp"
},
{
"name": "media: _",
"ordinal": 7,
"type_info": "Text"
}
],
"nullable": [
false,
false,
false,
false,
false,
false,
false,
false
],
"parameters": {
"Left": [
"Text",
"Text",
"Text",
"Text",
"Text",
"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 l.district,\n p.finish_date,\n p.media as \"media: _\"\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\n-- End of filters\nORDER BY p.time_created DESC\nLIMIT 50 OFFSET $6;"
},
"825e1ac484241349c54e75bb77186ce41ea98fd17cabd7308e737a6c9c5812a9": { "825e1ac484241349c54e75bb77186ce41ea98fd17cabd7308e737a6c9c5812a9": {
"describe": { "describe": {
"columns": [ "columns": [

View File

@ -1,6 +1,6 @@
use jl_types::{ use jl_types::{
domain::{project::Project, project_state::ProjectState}, domain::{project::Project, project_state::ProjectState},
dto::filters::Filter, dto::{filters::Filter, project_card::ProjectCardDto},
}; };
use sqlx::{postgres::PgQueryResult, PgPool, Postgres, Transaction}; use sqlx::{postgres::PgQueryResult, PgPool, Postgres, Transaction};
use uuid::Uuid; use uuid::Uuid;
@ -83,7 +83,7 @@ pub async fn fetch_with_filters_paged(
conn: &PgPool, conn: &PgPool,
filters: &Vec<Filter>, filters: &Vec<Filter>,
page: &i64, page: &i64,
) -> Result<Vec<Project>, sqlx::Error> { ) -> Result<Vec<ProjectCardDto>, sqlx::Error> {
let offset = (page - 1) * 50; let offset = (page - 1) * 50;
let mut city_filter = None; let mut city_filter = None;
let mut district_filter = None; let mut district_filter = None;
@ -95,7 +95,7 @@ pub async fn fetch_with_filters_paged(
match filter { match filter {
Filter::InCity(city) => city_filter = Some(city), Filter::InCity(city) => city_filter = Some(city),
Filter::InDistrict(district) => district_filter = Some(district), Filter::InDistrict(district) => district_filter = Some(district),
Filter::Finished => project_state_filter = ProjectState::InConstruction, Filter::Finished => project_state_filter = ProjectState::Finished,
Filter::ByProjectType(project_type) => project_type_filter = Some(project_type), Filter::ByProjectType(project_type) => project_type_filter = Some(project_type),
Filter::ByProjectCondition(project_condition) => { Filter::ByProjectCondition(project_condition) => {
project_condition_filter = Some(project_condition) project_condition_filter = Some(project_condition)
@ -104,7 +104,7 @@ pub async fn fetch_with_filters_paged(
} }
sqlx::query_file_as!( sqlx::query_file_as!(
Project, ProjectCardDto,
"sql/project/fetch_with_filters_paged.sql", "sql/project/fetch_with_filters_paged.sql",
city_filter, city_filter,
district_filter, district_filter,

View File

@ -1,4 +1,4 @@
use std::{collections::HashMap, str::FromStr, sync::Arc}; use std::{collections::{HashMap, HashSet}, str::FromStr, sync::Arc};
use actix_web::{ use actix_web::{
get, get,
@ -8,10 +8,10 @@ use actix_web_utils::extensions::typed_response::TypedHttpResponse;
use err::MessageResource; use err::MessageResource;
use jl_types::{ use jl_types::{
domain::{ domain::{
agent::Agent, location::Location, project::Project, project_condition::ProjectCondition, agent::Agent, project_condition::ProjectCondition,
project_type::ProjectType, project_type::ProjectType,
}, },
dto::{filters::Filter, listing::Listing}, dto::{filters::Filter, listing::Listing, project_card::ProjectCardDto},
}; };
use sqlx::PgPool; use sqlx::PgPool;
use uuid::Uuid; use uuid::Uuid;
@ -26,7 +26,7 @@ pub async fn get_all_agents(db_conn: web::Data<Arc<PgPool>>) -> TypedHttpRespons
#[get("/locations")] #[get("/locations")]
pub async fn get_all_locations( pub async fn get_all_locations(
db_conn: web::Data<Arc<PgPool>>, db_conn: web::Data<Arc<PgPool>>,
) -> TypedHttpResponse<Vec<Location>> { ) -> TypedHttpResponse<HashSet<String>> {
services::read::get_all_locations(&db_conn).await services::read::get_all_locations(&db_conn).await
} }
@ -34,7 +34,7 @@ pub async fn get_all_locations(
pub async fn get_locations_in_city( pub async fn get_locations_in_city(
db_conn: web::Data<Arc<PgPool>>, db_conn: web::Data<Arc<PgPool>>,
city: Path<String>, city: Path<String>,
) -> TypedHttpResponse<Vec<Location>> { ) -> TypedHttpResponse<HashSet<String>> {
services::read::get_all_locations_in_city(&db_conn, &city).await services::read::get_all_locations_in_city(&db_conn, &city).await
} }
@ -43,7 +43,7 @@ pub async fn get_projects_paged(
db_conn: web::Data<Arc<PgPool>>, db_conn: web::Data<Arc<PgPool>>,
page: Path<i64>, page: Path<i64>,
query_params: web::Query<HashMap<String, String>>, query_params: web::Query<HashMap<String, String>>,
) -> TypedHttpResponse<Vec<Project>> { ) -> TypedHttpResponse<Vec<ProjectCardDto>> {
let filters = match parse_params_into_filters(query_params.0) { let filters = match parse_params_into_filters(query_params.0) {
Ok(filters) => filters, Ok(filters) => filters,
Err(msg) => return TypedHttpResponse::return_standard_error(400, msg), Err(msg) => return TypedHttpResponse::return_standard_error(400, msg),

View File

@ -1,7 +1,9 @@
use std::collections::HashSet;
use actix_web_utils::extensions::typed_response::TypedHttpResponse; use actix_web_utils::extensions::typed_response::TypedHttpResponse;
use jl_types::{ use jl_types::{
domain::{agent::Agent, location::Location, project::Project}, domain::{agent::Agent},
dto::{filters::Filter, listing::Listing}, dto::{filters::Filter, listing::Listing, project_card::ProjectCardDto},
}; };
use sqlx::PgPool; use sqlx::PgPool;
use uuid::Uuid; use uuid::Uuid;
@ -12,24 +14,27 @@ pub async fn get_all_agents(conn: &PgPool) -> TypedHttpResponse<Vec<Agent>> {
success!(handle_db_read_op!(dao::agent::fetch_all(conn))) success!(handle_db_read_op!(dao::agent::fetch_all(conn)))
} }
pub async fn get_all_locations(conn: &PgPool) -> TypedHttpResponse<Vec<Location>> { pub async fn get_all_locations(conn: &PgPool) -> TypedHttpResponse<HashSet<String>> {
success!(handle_db_read_op!(dao::location::fetch_all_locations(conn))) let locations: HashSet<String> = handle_db_read_op!(dao::location::fetch_all_locations(conn)).into_iter().map(|location| location.city).collect();
success!(locations)
} }
pub async fn get_all_locations_in_city( pub async fn get_all_locations_in_city(
conn: &PgPool, conn: &PgPool,
city: &String, city: &String,
) -> TypedHttpResponse<Vec<Location>> { ) -> TypedHttpResponse<HashSet<String>> {
success!(handle_db_read_op!(dao::location::get_locations_in_city( success!(handle_db_read_op!(dao::location::get_locations_in_city(
conn, city conn, city
))) )).into_iter().map(|location| location.district).collect())
} }
pub async fn get_projects_paged( pub async fn get_projects_paged(
conn: &PgPool, conn: &PgPool,
page: &i64, page: &i64,
filters: &Vec<Filter>, filters: &Vec<Filter>,
) -> TypedHttpResponse<Vec<Project>> { ) -> TypedHttpResponse<Vec<ProjectCardDto>> {
success!(handle_db_read_op!(dao::project::fetch_with_filters_paged( success!(handle_db_read_op!(dao::project::fetch_with_filters_paged(
conn, filters, page conn, filters, page
))) )))