From f8f86a2fd25fd8f97ebb74aa807449eb5f0d0a9d Mon Sep 17 00:00:00 2001 From: Saikat Das <151205239+SaikatDash@users.noreply.github.com> Date: Wed, 14 Jan 2026 12:24:31 +0530 Subject: [PATCH 1/2] Update property.js --- backend/models/property.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/backend/models/property.js b/backend/models/property.js index 695c946..a7d7f3e 100644 --- a/backend/models/property.js +++ b/backend/models/property.js @@ -2,6 +2,25 @@ const mongoose = require("mongoose"); const propertySchema = new mongoose.Schema( { + title: String, + price: Number, + category: String, + + city: String, + state: String, + area: String, + + location: { + type: { + type: String, + enum: ["Point"], + required: true + }, + coordinates: { + type: [Number], // [longitude, latitude] + required: true + } + } title: { type: String, required: [true, "Title is required"], @@ -163,5 +182,4 @@ propertySchema.virtual("isAvailable").get(function () { }); const Property = mongoose.model("Property", propertySchema); - module.exports = Property; From d500dbe62598aca1a7c8b2240440d00ca16df074 Mon Sep 17 00:00:00 2001 From: Saikat Das <151205239+SaikatDash@users.noreply.github.com> Date: Wed, 14 Jan 2026 12:32:43 +0530 Subject: [PATCH 2/2] Implement property search functionality Added a searchProperties function to filter properties by city, state, and geographical location. --- backend/controllers/propertyController.js | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/backend/controllers/propertyController.js b/backend/controllers/propertyController.js index be041b4..15596de 100644 --- a/backend/controllers/propertyController.js +++ b/backend/controllers/propertyController.js @@ -34,6 +34,37 @@ const createProperty = async (req, res) => { res.status(500).json({ message: "Server Error" }); } }; +exports.searchProperties = async (req, res) => { + try { + const { city, state, lat, lng, radius = 5 } = req.query; + + let query = {}; + + // City / State filter + if (city) query.city = new RegExp(city, "i"); + if (state) query.state = new RegExp(state, "i"); + + // Geo-based search + if (lat && lng) { + query.location = { + $near: { + $geometry: { + type: "Point", + coordinates: [lng, lat] + }, + $maxDistance: radius * 1000 // km → meters + } + }; + } + + const properties = await Property.find(query); + + res.status(200).json(properties); + } catch (error) { + res.status(500).json({ message: error.message }); + } +}; + // @desc Get all properties // @route GET /api/properties