From e3e949d42abf0e453a270b7b2dfe86098661b608 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 11 Jun 2021 05:54:33 +0000 Subject: [PATCH] Add CAPI call to get dealers. #581 --- config/api_acl.yaml | 5 +++ config/routes/capi.yaml | 6 +++ src/Controller/CAPI/DealerController.php | 52 ++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 src/Controller/CAPI/DealerController.php diff --git a/config/api_acl.yaml b/config/api_acl.yaml index ab15187a..2e5bbdd3 100644 --- a/config/api_acl.yaml +++ b/config/api_acl.yaml @@ -62,3 +62,8 @@ access_keys: acls: - id: municipality.list label: List + - id: dealer + label: Dealer + acls: + - id: dealer.list + label: List diff --git a/config/routes/capi.yaml b/config/routes/capi.yaml index 5db14285..40e7b975 100644 --- a/config/routes/capi.yaml +++ b/config/routes/capi.yaml @@ -172,3 +172,9 @@ capi_municipality_list: path: /capi/municipality controller: App\Controller\CAPI\MunicipalityController::getAll methods: [GET] + +# dealer +capi_dealer_list: + path: /capi/dealers + controller: App\Controller\CAPI\DealerController::getAll + methods: [GET] diff --git a/src/Controller/CAPI/DealerController.php b/src/Controller/CAPI/DealerController.php new file mode 100644 index 00000000..f4f86d98 --- /dev/null +++ b/src/Controller/CAPI/DealerController.php @@ -0,0 +1,52 @@ +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); + } +}