From 7a2996d4e585cb22d9077dec6ff84ce858782d03 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 19 Jun 2020 04:16:45 +0000 Subject: [PATCH] Add getStatus to rider API. #428 --- config/routes/cmb_rider_api.yaml | 5 ++++ src/Controller/CMBRAPIController.php | 25 +++++++++++++++++++ .../RiderAPIHandler/CMBRiderAPIHandler.php | 25 +++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/config/routes/cmb_rider_api.yaml b/config/routes/cmb_rider_api.yaml index eb4f2186..03e89f5b 100644 --- a/config/routes/cmb_rider_api.yaml +++ b/config/routes/cmb_rider_api.yaml @@ -129,3 +129,8 @@ cmb_rapi_jo_finish_photos_upload: path: /cmbrapi/uploadfinishphotos controller: App\Controller\CMBRAPIController::uploadFinishPhotos methods: [POST] + +cmb_rapi_status: + path: /cmbrapi/status + controller: App\Controller\CMBRAPIController::getStatus + methods: [GET] diff --git a/src/Controller/CMBRAPIController.php b/src/Controller/CMBRAPIController.php index 2d503831..ce5868c5 100644 --- a/src/Controller/CMBRAPIController.php +++ b/src/Controller/CMBRAPIController.php @@ -642,4 +642,29 @@ class CMBRAPIController extends Controller // response return $res->getReturnResponse(); } + + public function getStatus(Request $req, RiderAPIHandlerInterface $rapi_handler) + { + $res = new NewAPIResult(); + + $data = $rapi_handler->getStatus($req); + + if (isset($data['error'])) + { + $message = $data['error']; + $title = $data['title']; + + $res->setError(true) + ->setErrorTitle($title) + ->setErrorMessage($message); + } + else + { + $res->setData($data); + } + + // response + return $res->getReturnResponse(); + } + } diff --git a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php index 8231d2ac..14da1e6e 100644 --- a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php @@ -1623,6 +1623,31 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + public function getStatus(Request $req) + { + $required_params = []; + $data = $this->checkParamsAndKey($req, $required_params); + if (isset($data['error'])) + { + $data['title'] = 'Failed Get Status'; + return $data; + } + + $rider = $this->session->getRider(); + + $rider_status = $rider->isAvailable(); + + $status = 'Offline'; + if ($rider_status) + $status = 'Online'; + + $data = [ + 'status' => $status, + ]; + + return $data; + } + protected function checkMissingParameters(Request $req, $params = []) { $missing = [];