diff --git a/citywalls2/controllers/streetController.js b/citywalls2/controllers/streetController.js index d90c752..3a2e58c 100644 --- a/citywalls2/controllers/streetController.js +++ b/citywalls2/controllers/streetController.js @@ -148,27 +148,20 @@ exports.houseDetails = asyncHandler(async (req, res) => { }); -exports.filterPage = asyncHandler(async (req, res) => { +exports.filteredHouses = asyncHandler(async (req, res) => { + const { year, district, floors, apartments, condition, management_company, street } = req.query; + + // Получаем уникальные значения для фильтров const districtsCursor = await db.query('FOR house IN houses RETURN DISTINCT house.district'); const districts = await districtsCursor.all(); - + const managementCompaniesCursor = await db.query('FOR house IN houses RETURN DISTINCT house.management_company'); const managementCompanies = await managementCompaniesCursor.all(); - + const conditionsCursor = await db.query('FOR house IN houses RETURN DISTINCT house.condition'); const conditions = await conditionsCursor.all(); - - res.render('houses_filter', { - title: 'Дома Санкт-Петербурга', - districts, - managementCompanies, - conditions, - }); -}); - -exports.filteredHouses = asyncHandler(async (req, res) => { - const { year, district, floors, apartments, condition, management_company, street } = req.query; + // Строим запрос для фильтрации домов let query = 'FOR house IN houses'; const bindVars = {}; @@ -214,9 +207,14 @@ exports.filteredHouses = asyncHandler(async (req, res) => { const cursor = await db.query(query, bindVars); const houses = await cursor.all(); + // Передаем данные для фильтров и результаты поиска res.render('houses_list', { - title: 'Результаты фильтрации домов', + title: 'Дома Санкт-Петербурга', + districts, + managementCompanies, + conditions, houses, + filters: { year, district, floors, apartments, condition, management_company, street }, }); }); diff --git a/citywalls2/routes/main.js b/citywalls2/routes/main.js index f6060a9..9c770c4 100644 --- a/citywalls2/routes/main.js +++ b/citywalls2/routes/main.js @@ -21,8 +21,7 @@ router.get('/main/streets/:streetName/houses', street_controller.housesByStreet) // Маршрут для страницы дома router.get('/main/streets/:streetName/houses/:houseId', street_controller.houseDetails); -router.get('/main/houses', street_controller.filterPage); -router.get('/main/houses/filter', street_controller.filteredHouses); +router.get('/main/houses', street_controller.filteredHouses); module.exports = router;