diff --git a/backend/src/customers/controllers.ts b/backend/src/customers/controllers.ts index 83983c4..e837aeb 100644 --- a/backend/src/customers/controllers.ts +++ b/backend/src/customers/controllers.ts @@ -148,6 +148,26 @@ const getAllDocsByClusterIDs = async ( return datas; }; + +/** + * Finds all clusters within specified coordinates + * @param lower_left coordinates of lower left binding of location range + * @param upper_right coordinates of upper right binding of location range + * @returns list of cluster IDs that fall within location range + */ +const getClustersByLocation = async ( + lower_left: number[], + upper_right: number[] +) => + ClusterModel.find({ + $and: [ + { "location.0": { $gte: lower_left[0] } }, + { "location.0": { $lte: upper_right[0] } }, + { "location.1": { $gte: lower_left[1] } }, + { "location.1": { $lte: upper_right[1] } } + ] + }) + export default { getClusters, insertCluster, @@ -160,5 +180,6 @@ export default { getDataByNetId, insertData, deleteData, - getAllDocsByClusterIDs, + getClustersByLocation, + getAllDocsByClusterIDs }; diff --git a/backend/src/customers/views.ts b/backend/src/customers/views.ts index 4df7dbd..ffb908a 100644 --- a/backend/src/customers/views.ts +++ b/backend/src/customers/views.ts @@ -95,4 +95,18 @@ docRouter.get("/clusterData/", async (req, res) => { .send(successJson(await DocController.getAllDocsByClusterIDs(clusterIds, minDate, maxDate))); }); -export default docRouter; \ No newline at end of file +/** + * Gets all cluster IDs in location range [lower_left, upper_right] + */ +docRouter.post("/get-clusters-in-range/", async (req, res) => { + const { lower_left, upper_right } = req.body; + res + .status(200) + .send( + successJson( + await DocController.getClustersByLocation(lower_left, upper_right) + ) + ); +}); + +export default docRouter;