From fac78e558decc5ba70c14b1ebfd63192eb634a6b Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Tue, 6 Nov 2018 01:55:51 +0800 Subject: [PATCH] Add plate number warranty API call #166 --- catalyst/api-bundle/Command/TestCommand.php | 6 +++++- config/routes/warranty_api.yaml | 8 ++++++++ src/Controller/CAPI/WarrantyController.php | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/catalyst/api-bundle/Command/TestCommand.php b/catalyst/api-bundle/Command/TestCommand.php index 01a61e26..179b55b0 100644 --- a/catalyst/api-bundle/Command/TestCommand.php +++ b/catalyst/api-bundle/Command/TestCommand.php @@ -42,9 +42,10 @@ class TestCommand extends Command // TODO: shift this out of the bundle, since it's project specific // warranty register $serial = 'AJ34LJADR12134LKJL'; + $plate_num = 'XEN918'; $params = [ 'serial' => $serial, - 'plate_number' => 'XEN918', + 'plate_number' => $plate_num, 'warranty_class' => 'private', 'battery_model_id' => 438, 'battery_size_id' => 1171, @@ -59,6 +60,9 @@ class TestCommand extends Command // warranty claim $api->post('/capi/warranties/' . $serial . '/claim'); + // plate warranty + $api->get('/capi/plates/' . $plate_num . '/warranties'); + // battery // $api->get('/capi/battery_models'); // $api->get('/capi/battery_sizes'); diff --git a/config/routes/warranty_api.yaml b/config/routes/warranty_api.yaml index 4b58b34c..7b46b960 100644 --- a/config/routes/warranty_api.yaml +++ b/config/routes/warranty_api.yaml @@ -32,6 +32,14 @@ capi_vehicle_list: methods: [GET] +# plate api + +capi_plate_warranty: + path: /capi/plates/{plate_number}/warranties + controller: App\Controller\CAPI\WarrantyController::getPlateWarranties + methods: [GET] + + # warranty api # check warranty by serial diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index c77b29e4..969aec50 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -178,4 +178,22 @@ class WarrantyController extends APIController return new APIResponse(true, 'Warranty claimed successfully.'); } + + public function getPlateWarranties($plate_number, EntityManagerInterface $em) + { + $warranties = $em->getRepository(Warranty::class) + ->findBy(['plate_number' => $plate_number], ['date_purchase' => 'DESC']); + + $warr_data = []; + foreach ($warranties as $warr) + { + $warr_data[] = $this->generateWarrantyData($warr); + } + + $data = [ + 'warranties' => $warr_data, + ]; + + return new APIResponse(true, 'Warranties loaded.', $data); + } }