From 5f1823ab4f5fc4dd56ab0053edc093cfc95f3e92 Mon Sep 17 00:00:00 2001 From: Franklin Date: Fri, 14 Apr 2023 17:24:22 -0400 Subject: [PATCH] Roomcount filter works now --- sql/project/fetch_with_filters_paged.sql | 3 ++- src/dao/project.rs | 5 +++++ src/routes/read.rs | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/sql/project/fetch_with_filters_paged.sql b/sql/project/fetch_with_filters_paged.sql index c6c963d..c553474 100644 --- a/sql/project/fetch_with_filters_paged.sql +++ b/sql/project/fetch_with_filters_paged.sql @@ -16,6 +16,7 @@ AND (LOWER(l.district) LIKE '%' || LOWER($2) || '%' OR $2 IS null) -- District F AND (p.project_type = $3 OR $3 IS null) -- ProjectType AND (p.project_condition = $4 OR $4 IS null) -- ProjectCondition AND (p.project_state = $5 OR $5 IS null) -- ProjectState +AND ((SELECT COUNT(*) FROM unit u WHERE u.project_id = p.id AND u.rooms = $6) > 0 OR $6 IS NULL) -- End of filters ORDER BY p.time_created DESC -LIMIT 50 OFFSET $6; \ No newline at end of file +LIMIT 50 OFFSET $7; \ No newline at end of file diff --git a/src/dao/project.rs b/src/dao/project.rs index 8fe1f55..4b89eea 100644 --- a/src/dao/project.rs +++ b/src/dao/project.rs @@ -90,6 +90,7 @@ pub async fn fetch_with_filters_paged( let mut project_type_filter = None; let mut project_state_filter = ProjectState::InConstruction; let mut project_condition_filter = None; + let mut project_room_count_filter = None; for filter in filters { match filter { @@ -100,6 +101,9 @@ pub async fn fetch_with_filters_paged( Filter::ByProjectCondition(project_condition) => { project_condition_filter = Some(project_condition) } + Filter::ByRoomCount(room_count) => { + project_room_count_filter = Some(room_count) + }, } } @@ -111,6 +115,7 @@ pub async fn fetch_with_filters_paged( project_type_filter as _, project_condition_filter as _, project_state_filter as _, + project_room_count_filter as _, offset ) .fetch_all(conn) diff --git a/src/routes/read.rs b/src/routes/read.rs index 6aae495..15a5ff6 100644 --- a/src/routes/read.rs +++ b/src/routes/read.rs @@ -60,6 +60,7 @@ pub async fn get_project_data( ) -> TypedHttpResponse { services::read::get_project_data(&db_conn, &project_id).await } + #[post("/contact")] pub async fn create_contact_request(db_conn: web::Data>, contact: web::Json) -> TypedHttpResponse<()> { services::read::create_contact(&db_conn, contact.0).await @@ -96,6 +97,13 @@ fn parse_params_into_filters( Err(_) => {} } } + "byroomcount" => { + let room_count = params.get(key).unwrap(); + match i32::from_str(&room_count) { + Ok(room_count) => filters.push(Filter::ByRoomCount(room_count)), + Err(_) => {}, + } + }, _ => {} }; }