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
This commit is contained in:
parent
b7c5bad80b
commit
da4f694c03
5 changed files with 65 additions and 2 deletions
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ use App\Entity\PrivacyPolicy;
|
|||
use DateTime;
|
||||
use Exception;
|
||||
|
||||
|
||||
// mobile API
|
||||
class APIController extends Controller
|
||||
{
|
||||
protected $session;
|
||||
|
|
|
|||
|
|
@ -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.');
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue