From da4f694c03fd0d4d9c88a1a0eba534b124a0faf8 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 28 Aug 2019 03:10:19 +0000 Subject: [PATCH] Add setPrivacyPolicy to WarrantyController for third party API. Add route to third party api yaml. Add comment to APIController and WarrantyController indicating whether third party API or mobile API. Modify checking for required parameters, instead of using empty() to use isset()). #256 --- .../api-bundle/Command/TestAPICommand.php | 8 ++++ .../api-bundle/Controller/APIController.php | 3 +- config/routes/capi.yaml | 6 +++ src/Controller/APIController.php | 2 +- src/Controller/CAPI/WarrantyController.php | 48 +++++++++++++++++++ 5 files changed, 65 insertions(+), 2 deletions(-) diff --git a/catalyst/api-bundle/Command/TestAPICommand.php b/catalyst/api-bundle/Command/TestAPICommand.php index ee0b8992..f76a8285 100644 --- a/catalyst/api-bundle/Command/TestAPICommand.php +++ b/catalyst/api-bundle/Command/TestAPICommand.php @@ -80,6 +80,14 @@ class TestAPICommand extends Command ]; $api->post('/capi/warranties/'. $id, $params); + // warranty set privacy policy + $id = 86811; + $policy_id = 2; + $params = [ + 'privacy_policy_id' => $policy_id, + ]; + $api->post('/capi/warranties/' . $id .'/privacypolicy', $params); + // warranty claim $id = 86811; $serial = 'AJ34LJADR12134LKJL5'; diff --git a/catalyst/api-bundle/Controller/APIController.php b/catalyst/api-bundle/Controller/APIController.php index 7f359680..74c63d3c 100644 --- a/catalyst/api-bundle/Controller/APIController.php +++ b/catalyst/api-bundle/Controller/APIController.php @@ -24,7 +24,8 @@ abstract class APIController extends Controller else { $check = $req->request->get($param); - if (empty($check)) + //if (empty($check)) + if (!isset($check)) $missing[] = $param; } } diff --git a/config/routes/capi.yaml b/config/routes/capi.yaml index d99fb182..67509914 100644 --- a/config/routes/capi.yaml +++ b/config/routes/capi.yaml @@ -102,6 +102,12 @@ capi_warranty_delete: controller: App\Controller\CAPI\WarrantyController::delete methods: [POST] +# set privacy policy of warranty +capi_warranty_privacy_policy: + path: /capi/warranties/{id}/privacypolicy + controller: App\Controller\CAPI\WarrantyController::setPrivacyPolicy + methods: [POST] + # customer vehicle api # find customer vehicle by id diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index fcd49749..075879bb 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -49,7 +49,7 @@ use App\Entity\PrivacyPolicy; use DateTime; use Exception; - +// mobile API class APIController extends Controller { protected $session; diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index 710ea886..d76afffc 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -16,6 +16,7 @@ use App\Entity\BatterySize; use App\Entity\SAPBattery; use App\Entity\SAPBatterySize; use App\Entity\SAPBatteryBrand; +use App\Entity\PrivacyPolicy; use App\Ramcar\NameValue; use App\Ramcar\WarrantyClass; @@ -24,6 +25,7 @@ use DateTime; use Catalyst\APIBundle\Access\Generator as ACLGenerator; +// third party API class WarrantyController extends APIController { protected $acl_gen; @@ -445,4 +447,50 @@ class WarrantyController extends APIController return new APIResponse(true, 'Warranty deleted successfully.'); } + + public function setPrivacyPolicy(Request $req, EntityManagerInterface $em, $id) + { + $this->denyAccessUnlessGranted('warranty.set.privacypolicy', 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); + } + + $params = [ + 'privacy_policy_id', + ]; + + $msg = $this->checkRequiredParameters($req, $params); + error_log('msg - ' . $msg); + if ($msg) + return new APIResponse(false, $msg); + + $privacy_policy_id = $req->request->get('privacy_policy_id'); + + if ($privacy_policy_id == 0) + { + $warr->setPrivacyPolicy(null); + } + else + { + // find privacy policy + $privacy_policy = $em->getRepository(PrivacyPolicy::class)->find($privacy_policy_id); + if ($privacy_policy == null) + { + return new APIResponse(false, 'No privacy policy found with that id.', null, 404); + } + + // set privacy policy of warranty + $warr->setPrivacyPolicy($privacy_policy); + } + + $em->persist($warr); + $em->flush(); + + return new APIResponse(true, 'Privacy policy for warranty set successfully.'); + + } }