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