diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 4925cf9b..d85978a8 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -26,6 +26,7 @@ use App\Service\InvoiceCreator; use App\Service\RisingTideGateway; use App\Service\MQTTClient; use App\Service\GeofenceTracker; +use App\Service\RiderTracker; use App\Entity\MobileSession; use App\Entity\Customer; @@ -1116,7 +1117,7 @@ class APIController extends Controller return $res->getReturnResponse(); } - public function getRiderStatus(Request $req) + public function getRiderStatus(Request $req, RiderTracker $rt) { $required_params = []; $em = $this->getDoctrine()->getManager(); @@ -1243,8 +1244,9 @@ class APIController extends Controller case JOStatus::ASSIGNED: case JOStatus::IN_TRANSIT: case JOStatus::IN_PROGRESS: - $coord = $jo->getHub()->getCoordinates(); $rider = $jo->getRider(); + // get rider coordinates from redis + $coord = $rt->getRiderLocation($rider->getID()); // default image url $url_prefix = $req->getSchemeAndHttpHost(); diff --git a/src/Service/RiderTracker.php b/src/Service/RiderTracker.php index 59bf1f17..c34d215d 100644 --- a/src/Service/RiderTracker.php +++ b/src/Service/RiderTracker.php @@ -33,26 +33,25 @@ class RiderTracker public function getRiderLocation($rider_id) { - // check if rider id exists or is valid - $rider = $this->em->getRepository(Rider::class)->find($rider_id); - if ($rider != null) + $coordinates = new Point(0,0); + $key = $this->getRiderKey($rider_id); + + // check redis cache for rider information + if (($this->redis->hexists($key, 'longitude')) && + ($this->redis->hexists($key, 'latitude'))) { - $coordinates = $rider->getHub()->getCoordinates(); - - $key = $this->getRiderKey($rider_id); - - // check redis cache for rider information - if (($this->redis->hexists($key, 'longitude')) && - ($this->redis->hexists($key, 'latitude'))) - { - $long = $this->redis->hget($key, 'longitude'); - $lat = $this->redis->hget($key, 'latitude'); - - $coordinates = new Point($long, $lat); - } - - return $coordinates; + $long = $this->redis->hget($key, 'longitude'); + $lat = $this->redis->hget($key, 'latitude'); + $coordinates = new Point($long, $lat); } + else + { + $rider = $this->em->getRepository(Rider::class)->find($rider_id); + $coordinates = $rider->getHub()->getCoordinates(); + } + + return $coordinates; + } }