Merge branch '263-capi-command-to-return-privacy-policy-contents' into 'master'

Resolve "CAPI command to return privacy policy contents"

Closes #263

See merge request jankstudio/resq!310
This commit is contained in:
Kendrick Chan 2019-09-06 07:24:38 +00:00
commit d8aa28d751
5 changed files with 62 additions and 1 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);
}
}

View file

@ -205,7 +205,8 @@ class PrivacyPolicyController extends Controller
throw $this->createNotFoundException('The item does not exist');
// set and save values
$row->setName($req->request->get('name'));
$row->setName($req->request->get('name'))
->setContent($req->request->get('content'));
// validate
$errors = $validator->validate($row);