From eadcd4604a9139fffcb3bd0d1c025d073f3d3f76 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 23 Jul 2020 03:55:33 +0000 Subject: [PATCH] Add getHeaderCoordinates to rider api. #424 --- .../RiderAPIHandler/CMBRiderAPIHandler.php | 108 +++++++++++++++++- 1 file changed, 105 insertions(+), 3 deletions(-) diff --git a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php index 27bfedc4..8834a106 100644 --- a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php @@ -98,6 +98,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + // retry until we get a unique id while (true) { @@ -191,6 +195,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + // assign rider to session $this->session->setRider($rider); @@ -248,6 +256,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + // make rider unavailable $rider = $this->session->getRider(); @@ -288,6 +300,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + // set rider to available to take on JOs $rider = $this->session->getRider(); @@ -322,6 +338,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + // set rider to unavailable to take on JOs $rider = $this->session->getRider(); @@ -371,6 +391,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + $rider = $this->session->getRider(); // get JOs assigned to rider for the month given @@ -577,6 +601,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + $rider = $this->session->getRider(); $qb = $this->em->getRepository(JobOrder::class)->createQueryBuilder('j'); @@ -906,6 +934,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + $jo_data = $this->formatJobOrderData($req, $jo); $data = [ @@ -927,6 +959,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + // TODO: put JO in job queue // TODO: refactor this into a jo handler class, so we don't have to repeat for control center @@ -955,12 +991,13 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + // set jo status to in transit $jo->setStatus(JOStatus::IN_TRANSIT); - // set rider's active JO - - // TODO: send mqtt event (?) // add event log @@ -991,6 +1028,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + $cancel_reason = $req->request->get('cancel_reason'); $jo->cancel($cancel_reason); @@ -1022,6 +1063,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + $jo->perform(); // add event log @@ -1050,6 +1095,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + $jo->requeue(); // set rider to null @@ -1096,6 +1145,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + // TODO: refactor this into a jo handler class, so we don't have to repeat for control center // set jo status to in progress @@ -1168,6 +1221,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + // add mode of payment $mode = $req->request->get('mode_of_payment'); $jo->setModeOfPayment($mode); @@ -1441,6 +1498,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + $inv = $jo->getInvoice(); $promo = $inv->getPromo(); @@ -1514,6 +1575,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + // set jo status to in progress $jo->setStatus(JOStatus::IN_PROGRESS); @@ -1541,6 +1606,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + // set customer signature $jo_extra = $jo->getJOExtra(); $sig_file = $this->handleFileUpload($req, 'signature'); @@ -1650,6 +1719,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + $rider = $this->session->getRider(); $rider->setActiveJobOrder($jo); @@ -1672,6 +1745,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + $odometer_reading = $req->request->get('odometer'); if ($odometer_reading > 999999) @@ -1728,6 +1805,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + $dest = $this->upload_dir; $img_1_file = $req->files->get('img_1'); @@ -1908,6 +1989,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + $rider = $this->session->getRider(); $rider_status = $rider->isAvailable(); @@ -1945,6 +2030,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + $rider = $this->session->getRider(); // check if we have an active JO @@ -2026,6 +2115,10 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // get longitude and latitude + // TODO: right now, we're just checking if we get the coordinates + $this->getHeaderCoordinates($req); + $rider = $this->session->getRider(); // check if rider is assigned to JO if ($jo->getRider() != null) @@ -2308,4 +2401,13 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $req->getScheme() . '://' . $req->getHttpHost() . $req->getBasePath() . '/uploads/jo_extra/' . $filename; } + + protected function getHeaderCoordinates(Request $req) + { + $x_lng = $req->headers->get('x-longitude'); + $x_lat = $req->headers->get('x-latitude'); + + error_log('rider_longitude ' . $x_lng); + error_log('rider_latitude ' . $x_lat); + } }