|
@@ -1,14 +1,34 @@
|
|
|
<?php
|
|
|
-require_once("../../../mdb/vendor/autoload.php");
|
|
|
+require_once("../vendor/autoload.php");
|
|
|
+
|
|
|
use MongoDB\BSON\ObjectId;
|
|
|
use MongoDB\Client;
|
|
|
+use Firebase\JWT\JWT;
|
|
|
+use Firebase\JWT\Key;
|
|
|
|
|
|
-// Requires the MongoDB PHP Driver
|
|
|
-// https://www.mongodb.com/docs/drivers/php/
|
|
|
+$userInput = file_get_contents('php://input');
|
|
|
+$userInputData = json_decode($userInput, true);
|
|
|
+if ($userInputData !== null) {
|
|
|
+ $headers = explode(" ", trim($_SERVER["HTTP_AUTHORIZATION"]));
|
|
|
+ $key = '97eda3db6f898bfb1f821178d1c27064';
|
|
|
+ $jwt = $headers[1];
|
|
|
+ $decoded = JWT::decode($jwt, new Key($key, 'HS256'));
|
|
|
+ //print_r($decoded);
|
|
|
+ $client = new Client('mongodb://kpadmin:AnandAyyappan1981@127.0.0.1:27017/?authSource=kpmaster');
|
|
|
+ $collection = $client->selectCollection('kpmaster', 'kpu');
|
|
|
+ $return = $collection->updateOne(['_id' => new ObjectId($decoded->kpid)], ['$set' => ['location' => ['coordinates' => [$userInputData["long"], $userInputData["lat"]], 'type' => "Point"]]]);
|
|
|
|
|
|
-$client = new Client('mongodb://kpadmin:AnandAyyappan1981@127.0.0.1:27017/?authSource=kpmaster');
|
|
|
-$collection = $client->selectCollection('kpmaster', 'kpu');
|
|
|
-$return = $collection->updateOne(['_id' => new ObjectId('64b0f61b8b3742ad72109e80')], ['$set' => ['location' => ['coordinates' => [76.7682501,8.73673601],'type'=> "Point"]]]);
|
|
|
-printf("Matched %d document(s)\n", $return->getMatchedCount());
|
|
|
-printf("Modified %d document(s)\n", $return->getModifiedCount());
|
|
|
-?>
|
|
|
+ if ($return->getModifiedCount() == 1) {
|
|
|
+ $message['status'] = true;
|
|
|
+ $message['statusMessage'] = "Location updated successfully";
|
|
|
+ } else {
|
|
|
+ $message['status'] = false;
|
|
|
+ $message['statusCode'] = 'KP005';
|
|
|
+ $message['statusMessage'] = "Location updation Failed";
|
|
|
+ }
|
|
|
+} else {
|
|
|
+ $message['status'] = false;
|
|
|
+ $message['statusCode'] = "KP001";
|
|
|
+ $message['statusMessage'] = "Data Not Received";
|
|
|
+}
|
|
|
+echo json_encode($message);
|