From 918f95e4256e83a98e7a95d9a88d059098ec50e6 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 28 Aug 2019 02:15:26 +0000 Subject: [PATCH 1/2] Modify the association between Warranty and PrivacyPolicy to ManyToOne. Add getters and setters for warranty in PrivacyPolicy. #256 --- src/Entity/PrivacyPolicy.php | 22 +++++++++++++++++++--- src/Entity/Warranty.php | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Entity/PrivacyPolicy.php b/src/Entity/PrivacyPolicy.php index b59ee551..c3fbcb55 100644 --- a/src/Entity/PrivacyPolicy.php +++ b/src/Entity/PrivacyPolicy.php @@ -48,6 +48,16 @@ class PrivacyPolicy */ protected $cust_promo; + /** + * @ORM\OneToMany(targetEntity="Warranty", mappedBy="privacy_policy") + */ + protected $warranties; + + public function __construct() + { + $this->warranties = new ArrayCollection(); + } + public function getID() { return $this->id; @@ -108,9 +118,15 @@ class PrivacyPolicy return $this->cust_promo; } + public function addWarranty(Warranty $warranty) + { + $this->warranties[] = $warranty; + return $this; + } - - - + public function getWarrantiess() + { + return $this->warranties; + } } diff --git a/src/Entity/Warranty.php b/src/Entity/Warranty.php index 49fa7f30..37a158c2 100644 --- a/src/Entity/Warranty.php +++ b/src/Entity/Warranty.php @@ -129,7 +129,7 @@ class Warranty // privacy policy /** - * @ORM\OneToOne(targetEntity="PrivacyPolicy") + * @ORM\ManyToOne(targetEntity="PrivacyPolicy", inversedBy="warranties") * @ORM\JoinColumn(name="warranty_privacy_policy", referencedColumnName="id", nullable=true) */ protected $privacy_policy; From da4f694c03fd0d4d9c88a1a0eba534b124a0faf8 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 28 Aug 2019 03:10:19 +0000 Subject: [PATCH 2/2] 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.'); + + } }