From e634f2ee32c14e0123c4f4338fb24d9dae56eb30 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 15 Aug 2019 08:25:34 +0000 Subject: [PATCH 1/3] Add method to cancel warranty in WarrantyController. Add route and acl for cancel warranty. Add test command to test cancel warranty. #250 --- .../api-bundle/Command/TestAPICommand.php | 4 ++++ config/api_acl.yaml | 2 ++ config/routes/capi.yaml | 6 ++++++ src/Controller/CAPI/WarrantyController.php | 21 +++++++++++++++++++ 4 files changed, 33 insertions(+) diff --git a/catalyst/api-bundle/Command/TestAPICommand.php b/catalyst/api-bundle/Command/TestAPICommand.php index b7c12755..8d6680f2 100644 --- a/catalyst/api-bundle/Command/TestAPICommand.php +++ b/catalyst/api-bundle/Command/TestAPICommand.php @@ -73,6 +73,10 @@ class TestAPICommand extends Command ]; $api->post('/capi/warranties/' . $id . '/claim', $params); + // warranty cancel + $id = 86811; + $api->get('/capi/warranties/' . $id . '/cancel'); + // plate warranty $api->get('/capi/plates/' . $plate_num . '/warranties'); diff --git a/config/api_acl.yaml b/config/api_acl.yaml index 771d3d09..d1138fbc 100644 --- a/config/api_acl.yaml +++ b/config/api_acl.yaml @@ -12,6 +12,8 @@ access_keys: label: Register Battery - id: warranty.claim label: Claim + - id: warranty.cancel + label: Cancel - id: batterybrand label: Battery Brand Access acls: diff --git a/config/routes/capi.yaml b/config/routes/capi.yaml index a340041c..a8452122 100644 --- a/config/routes/capi.yaml +++ b/config/routes/capi.yaml @@ -84,6 +84,12 @@ capi_warranty_get_all: controller: App\Controller\CAPI\WarrantyController::getAll methods: [GET] +# cancel warranty +capi_warranty_cancel: + path: /capi/warranties/{id}/cancel + controller: App\Controller\CAPI\WarrantyController::cancel + methods: [GET] + # customer vehicle api diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index 081201ea..be80b25c 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -310,4 +310,25 @@ class WarrantyController extends APIController return new APIResponse(true, 'Warranties loaded.', $data); } + + public function cancel(Request $req, EntityManagerInterface $em, $id) + { + $this->denyAccessUnlessGranted('warranty.cancel', null, 'No access.'); + + // find warranty + $warr = $em->getRepository(Warranty::class)->find($id); + if ($warr == null) + { + return new APIResponse(false, 'No warranty found with that id.', null, 404); + } + + // set status to cancelled + $warr->setStatus(WarrantyStatus::CANCELLED); + + $em->persist($warr); + $em->flush(); + + return new APIResponse(true, 'Warranty cancelled successfully.'); + + } } From 2f8eab22368312c1a4f71f5967cc5ff47557909b Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 16 Aug 2019 01:53:24 +0000 Subject: [PATCH 2/3] Add checking for null on date_expire for warranty. #250 --- src/Controller/CAPI/WarrantyController.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index be80b25c..e5e367aa 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -60,7 +60,6 @@ class WarrantyController extends APIController 'status' => (string) $warr->getStatus(), 'date_create' => (string) $warr->getDateCreate()->format('YmdHis'), 'date_purchase' => (string) $warr->getDatePurchase()->format('Ymd'), - 'date_expire' => (string) $warr->getDateExpire()->format('Ymd'), 'flag_activated' => (boolean) $warr->isActivated(), ]; @@ -70,6 +69,12 @@ class WarrantyController extends APIController else $data['date_claim'] = (string) $warr->getDateClaim()->format('Ymd'); + $date_expire = $warr->getDateExpire(); + if ($date_expire == null) + $data['date_expire'] = null; + else + $data['date_expire'] = (string) $warr->getDateExpire()->format('Ymd'); + return $data; } @@ -322,6 +327,11 @@ class WarrantyController extends APIController return new APIResponse(false, 'No warranty found with that id.', null, 404); } + if ($warr->getStatus() == WarrantyStatus::CANCELLED) + { + return new APIResponse(false, 'Warranty already cancelled.'); + } + // set status to cancelled $warr->setStatus(WarrantyStatus::CANCELLED); From cf89311e1737d48a443d961ac6e1bcf88fc6d860 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 16 Aug 2019 03:01:25 +0000 Subject: [PATCH 3/3] Add delete method to WarrantyController. #250 --- .../api-bundle/Command/TestAPICommand.php | 4 ++++ config/api_acl.yaml | 2 ++ config/routes/capi.yaml | 6 ++++++ src/Controller/CAPI/WarrantyController.php | 19 ++++++++++++++++++- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/catalyst/api-bundle/Command/TestAPICommand.php b/catalyst/api-bundle/Command/TestAPICommand.php index 8d6680f2..b70f3bdd 100644 --- a/catalyst/api-bundle/Command/TestAPICommand.php +++ b/catalyst/api-bundle/Command/TestAPICommand.php @@ -80,6 +80,10 @@ class TestAPICommand extends Command // plate warranty $api->get('/capi/plates/' . $plate_num . '/warranties'); + // warranty delete + $id = 86811; + $api->post('/capi/warranties/' . $id . '/delete'); + // battery $api->get('/capi/battery_brands'); $api->get('/capi/battery_sizes'); diff --git a/config/api_acl.yaml b/config/api_acl.yaml index d1138fbc..e7c24b9f 100644 --- a/config/api_acl.yaml +++ b/config/api_acl.yaml @@ -14,6 +14,8 @@ access_keys: label: Claim - id: warranty.cancel label: Cancel + - id: warranty.delete + label: Delete - id: batterybrand label: Battery Brand Access acls: diff --git a/config/routes/capi.yaml b/config/routes/capi.yaml index a8452122..c6dcb72d 100644 --- a/config/routes/capi.yaml +++ b/config/routes/capi.yaml @@ -90,6 +90,12 @@ capi_warranty_cancel: controller: App\Controller\CAPI\WarrantyController::cancel methods: [GET] +# delete warranty +capi_warranty_delete: + path: /capi/warranties/{id}/delete + controller: App\Controller\CAPI\WarrantyController::delete + methods: [POST] + # customer vehicle api diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index e5e367aa..9b4a5094 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -339,6 +339,23 @@ class WarrantyController extends APIController $em->flush(); return new APIResponse(true, 'Warranty cancelled successfully.'); - + } + + public function delete(EntityManagerInterface $em, $id) + { + $this->denyAccessUnlessGranted('warranty.delete', null, 'No access.'); + + // find warranty + $warr = $em->getRepository(Warranty::class)->find($id); + if ($warr == null) + { + return new APIResponse(false, 'No warranty found with that id.', null, 404); + } + + // delete the warranty + $em->remove($warr); + $em->flush(); + + return new APIResponse(true, 'Warranty deleted successfully.'); } }