Add getPrivacyPolicy to third party API. #263

This commit is contained in:
Korina Cordero 2019-09-06 07:10:54 +00:00
parent 47e098be1c
commit 417bd3c0e1
4 changed files with 60 additions and 0 deletions

View file

@ -115,5 +115,9 @@ class TestAPICommand extends Command
// vehicle
$api->get('/capi/vehicle_manufacturers');
$api->get('/capi/vehicles');
// privacy policy
$privacy_policy_id = 2;
$api->get('/capi/privacy_policy/' . $privacy_policy_id );
}
}

View file

@ -45,3 +45,8 @@ access_keys:
acls:
- id: vehicle.list
label: List
- id: privacypolicy
label: Privacy Policy
acls:
- id: privacypolicy.find
label: Find Privacy Policy

View file

@ -127,3 +127,11 @@ capi_cv_register:
path: /capi/customer_vehicle
controller: App\Controller\CAPI\CustomerVehicle::register
methods: [POST]
# privacy policy
# get privacy policy by id
capi_privacy_policy:
path: /capi/privacy_policy/{id}
controller: App\Controller\CAPI\PrivacyPolicyController::getPrivacyPolicy
methods: [GET]

View file

@ -0,0 +1,43 @@
<?php
namespace App\Controller\CAPI;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\Query;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Catalyst\APIBundle\Controller\APIController;
use Catalyst\APIBundle\Response\APIResponse;
use App\Entity\PrivacyPolicy;
use Catalyst\APIBundle\Access\Generator as ACLGenerator;
// third party API
class PrivacyPolicyController extends APIController
{
protected $acl_gen;
public function __construct(ACLGenerator $acl_gen)
{
$this->acl_gen = $acl_gen;
}
public function getPrivacyPolicy($id, EntityManagerInterface $em)
{
$this->denyAccessUnlessGranted('privacypolicy.find', null, 'No access.');
$privacy_policy = $em->getRepository(PrivacyPolicy::class)->find($id);
if ($privacy_policy == null)
return new APIResponse(false, 'No privacy policy found with that number.', null, 404);
$data = [
'privacy_policy' => (string) $privacy_policy->getContent(),
];
return new APIResponse(true, 'Privacy policy found.', $data);
}
}