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.'); + + } }