Skip to content

Commit

Permalink
отображение и фильтрация домов на одной странице done
Browse files Browse the repository at this point in the history
  • Loading branch information
elcstazi committed Dec 11, 2024
1 parent dc52bd7 commit 8c1de61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
28 changes: 13 additions & 15 deletions citywalls2/controllers/streetController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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 },
});
});

3 changes: 1 addition & 2 deletions citywalls2/routes/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 8c1de61

Please sign in to comment.