Add setPrivacyPolicy method to APIController. Add route and acl for setting of privacy policy for warranty. Allow null to be set for setPrivacyPolicy in Warranty entity. Modify the checking for missing parameters, from empty to isset. #256

This commit is contained in:
Korina Cordero 2019-08-27 07:49:10 +00:00
parent 6398c58b32
commit 9efc347a7f
4 changed files with 61 additions and 2 deletions

View file

@ -18,6 +18,8 @@ access_keys:
label: Cancel label: Cancel
- id: warranty.delete - id: warranty.delete
label: Delete label: Delete
- id: warranty.set.privacypolicy
label: Set Privacy Policy
- id: batterybrand - id: batterybrand
label: Battery Brand Access label: Battery Brand Access
acls: acls:

View file

@ -149,3 +149,8 @@ api_partner_review:
path: /api/partners/{pid}/review path: /api/partners/{pid}/review
controller: App\Controller\APIController:reviewPartner controller: App\Controller\APIController:reviewPartner
methods: [POST] methods: [POST]
api_warranty_privacy_policy:
path: /api/warranty/{wid}/privacy_policy
controller: App\Controller\APIController::setPrivacyPolicy
methods: [POST]

View file

@ -81,7 +81,8 @@ class APIController extends Controller
else if ($req->getMethod() == 'POST') else if ($req->getMethod() == 'POST')
{ {
$check = $req->request->get($param); $check = $req->request->get($param);
if (empty($check)) //if (empty($check))
if (!isset($check))
$missing[] = $param; $missing[] = $param;
} }
else else
@ -2182,4 +2183,55 @@ class APIController extends Controller
return $res->getReturnResponse(); return $res->getReturnResponse();
} }
public function setPrivacyPolicy($wid, Request $req, EntityManagerInterface $em)
{
$required_params = [
'privacy_policy_id',
];
error_log($req->request->get('privacy_policy_id'));
$res = $this->checkParamsAndKey($req, $em, $required_params);
if ($res->isError())
return $res->getReturnResponse();
$policy_id = $req->request->get('privacy_policy_id');
// check if warranty exists
$warranty = $em->getRepository(Warranty::class)->find($wid);
if ($warranty == null)
{
$res->setError(true)
->setErrorMessage('No warranty found.');
return $res->getReturnResponse();
}
if ($policy_id == 0)
{
$warranty->setPrivacyPolicy(null);
}
else
{
// find the privacy policy
$privacy_policy = $em->getRepository(PrivacyPolicy::class)->find($policy_id);
if ($privacy_policy == null)
{
$res->setError(true)
->setErrorMessage('No privacy policy found.');
return $res->getReturnResponse();
}
$warranty->setPrivacyPolicy($privacy_policy);
}
// save to db
$em->persist($warranty);
$em->flush();
$data = [];
$res->setData($data);
return $res->getReturnResponse();
}
} }

View file

@ -382,7 +382,7 @@ class Warranty
return true; return true;
} }
public function setPrivacyPolicy(PrivacyPolicy $privacy_policy) public function setPrivacyPolicy($privacy_policy)
{ {
$this->privacy_policy = $privacy_policy; $this->privacy_policy = $privacy_policy;
return $this; return $this;