Merge branch '581-create-capi-api-call-to-get-dealers' into 'master-fix'
Resolve "Create CAPI API call to get dealers" See merge request jankstudio/resq!697
This commit is contained in:
commit
45c7ccbac1
3 changed files with 63 additions and 0 deletions
|
|
@ -62,3 +62,8 @@ access_keys:
|
||||||
acls:
|
acls:
|
||||||
- id: municipality.list
|
- id: municipality.list
|
||||||
label: List
|
label: List
|
||||||
|
- id: dealer
|
||||||
|
label: Dealer
|
||||||
|
acls:
|
||||||
|
- id: dealer.list
|
||||||
|
label: List
|
||||||
|
|
|
||||||
|
|
@ -172,3 +172,9 @@ capi_municipality_list:
|
||||||
path: /capi/municipality
|
path: /capi/municipality
|
||||||
controller: App\Controller\CAPI\MunicipalityController::getAll
|
controller: App\Controller\CAPI\MunicipalityController::getAll
|
||||||
methods: [GET]
|
methods: [GET]
|
||||||
|
|
||||||
|
# dealer
|
||||||
|
capi_dealer_list:
|
||||||
|
path: /capi/dealers
|
||||||
|
controller: App\Controller\CAPI\DealerController::getAll
|
||||||
|
methods: [GET]
|
||||||
|
|
|
||||||
52
src/Controller/CAPI/DealerController.php
Normal file
52
src/Controller/CAPI/DealerController.php
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
<?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 Catalyst\APIBundle\Controller\APIController;
|
||||||
|
use Catalyst\APIBundle\Response\APIResponse;
|
||||||
|
|
||||||
|
use App\Entity\Dealer;
|
||||||
|
|
||||||
|
use Catalyst\APIBundle\Access\Generator as ACLGenerator;
|
||||||
|
|
||||||
|
class DealerController extends APIController
|
||||||
|
{
|
||||||
|
protected $acl_gen;
|
||||||
|
|
||||||
|
public function __construct(ACLGenerator $acl_gen)
|
||||||
|
{
|
||||||
|
$this->acl_gen = $acl_gen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAll(EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
// get all dealer data order by dealer name
|
||||||
|
$this->denyAccessUnlessGranted('dealer.list', null, 'No access.');
|
||||||
|
|
||||||
|
$results = $em->getRepository(Dealer::class)->findBy([], ['name' => 'ASC']);
|
||||||
|
|
||||||
|
$dealers = [];
|
||||||
|
foreach($results as $res)
|
||||||
|
{
|
||||||
|
$dealer_id = $res->getId();
|
||||||
|
$dealer_name = $res->getName();
|
||||||
|
$dealer_address = $res->getAddress();
|
||||||
|
$dealer_branch_code = $res->getBranchCode();
|
||||||
|
|
||||||
|
$dealers[$dealer_id] = [
|
||||||
|
'name' => $dealer_name,
|
||||||
|
'address' => $dealer_address,
|
||||||
|
'branch_code' => $dealer_branch_code,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'dealers' => $dealers,
|
||||||
|
];
|
||||||
|
return new APIResponse(true, 'Dealers loaded.', $data);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue