Added location search filters
This commit is contained in:
parent
21e38519d2
commit
e9244efb2f
2
.env
2
.env
|
@ -1,2 +1,2 @@
|
||||||
DATABASE_URL="postgres://root:NMWrHZcu9QCu6wlmRUeEw1vXUYq7JhQYSPICTnl5yN9Pu5NIHUOcaj2noV9ejhFgfk5AfKIM2e9x97rbGCwbgTpVa3Fe8nfHgrYLZ2B36sOININQG60T2vIsQX3gkE6U@backend.blancoinfante.com:9102/postgres"
|
DATABASE_URL="postgres://root:NMWrHZcu9QCu6wlmRUeEw1vXUYq7JhQYSPICTnl5yN9Pu5NIHUOcaj2noV9ejhFgfk5AfKIM2e9x97rbGCwbgTpVa3Fe8nfHgrYLZ2B36sOININQG60T2vIsQX3gkE6U@backend.blancoinfante.com:9102/postgres"
|
||||||
SQLX_OFFLINE=TRUE
|
SQLX_OFFLINE=FALSE
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug",
|
||||||
|
"program": "${workspaceFolder}/<executable file>",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -7,15 +7,18 @@ p.state as "state: _",
|
||||||
p.time_created,
|
p.time_created,
|
||||||
p.last_updated
|
p.last_updated
|
||||||
FROM property p, property_details pd, location l where pd.property_id = p.id AND pd.location_id = l.id
|
FROM property p, property_details pd, location l where pd.property_id = p.id AND pd.location_id = l.id
|
||||||
AND (p.time_created <= $1 OR $1 = null) -- Before Filter
|
AND (p.time_created <= $1 OR $1 IS null) -- Before Filter
|
||||||
AND (p.time_created >= $2 OR $2 = null) -- After Filter
|
AND (p.time_created >= $2 OR $2 IS null) -- After Filter
|
||||||
AND (p.title LIKE ('%' || LOWER($3) || '%') OR $3 = null) -- Title filter (like)
|
AND (LOWER(p.title) LIKE '%' || LOWER($3) || '%' OR $3 IS null) -- Title filter (like)
|
||||||
AND (p.description LIKE ('%' || LOWER($4) || '%') OR $4 = null) -- Description Filter (like)
|
AND (LOWER(p.description) LIKE '%' || LOWER($4) || '%' OR $4 IS null) -- Description Filter (like)
|
||||||
AND (pd.meters > $5 OR $5 = null) -- Bigger than or equal to filter
|
AND (pd.meters > $5 OR $5 IS null) -- Bigger than or equal to filter
|
||||||
AND (pd.meters < $6 OR $6 = null) -- Smaller than or equal to filter
|
AND (pd.meters < $6 OR $6 IS null) -- Smaller than or equal to filter
|
||||||
AND (pd.location_id = $7 OR $7 = null) -- Location Filter
|
AND (LOWER(l.country) LIKE '%' || LOWER($7) || '%' OR $7 IS null) -- Location Filter
|
||||||
AND (pd.listing_type LIKE $8 || '%' OR $8 = null) -- Listing type filter
|
AND (LOWER(l.province) LIKE '%' || LOWER($8) || '%' OR $8 IS null) -- Location Filter
|
||||||
AND (split_part(pd.listing_type, ' ', 2)::FLOAT8 >= $9::FLOAT8 OR $9 = null) -- More expensive than filter
|
AND (LOWER(l.city) LIKE '%' || LOWER($9) || '%' OR $9 IS null) -- Location Filter
|
||||||
AND (split_part(pd.listing_type, ' ', 2)::FLOAT8 <= $10::FLOAT8 OR $10 = null) -- More expensive than filter
|
AND (LOWER(l.district) LIKE '%' || LOWER($10) || '%' OR $10 IS null) -- Location Filter
|
||||||
|
AND (pd.listing_type LIKE $11 || '%' OR $11 IS null) -- Listing type filter
|
||||||
|
AND (split_part(pd.listing_type, ' ', 2)::FLOAT8 >= $12::FLOAT8 OR $12 IS null) -- More expensive than filter
|
||||||
|
AND (split_part(pd.listing_type, ' ', 2)::FLOAT8 <= $13::FLOAT8 OR $13 IS null) -- More expensive than filter
|
||||||
ORDER BY p.time_created DESC
|
ORDER BY p.time_created DESC
|
||||||
LIMIT 25 OFFSET $11
|
LIMIT 25 OFFSET $14
|
|
@ -41,7 +41,10 @@ pub async fn fetch_properties_paged_with_filters(
|
||||||
let mut description_filter = None;
|
let mut description_filter = None;
|
||||||
let mut bigger_filter = None;
|
let mut bigger_filter = None;
|
||||||
let mut smaller_filter = None;
|
let mut smaller_filter = None;
|
||||||
let mut location_filter = None;
|
let mut country_filter = None;
|
||||||
|
let mut province_filter = None;
|
||||||
|
let mut city_filter = None;
|
||||||
|
let mut district_filter = None;
|
||||||
let mut listing_type_filter = None;
|
let mut listing_type_filter = None;
|
||||||
let mut more_expensive_than_filter = None;
|
let mut more_expensive_than_filter = None;
|
||||||
let mut cheaper_than_filter = None;
|
let mut cheaper_than_filter = None;
|
||||||
|
@ -56,9 +59,19 @@ pub async fn fetch_properties_paged_with_filters(
|
||||||
PropertyFilter::Description(description_like) => {
|
PropertyFilter::Description(description_like) => {
|
||||||
description_filter = Some(description_like)
|
description_filter = Some(description_like)
|
||||||
}
|
}
|
||||||
PropertyFilter::Location(location_id) => location_filter = Some(location_id),
|
PropertyFilter::Country(country) => country_filter = Some(country),
|
||||||
|
PropertyFilter::Province(province) => province_filter = Some(province),
|
||||||
|
PropertyFilter::City(city) => city_filter = Some(city),
|
||||||
|
PropertyFilter::District(district) => district_filter = Some(district),
|
||||||
PropertyFilter::MoreExpensiveThan(listing_type) => {
|
PropertyFilter::MoreExpensiveThan(listing_type) => {
|
||||||
listing_type_filter = Some(listing_type.to_string().split(" ").collect::<String>());
|
let listing_type_string = listing_type.to_string();
|
||||||
|
let listing_type_split = listing_type_string.split(" ").collect::<Vec<&str>>();
|
||||||
|
match listing_type_split.first() {
|
||||||
|
Some(listing_type_str) => {
|
||||||
|
listing_type_filter = Some(listing_type_str.to_string().clone())
|
||||||
|
},
|
||||||
|
None => {},
|
||||||
|
}
|
||||||
more_expensive_than_filter = match listing_type {
|
more_expensive_than_filter = match listing_type {
|
||||||
remax_types::domain::property_details::ListingType::Rent(amount) => {
|
remax_types::domain::property_details::ListingType::Rent(amount) => {
|
||||||
Some(amount)
|
Some(amount)
|
||||||
|
@ -70,7 +83,14 @@ pub async fn fetch_properties_paged_with_filters(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PropertyFilter::CheaperThan(listing_type) => {
|
PropertyFilter::CheaperThan(listing_type) => {
|
||||||
listing_type_filter = Some(listing_type.to_string().split(" ").collect::<String>());
|
let listing_type_string = listing_type.to_string();
|
||||||
|
let listing_type_split = listing_type_string.split(" ").collect::<Vec<&str>>();
|
||||||
|
match listing_type_split.first() {
|
||||||
|
Some(listing_type_str) => {
|
||||||
|
listing_type_filter = Some(listing_type_str.to_string().clone())
|
||||||
|
},
|
||||||
|
None => {},
|
||||||
|
}
|
||||||
cheaper_than_filter = match listing_type {
|
cheaper_than_filter = match listing_type {
|
||||||
remax_types::domain::property_details::ListingType::Rent(amount) => {
|
remax_types::domain::property_details::ListingType::Rent(amount) => {
|
||||||
Some(amount)
|
Some(amount)
|
||||||
|
@ -92,7 +112,10 @@ pub async fn fetch_properties_paged_with_filters(
|
||||||
description_filter,
|
description_filter,
|
||||||
bigger_filter,
|
bigger_filter,
|
||||||
smaller_filter,
|
smaller_filter,
|
||||||
location_filter,
|
country_filter,
|
||||||
|
province_filter,
|
||||||
|
city_filter,
|
||||||
|
district_filter,
|
||||||
listing_type_filter,
|
listing_type_filter,
|
||||||
more_expensive_than_filter,
|
more_expensive_than_filter,
|
||||||
cheaper_than_filter,
|
cheaper_than_filter,
|
||||||
|
|
|
@ -65,12 +65,21 @@ fn parse_params_into_filters(params: HashMap<String, String>) -> Result<Vec<Prop
|
||||||
let description_like = params.get(key).unwrap();
|
let description_like = params.get(key).unwrap();
|
||||||
filters.push(PropertyFilter::Description(description_like.clone()));
|
filters.push(PropertyFilter::Description(description_like.clone()));
|
||||||
},
|
},
|
||||||
"location" => {
|
"country" => {
|
||||||
let uid = match Uuid::from_str(params.get(key).unwrap()) {
|
let country = params.get(key).unwrap().clone();
|
||||||
Ok(id) => id,
|
filters.push(PropertyFilter::Country(country));
|
||||||
Err(error) => return Err(MessageResource::new_from_string(error.to_string())),
|
},
|
||||||
};
|
"province" => {
|
||||||
filters.push(PropertyFilter::Location(uid));
|
let province = params.get(key).unwrap().clone();
|
||||||
|
filters.push(PropertyFilter::Province(province));
|
||||||
|
},
|
||||||
|
"city" => {
|
||||||
|
let city = params.get(key).unwrap().clone();
|
||||||
|
filters.push(PropertyFilter::City(city));
|
||||||
|
},
|
||||||
|
"district" => {
|
||||||
|
let district = params.get(key).unwrap().clone();
|
||||||
|
filters.push(PropertyFilter::District(district));
|
||||||
},
|
},
|
||||||
"cheaperthan" => {
|
"cheaperthan" => {
|
||||||
let cheaper_than = params.get(key).unwrap().clone();
|
let cheaper_than = params.get(key).unwrap().clone();
|
||||||
|
|
Loading…
Reference in New Issue