From b3b46bca7bbbccccb027c1038045be78bacc3edb Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 30 Apr 2020 05:38:41 +0000 Subject: [PATCH] Add versionCheck API call. #392 --- .env.dist | 3 +++ config/resq.services.yaml | 1 + config/routes/api.yaml | 5 ++++ config/services.yaml | 1 + src/Controller/APIController.php | 45 ++++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+) diff --git a/.env.dist b/.env.dist index ead1c943..bd82f980 100644 --- a/.env.dist +++ b/.env.dist @@ -71,3 +71,6 @@ API_LOGGING=set_to_true_or_false CUST_DISTANCE_LIMIT=set_to_number MAPTILER_API_KEY=map_tiler_api_key + +# API version +API_VERSION=insert_api_version_here diff --git a/config/resq.services.yaml b/config/resq.services.yaml index 284b7b73..82eb4cc5 100644 --- a/config/resq.services.yaml +++ b/config/resq.services.yaml @@ -12,6 +12,7 @@ parameters: app_access_key: 'access_keys' cvu_brand_id: "%env(CVU_BRAND_ID)%" country_code: "%env(COUNTRY_CODE)%" + api_version: "%env(API_VERSION)%" services: # default configuration for services in *this* file diff --git a/config/routes/api.yaml b/config/routes/api.yaml index aa1ce722..2d9f8925 100644 --- a/config/routes/api.yaml +++ b/config/routes/api.yaml @@ -159,3 +159,8 @@ api_new_jo_request: path: /api/new_job_order controller: App\Controller\APIController::newRequestJobOrder methods: [POST] + +api_version_check: + path: /api/version_check + controller: App\Controller\APIController::versionCheck + methods: [GET] diff --git a/config/services.yaml b/config/services.yaml index 284b7b73..82eb4cc5 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -12,6 +12,7 @@ parameters: app_access_key: 'access_keys' cvu_brand_id: "%env(CVU_BRAND_ID)%" country_code: "%env(COUNTRY_CODE)%" + api_version: "%env(API_VERSION)%" services: # default configuration for services in *this* file diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 1e14bca2..35758290 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -2642,6 +2642,51 @@ class APIController extends Controller implements LoggedController return $res->getReturnResponse(); } + public function versionCheck(Request $req) + { + $res = new APIResult(); + + $required_params = [ + 'version', + ]; + + $missing = $this->checkMissingParameters($req, $required_params); + if (count($missing) > 0) + { + $params = implode(', ', $missing); + $res->setError(true) + ->setErrorMessage('Missing parameter(s): ' . $params); + return $res->getReturnResponse(); + } + + $need_update = false; + + $api_version = $this->getParameter('api_version'); + + $app_version = $req->query->get('version'); + + $api_v = explode('.', $api_version); + $app_v = explode('.', $app_version); + + if ($api_v[0] < $app_v[0]) + { + $res->setError(true) + ->setErrorMessage('Invalid application version: ' . $app_version); + return $res->getReturnResponse(); + } + + if ($api_v[0] > $app_v[0]) + $need_update = true; + + $data = [ + 'need_update' => $need_update, + ]; + + $res->setData($data); + + return $res->getReturnResponse(); + } + protected function findCustomerByNumber($number) { $em = $this->getDoctrine()->getManager();