From 719cccf778503efb21c4094cbba0ee9a75ea0571 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 2 Apr 2020 03:33:02 +0000 Subject: [PATCH] Add API call to get warranties when given a list of serial numbers. #372 --- .../api-bundle/Command/TestAPICommand.php | 18 +++++++-- config/api_acl.yaml | 2 + config/routes/capi.yaml | 6 +++ src/Controller/CAPI/WarrantyController.php | 40 +++++++++++++++++++ 4 files changed, 63 insertions(+), 3 deletions(-) diff --git a/catalyst/api-bundle/Command/TestAPICommand.php b/catalyst/api-bundle/Command/TestAPICommand.php index 7e959808..a8a2be2a 100644 --- a/catalyst/api-bundle/Command/TestAPICommand.php +++ b/catalyst/api-bundle/Command/TestAPICommand.php @@ -64,7 +64,7 @@ class TestAPICommand extends Command 'start' => '1', ]; - $api->get('/capi/warranties', $params); + //$api->get('/capi/warranties', $params); // warranty find @@ -123,7 +123,7 @@ class TestAPICommand extends Command // privacy policy $privacy_policy_id = 2; - $api->get('/capi/privacy_policy/' . $privacy_policy_id ); + //$api->get('/capi/privacy_policy/' . $privacy_policy_id ); // register new customer $params = [ @@ -137,6 +137,18 @@ class TestAPICommand extends Command 'v_condition' => 'new', 'v_fuel_type' => 'gas', ]; - $api->post('/capi/quick_registration', $params); + //$api->post('/capi/quick_registration', $params); + + // get warranties given list of serial numbers + $serial_list = [ + 'AJ34LJADR12134LKJM4', + 'AJ34LJADR12134LKJL5', + ]; + + $params = [ + 'serial_list' => $serial_list, + ]; + + $api->post('/capi/warranties_list', $params); } } diff --git a/config/api_acl.yaml b/config/api_acl.yaml index 2ff18704..a7ad72d5 100644 --- a/config/api_acl.yaml +++ b/config/api_acl.yaml @@ -20,6 +20,8 @@ access_keys: label: Delete - id: warranty.set.privacypolicy label: Set Privacy Policy + - id: warranty.list.serial + label: List by Serial - id: batterybrand label: Battery Brand Access acls: diff --git a/config/routes/capi.yaml b/config/routes/capi.yaml index ee3c8668..0c2e5ac1 100644 --- a/config/routes/capi.yaml +++ b/config/routes/capi.yaml @@ -108,6 +108,12 @@ capi_warranty_privacy_policy: controller: App\Controller\CAPI\WarrantyController::setPrivacyPolicy methods: [POST] +# get list of warranties given list of serials +capi_warranty_get_warranties_from_serials: + path: /capi/warranties_list + controller: App\Controller\CAPI\WarrantyController::getWarrantiesBySerialList + methods: [POST] + # customer vehicle api # find customer vehicle by id diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index 83ecf74a..114f3c8c 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -502,6 +502,46 @@ class WarrantyController extends APIController } + public function getWarrantiesBySerialList(Request $req, EntityManagerInterface $em) + { + $this->denyAccessUnlessGranted('warranty.list.serial', null, 'No access.'); + + error_log('getWarrantiesBySerialList'); + // required parameters + $params = [ + 'serial_list', + ]; + + $msg = $this->checkRequiredParameters($req, $params); + error_log('msg - ' . $msg); + if ($msg) + return new APIResponse(false, $msg); + + $serial_list = $req->request->get('serial_list'); + + if (empty($serial_list)) + return new APIResponse(false, 'Empty serial numbers list.'); + + $warranty_list = []; + foreach ($serial_list as $serial) + { + $clean_serial = $this->cleanSerial($serial); + $warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $clean_serial]); + + if ($warr == null) + return new APIResponse(false, 'No warranty found with that serial number.', null, 404); + + $warranty_list[] = $this->generateWarrantyData($warr); + } + + + $data = [ + 'warranties' => $warranty_list, + ]; + + return new APIResponse(true, 'Warranties found.', $data); + } + protected function getCustomerFromMobile($em, $warranty) { $w_mobile = $warranty->getMobileNumber();