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