From ca3fbc21c87e1f442279872da26be100eeecf628 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 27 Oct 2021 02:54:34 +0000 Subject: [PATCH] Add route for customer vehicle removal. Add call to get locations. #632 --- config/routes/api.yaml | 6 +++ src/Controller/APIController.php | 34 ++++++++++++++ src/Entity/CustomerMetadata.php | 79 ++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 src/Entity/CustomerMetadata.php diff --git a/config/routes/api.yaml b/config/routes/api.yaml index d4cfda3f..63a05c2f 100644 --- a/config/routes/api.yaml +++ b/config/routes/api.yaml @@ -205,3 +205,9 @@ api_locations: path: /api/locations controller: App\Controller\APIController::getLocations methods: [GET] + +api_cust_vehicle_remove: + path: /api/vehicles/{id}/remove + controller: App\Controller\APIController::removeVehicle + methods: [DELETE] + diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 5e01ac72..7317dc45 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -3648,6 +3648,7 @@ class APIController extends Controller implements LoggedController } else { + // TODO: limit locations to 6. If more than 6, pop the first one out // add location to existing customer meta $c_meta->addMetaInfo($name, $loc_info); } @@ -3655,7 +3656,40 @@ class APIController extends Controller implements LoggedController $em->flush(); return $res->getReturnResponse(); + } + public function getLocations(Request $req) + { + $required_params = []; + $em = $this->getDoctrine()->getManager(); + $res = $this->checkParamsAndKey($req, $em, $required_params); + if ($res->isError()) + return $res->getReturnResponse(); + + // get customer + $cust = $this->session->getCustomer(); + if ($cust == null) + { + $res->setError(true) + ->setErrorMessage('No customer information found'); + return $res->getReturnResponse(); + } + + // get the customer meta for customer + $locations = []; + $cust_meta = $em->getRepository(CustomerMetadata::class)->findOneBy(['customer' => $cust]); + if ($cust_meta != null) + { + $locations[] = $cust_meta->getAllMetaInfo(); + } + + $data = [ + 'locations' => $locations, + ]; + + $res->setData($data); + + return $res->getReturnResponse(); } protected function updateWarranty($res, $em, $rt, $trans, $req, $serial, $inv_filename = null, $wcard_filename = null, diff --git a/src/Entity/CustomerMetadata.php b/src/Entity/CustomerMetadata.php new file mode 100644 index 00000000..c3fe1509 --- /dev/null +++ b/src/Entity/CustomerMetadata.php @@ -0,0 +1,79 @@ +meta_info = []; + } + + public function getID() + { + return $this->id; + } + + public function setCustomer(Customer $customer) + { + $this->customer = $customer; + return $this; + } + + public function getCustomer() + { + return $this->customer; + } + + public function addMetaInfo($id, $value) + { + $this->meta_info[$id] = $value; + return $this; + } + + public function getMetaInfo($id) + { + // return null if we don't have it + if (!isset($this->meta_info[$id])) + return null; + + return $this->meta_info[$id]; + } + + public function getAllMetaInfo() + { + return $this->meta_info; + } +}