From 719cccf778503efb21c4094cbba0ee9a75ea0571 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 2 Apr 2020 03:33:02 +0000 Subject: [PATCH 1/3] 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(); From 135ab10cd38c52d18a27765b6455de2f558b6e42 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 2 Apr 2020 03:58:21 +0000 Subject: [PATCH 2/3] Add to response the list of serials with no warranties. #372 --- catalyst/api-bundle/Command/TestAPICommand.php | 3 ++- src/Controller/CAPI/WarrantyController.php | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/catalyst/api-bundle/Command/TestAPICommand.php b/catalyst/api-bundle/Command/TestAPICommand.php index a8a2be2a..952b98b6 100644 --- a/catalyst/api-bundle/Command/TestAPICommand.php +++ b/catalyst/api-bundle/Command/TestAPICommand.php @@ -142,7 +142,8 @@ class TestAPICommand extends Command // get warranties given list of serial numbers $serial_list = [ 'AJ34LJADR12134LKJM4', - 'AJ34LJADR12134LKJL5', + 'AJ34LJADR12134LKJL5', + 'test', ]; $params = [ diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index 114f3c8c..affdb892 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -523,20 +523,22 @@ class WarrantyController extends APIController return new APIResponse(false, 'Empty serial numbers list.'); $warranty_list = []; + $warr_not_found_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); + $warr_not_found_list[] = 'Warranty not found for ' . $clean_serial; + else + $warranty_list[] = $this->generateWarrantyData($warr); } $data = [ - 'warranties' => $warranty_list, + 'warranties_found' => $warranty_list, + 'warranties_not_found' => $warr_not_found_list, ]; return new APIResponse(true, 'Warranties found.', $data); From 1dac0c506e01fafe3007e31ef992e70142cc8c7d Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 2 Apr 2020 04:01:08 +0000 Subject: [PATCH 3/3] Remove message. #372 --- src/Controller/CAPI/WarrantyController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index affdb892..e5f5437e 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -530,7 +530,7 @@ class WarrantyController extends APIController $warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $clean_serial]); if ($warr == null) - $warr_not_found_list[] = 'Warranty not found for ' . $clean_serial; + $warr_not_found_list[] = $clean_serial; else $warranty_list[] = $this->generateWarrantyData($warr); }