Răsfoiți Sursa

Get Listing Updated

Anand Ayyappan 1 an în urmă
părinte
comite
e95bc0d7d3
1 a modificat fișierele cu 24 adăugiri și 6 ștergeri
  1. 24 6
      api/v1/getListing/index.php

+ 24 - 6
api/v1/getListing/index.php

@@ -1,12 +1,30 @@
 <?php
 require_once("../vendor/autoload.php");
+
 use MongoDB\Client;
 
 // Requires the MongoDB PHP Driver
 // https://www.mongodb.com/docs/drivers/php/
-
-$client = new Client('mongodb://kpadmin:AnandAyyappan1981@127.0.0.1:27017/?authSource=kpmaster');
-$collection = $client->selectCollection('kpmaster', 'kpu');
-$cursor = $collection->aggregate([['$geoNear' => ['near' => ['type' => 'Point', 'coordinates' => [76.768, 8.736]], 'spherical' => true, 'query' => ['srvs' => ['$all' => ['One']]], 'distanceField' => 'Dis', 'maxDistance' => 2000, 'includeLocs' => 'loc']], ['$project' => ['ID'=>'$oid', 'Name' => '$fn', 'Distance' => '$Dis', 'Location' => '$loc']]]);
-echo json_encode(iterator_to_array($cursor));
-?>
+$userInput = file_get_contents('php://input');
+$userInputData = json_decode($userInput, true);
+if ($userInputData !== null) {
+    $client = new Client('mongodb://kpadmin:AnandAyyappan1981@127.0.0.1:27017/?authSource=kpmaster');
+    $collection = $client->selectCollection('kpmaster', 'kpu');
+    $cursor = $collection->aggregate([['$geoNear' => ['near' => ['type' => 'Point', 'coordinates' => [$userInputData["long"], $userInputData["lat"]]], 'spherical' => true, 'query' => ['srvs' => ['$all' => [$userInputData["service"]]]], 'distanceField' => 'Dis', 'maxDistance' => $userInputData["maxdistance"], 'includeLocs' => 'loc']], ['$project' => ['ID' => '$oid', 'Name' => '$fn', 'Distance' => '$Dis', 'Location' => '$loc']]]);
+    $responseDataJson = iterator_to_array($cursor);
+    $dCount = Count($responseDataJson);
+    if ($dCount > 0) {
+        $message['status'] = true;
+        $message['count'] = $dCount;
+        $message['data'] = $responseDataJson;
+    } else {
+        $message['status'] = true;
+        $message['count'] = $dCount;
+        $message['statusMessage'] = "No Records Found!";
+    }
+} else {
+    $message['status'] = false;
+    $message['statusCode'] = "KP001";
+    $message['statusMessage'] = "Data Not Received";
+}
+echo json_encode($message);