From baf7b51f14679e5661830651cc5f237cd754654a Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 1 Jul 2019 07:46:54 +0000 Subject: [PATCH 01/15] Add flag_activated to the Warranty entity. Add Status field to Warranty results of search. #227 --- src/Entity/Warranty.php | 18 ++++++++++++++++++ templates/search/form.html.twig | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Entity/Warranty.php b/src/Entity/Warranty.php index c1e16d32..a0e71a99 100644 --- a/src/Entity/Warranty.php +++ b/src/Entity/Warranty.php @@ -121,12 +121,19 @@ class Warranty */ protected $claim_from; + // warranty activated + /** + * @ORM\Column(type="boolean") + */ + protected $flag_activated; + public function __construct() { $this->date_create = new DateTime(); $this->warranty_class = WarrantyClass::WTY_PRIVATE; $this->status = WarrantyStatus::ACTIVE; $this->date_claim = null; + $this->flag_activated = false; } public function getID() @@ -348,4 +355,15 @@ class Warranty { return $this->claim_from; } + + public function setActivated($flag_activated = true) + { + $this->flag_activated = $flag_activated; + return this; + } + + public function isActivated() + { + return $this->flag_activated; + } } diff --git a/templates/search/form.html.twig b/templates/search/form.html.twig index 892ca1ed..e1231721 100644 --- a/templates/search/form.html.twig +++ b/templates/search/form.html.twig @@ -197,6 +197,7 @@ Expiry Date Serial Battery + Status @@ -210,6 +211,13 @@ {{ result.getDateExpire|default("")|date('d M Y') }} {{ result.getSerial|default("") }} {{ result.getSAPBattery.getID|default("") }} + + {% if result.isActivated == true %} + Activated + {% else %} + Not Activated + {% endif %} + {% endfor %} From 6893211ff0d6a862c16faaece5d5edb6d72c7b8c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 1 Jul 2019 07:54:28 +0000 Subject: [PATCH 02/15] Add status to warranty for Customer Battery Search. #227 --- templates/warranty-search/form.html.twig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/templates/warranty-search/form.html.twig b/templates/warranty-search/form.html.twig index 371ee1ea..e643d3a4 100644 --- a/templates/warranty-search/form.html.twig +++ b/templates/warranty-search/form.html.twig @@ -125,6 +125,16 @@ End of Warranty {{ result.getDateExpire|date("d M Y") }} + + Status + + {% if result.isActivated == true %} + Activated + {% else %} + Not Activated + {% endif %} + + {% endfor %} From 60cab330b3ce6f079ba38ca0a81608d8ea2ec465 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 1 Jul 2019 08:26:58 +0000 Subject: [PATCH 03/15] Add flag_activated field for warranties in resq API responses. #227 --- src/Controller/CAPI/WarrantyController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index 1c56a837..081201ea 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -61,6 +61,7 @@ class WarrantyController extends APIController 'date_create' => (string) $warr->getDateCreate()->format('YmdHis'), 'date_purchase' => (string) $warr->getDatePurchase()->format('Ymd'), 'date_expire' => (string) $warr->getDateExpire()->format('Ymd'), + 'flag_activated' => (boolean) $warr->isActivated(), ]; $date_claim = $warr->getDateClaim(); From 1573ec0aa436c92a3a6099cf6679f32696837a59 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 2 Jul 2019 07:17:38 +0000 Subject: [PATCH 04/15] Return warranty information with customer vehicle information. #227 --- src/Controller/APIController.php | 59 ++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 7a39d50b..9642bb3b 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -38,6 +38,7 @@ use App\Entity\Promo; use App\Entity\Battery; use App\Entity\RiderRating; use App\Entity\JOEvent; +use App\Entity\Warranty; use DateTime; use Exception; @@ -673,6 +674,56 @@ class APIController extends Controller if ($cv->getWarrantyExpiration() != null) $wty_ex = $cv->getWarrantyExpiration()->format('Y-m-d'); + // NOTE: Modify the search for the latest warranty + // get latest warranty using plate number + $warranty_results = $em->getRepository(Warranty::class)->findBy(['plate_number' => $cv->getPlateNumber()], + ['date_create' => 'desc']); + + $warranty = current($warranty_results); + + // check for null values for battery and date claim and date expire + $batt_model = ''; + $batt_size = ''; + $sap_batt = ''; + $claim_date = ''; + $expiry_date = ''; + + if (!(is_null($warranty->getBatteryModel()))) { + $batt_model = $warranty->getBatteryModel()->getName(); + } + if (!(is_null($warranty->getBatterySize()))) { + $batt_size = $warranty->getBattyerSize()->getName(); + } + if (!(is_null($warranty->getSAPBattery()))) { + $sap_batt = $warranty->getSAPBattery()->getID(); + } + if (!(is_null($warranty->getDateClaim()))) { + $claim_date = $warranty->getDateClaim()->format("d M Y g:i A"); + } + if (!(is_null($warranty->getDateExpire()))) { + $expiry_date = $warranty->getDateExpire()->format("d M Y g:i A"); + } + + $warr[] = [ + 'id' => $warranty->getID(), + 'serial' => $warranty->getSerial(), + 'warranty_class' => $warranty->getWarrantyClass(), + 'plate_number' => $warranty->getPlateNumber(), + 'first_name' => $warranty->getFirstName(), + 'last_name' => $warranty->getLastName(), + 'mobile_number' => $warranty->getMobileNumber(), + 'battery_model' => $batt_model, + 'battery_size' => $batt_size, + 'sap_battery' => $sap_batt, + 'status' => $warranty->getStatus(), + 'date_create' => $warranty->getDateCreate()->format("d M Y g:i A"), + 'date_purchase' => $warranty->getDatePurchase()->format("d M Y g:i A"), + 'date_expire' => $expiry_date, + 'date_claim' => $claim_date, + 'claim_from' => $warranty->getClaimedFrom(), + 'is_activated' => $warranty->isActivated() ? 1 : 0, + ]; + $cv_list[] = [ 'cv_id' => $cv->getID(), 'mfg_id' => $cv->getVehicle()->getManufacturer()->getID(), @@ -688,6 +739,7 @@ class APIController extends Controller 'curr_batt_id' => $battery_id, 'is_motolite' => $cv->hasMotoliteBattery() ? 1 : 0, 'is_active' => $cv->isActive() ? 1 : 0, + 'warranty' => $warr, ]; } @@ -735,6 +787,7 @@ class APIController extends Controller $batts = $vehicle->getBatteries(); foreach ($batts as $batt) { + // TODO: Add warranty_tnv to battery information $batt_list[] = [ 'id' => $batt->getID(), 'mfg_id' => $batt->getManufacturer()->getID(), @@ -1645,6 +1698,9 @@ class APIController extends Controller 'plate_number' => $cv->getPlateNumber(), ]; + // TODO: mogol get warranty object for the plate number. Return only + // latest warranty. + // rider $rider = $jo->getRider(); if ($rider != null) @@ -1802,4 +1858,7 @@ class APIController extends Controller return $res->getReturnResponse(); } + + // TODO mogol add public function activateWarranty that takes in + // a plate number. Search for the latest warranty with the plate number } From 48b509ad431c63f663fe07bb5fd5a72431893cdc Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 2 Jul 2019 07:42:22 +0000 Subject: [PATCH 05/15] Return warranty information with customer vehicle information for job order history. #227 --- src/Controller/APIController.php | 58 +++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 9642bb3b..81f87f05 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -1691,16 +1691,66 @@ class APIController extends Controller 'status' => $status, ]; - // customer vehicle + // customer vehicle and warranty $cv = $jo->getCustomerVehicle(); + + // NOTE: Modify the search for the latest warranty + // get latest warranty using plate number + $warranty_results = $em->getRepository(Warranty::class)->findBy(['plate_number' => $cv->getPlateNumber()], + ['date_create' => 'desc']); + + $warranty = current($warranty_results); + + // check for null values for battery and date claim and date expire + $batt_model = ''; + $batt_size = ''; + $sap_batt = ''; + $claim_date = ''; + $expiry_date = ''; + + if (!(is_null($warranty->getBatteryModel()))) { + $batt_model = $warranty->getBatteryModel()->getName(); + } + if (!(is_null($warranty->getBatterySize()))) { + $batt_size = $warranty->getBattyerSize()->getName(); + } + if (!(is_null($warranty->getSAPBattery()))) { + $sap_batt = $warranty->getSAPBattery()->getID(); + } + if (!(is_null($warranty->getDateClaim()))) { + $claim_date = $warranty->getDateClaim()->format("d M Y g:i A"); + } + if (!(is_null($warranty->getDateExpire()))) { + $expiry_date = $warranty->getDateExpire()->format("d M Y g:i A"); + } + + $warr = []; + $warr[] = [ + 'id' => $warranty->getID(), + 'serial' => $warranty->getSerial(), + 'warranty_class' => $warranty->getWarrantyClass(), + 'plate_number' => $warranty->getPlateNumber(), + 'first_name' => $warranty->getFirstName(), + 'last_name' => $warranty->getLastName(), + 'mobile_number' => $warranty->getMobileNumber(), + 'battery_model' => $batt_model, + 'battery_size' => $batt_size, + 'sap_battery' => $sap_batt, + 'status' => $warranty->getStatus(), + 'date_create' => $warranty->getDateCreate()->format("d M Y g:i A"), + 'date_purchase' => $warranty->getDatePurchase()->format("d M Y g:i A"), + 'date_expire' => $expiry_date, + 'date_claim' => $claim_date, + 'claim_from' => $warranty->getClaimedFrom(), + 'is_activated' => $warranty->isActivated() ? 1 : 0, + ]; + $jo_data['customer_vehicle'] = [ 'id' => $cv->getID(), 'plate_number' => $cv->getPlateNumber(), + 'warranty' => $warr, ]; - // TODO: mogol get warranty object for the plate number. Return only - // latest warranty. - // rider $rider = $jo->getRider(); if ($rider != null) From 13b955d0b6f472b0b0fdb99c05a4282a5232aa17 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 2 Jul 2019 09:15:06 +0000 Subject: [PATCH 06/15] Add route to activate warranty. Move the code to search for warranty to a separate function. Fix bug in Warranty entity when setting flag_activated. #227 --- config/routes/api.yaml | 5 + src/Controller/APIController.php | 209 ++++++++++++++++--------------- src/Entity/Warranty.php | 2 +- 3 files changed, 113 insertions(+), 103 deletions(-) diff --git a/config/routes/api.yaml b/config/routes/api.yaml index 50e50957..2d3a11bc 100644 --- a/config/routes/api.yaml +++ b/config/routes/api.yaml @@ -124,3 +124,8 @@ api_location_support: path: /api/location_support controller: App\Controller\APIController:locationSupport methods: [GET] + +api_activate_warranty: + path: /api/activate_warranty + controller: App\Controller\APIController:activateWarranty + methods: [POST] diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 81f87f05..5134a884 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -674,55 +674,7 @@ class APIController extends Controller if ($cv->getWarrantyExpiration() != null) $wty_ex = $cv->getWarrantyExpiration()->format('Y-m-d'); - // NOTE: Modify the search for the latest warranty - // get latest warranty using plate number - $warranty_results = $em->getRepository(Warranty::class)->findBy(['plate_number' => $cv->getPlateNumber()], - ['date_create' => 'desc']); - - $warranty = current($warranty_results); - - // check for null values for battery and date claim and date expire - $batt_model = ''; - $batt_size = ''; - $sap_batt = ''; - $claim_date = ''; - $expiry_date = ''; - - if (!(is_null($warranty->getBatteryModel()))) { - $batt_model = $warranty->getBatteryModel()->getName(); - } - if (!(is_null($warranty->getBatterySize()))) { - $batt_size = $warranty->getBattyerSize()->getName(); - } - if (!(is_null($warranty->getSAPBattery()))) { - $sap_batt = $warranty->getSAPBattery()->getID(); - } - if (!(is_null($warranty->getDateClaim()))) { - $claim_date = $warranty->getDateClaim()->format("d M Y g:i A"); - } - if (!(is_null($warranty->getDateExpire()))) { - $expiry_date = $warranty->getDateExpire()->format("d M Y g:i A"); - } - - $warr[] = [ - 'id' => $warranty->getID(), - 'serial' => $warranty->getSerial(), - 'warranty_class' => $warranty->getWarrantyClass(), - 'plate_number' => $warranty->getPlateNumber(), - 'first_name' => $warranty->getFirstName(), - 'last_name' => $warranty->getLastName(), - 'mobile_number' => $warranty->getMobileNumber(), - 'battery_model' => $batt_model, - 'battery_size' => $batt_size, - 'sap_battery' => $sap_batt, - 'status' => $warranty->getStatus(), - 'date_create' => $warranty->getDateCreate()->format("d M Y g:i A"), - 'date_purchase' => $warranty->getDatePurchase()->format("d M Y g:i A"), - 'date_expire' => $expiry_date, - 'date_claim' => $claim_date, - 'claim_from' => $warranty->getClaimedFrom(), - 'is_activated' => $warranty->isActivated() ? 1 : 0, - ]; + $warranty = $this->findWarranty($cv->getPlateNumber()); $cv_list[] = [ 'cv_id' => $cv->getID(), @@ -739,7 +691,7 @@ class APIController extends Controller 'curr_batt_id' => $battery_id, 'is_motolite' => $cv->hasMotoliteBattery() ? 1 : 0, 'is_active' => $cv->isActive() ? 1 : 0, - 'warranty' => $warr, + 'warranty' => $warranty, ]; } @@ -1694,61 +1646,13 @@ class APIController extends Controller // customer vehicle and warranty $cv = $jo->getCustomerVehicle(); - // NOTE: Modify the search for the latest warranty // get latest warranty using plate number - $warranty_results = $em->getRepository(Warranty::class)->findBy(['plate_number' => $cv->getPlateNumber()], - ['date_create' => 'desc']); - - $warranty = current($warranty_results); - - // check for null values for battery and date claim and date expire - $batt_model = ''; - $batt_size = ''; - $sap_batt = ''; - $claim_date = ''; - $expiry_date = ''; - - if (!(is_null($warranty->getBatteryModel()))) { - $batt_model = $warranty->getBatteryModel()->getName(); - } - if (!(is_null($warranty->getBatterySize()))) { - $batt_size = $warranty->getBattyerSize()->getName(); - } - if (!(is_null($warranty->getSAPBattery()))) { - $sap_batt = $warranty->getSAPBattery()->getID(); - } - if (!(is_null($warranty->getDateClaim()))) { - $claim_date = $warranty->getDateClaim()->format("d M Y g:i A"); - } - if (!(is_null($warranty->getDateExpire()))) { - $expiry_date = $warranty->getDateExpire()->format("d M Y g:i A"); - } - - $warr = []; - $warr[] = [ - 'id' => $warranty->getID(), - 'serial' => $warranty->getSerial(), - 'warranty_class' => $warranty->getWarrantyClass(), - 'plate_number' => $warranty->getPlateNumber(), - 'first_name' => $warranty->getFirstName(), - 'last_name' => $warranty->getLastName(), - 'mobile_number' => $warranty->getMobileNumber(), - 'battery_model' => $batt_model, - 'battery_size' => $batt_size, - 'sap_battery' => $sap_batt, - 'status' => $warranty->getStatus(), - 'date_create' => $warranty->getDateCreate()->format("d M Y g:i A"), - 'date_purchase' => $warranty->getDatePurchase()->format("d M Y g:i A"), - 'date_expire' => $expiry_date, - 'date_claim' => $claim_date, - 'claim_from' => $warranty->getClaimedFrom(), - 'is_activated' => $warranty->isActivated() ? 1 : 0, - ]; + $warranty = $this->findWarranty($cv->getPlateNumber()); $jo_data['customer_vehicle'] = [ 'id' => $cv->getID(), 'plate_number' => $cv->getPlateNumber(), - 'warranty' => $warr, + 'warranty' => $warranty, ]; // rider @@ -1909,6 +1813,107 @@ class APIController extends Controller return $res->getReturnResponse(); } - // TODO mogol add public function activateWarranty that takes in - // a plate number. Search for the latest warranty with the plate number + public function activateWarranty(Request $req) + { + $required_params = ['plate_number']; + $em = $this->getDoctrine()->getManager(); + $res = $this->checkParamsAndKey($req, $em, $required_params); + if ($res->isError()) + return $res->getReturnResponse(); + + $plate_number = $req->request->get('plate_number'); + + // find warranty using plate number + $warranty_results = $em->getRepository(Warranty::class)->findBy(['plate_number' => $plate_number], + ['date_create' => 'desc']); + + // check if warranty_results is empty + if (empty($warranty_results)) + { + $res->setError(true) + ->setErrorMessage('No warranty found for plate number'); + return $res->getReturnResponse(); + } + + // get first entry + $warranty = current($warranty_results); + if ($warranty->isActivated()) + { + $res->setError(true) + ->setErrorMessage('Warranty already activated'); + return $res->getReturnResponse(); + } + + $warranty->setActivated(); + + $em->flush(); + + return $res->getReturnResponse(); + } + + protected function findWarranty($plate_number) + { + $em = $this->getDoctrine()->getManager(); + // NOTE: Modify the search for the latest warranty. This seems hacky. + // get latest warranty using plate number + $warranty_results = $em->getRepository(Warranty::class)->findBy(['plate_number' => $plate_number], + ['date_create' => 'desc']); + + // check if warranty_results is empty + if (empty($warranty_results)) + { + $res->setError(true) + ->setErrorMessage('No warranty found for plate number'); + return $res->getReturnResponse(); + } + + // get first entry + $warranty = current($warranty_results); + + // check for null values for battery and date claim and date expire + $batt_model = ''; + $batt_size = ''; + $sap_batt = ''; + $claim_date = ''; + $expiry_date = ''; + + if (!(is_null($warranty->getBatteryModel()))) { + $batt_model = $warranty->getBatteryModel()->getName(); + } + if (!(is_null($warranty->getBatterySize()))) { + $batt_size = $warranty->getBattyerSize()->getName(); + } + if (!(is_null($warranty->getSAPBattery()))) { + $sap_batt = $warranty->getSAPBattery()->getID(); + } + if (!(is_null($warranty->getDateClaim()))) { + $claim_date = $warranty->getDateClaim()->format("d M Y g:i A"); + } + if (!(is_null($warranty->getDateExpire()))) { + $expiry_date = $warranty->getDateExpire()->format("d M Y g:i A"); + } + + $warr = []; + $warr[] = [ + 'id' => $warranty->getID(), + 'serial' => $warranty->getSerial(), + 'warranty_class' => $warranty->getWarrantyClass(), + 'plate_number' => $warranty->getPlateNumber(), + 'first_name' => $warranty->getFirstName(), + 'last_name' => $warranty->getLastName(), + 'mobile_number' => $warranty->getMobileNumber(), + 'battery_model' => $batt_model, + 'battery_size' => $batt_size, + 'sap_battery' => $sap_batt, + 'status' => $warranty->getStatus(), + 'date_create' => $warranty->getDateCreate()->format("d M Y g:i A"), + 'date_purchase' => $warranty->getDatePurchase()->format("d M Y g:i A"), + 'date_expire' => $expiry_date, + 'date_claim' => $claim_date, + 'claim_from' => $warranty->getClaimedFrom(), + 'is_activated' => $warranty->isActivated() ? 1 : 0, + ]; + + return $warr; + } } diff --git a/src/Entity/Warranty.php b/src/Entity/Warranty.php index a0e71a99..1cfa242c 100644 --- a/src/Entity/Warranty.php +++ b/src/Entity/Warranty.php @@ -359,7 +359,7 @@ class Warranty public function setActivated($flag_activated = true) { $this->flag_activated = $flag_activated; - return this; + return $this; } public function isActivated() From 79b0d3082d1290ceff5a47a388bf40dc4aee439e Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 3 Jul 2019 02:56:35 +0000 Subject: [PATCH 07/15] Fix typo when calling getBatterySize(). #227 --- src/Controller/APIController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 5134a884..55a8efa3 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -1881,7 +1881,7 @@ class APIController extends Controller $batt_model = $warranty->getBatteryModel()->getName(); } if (!(is_null($warranty->getBatterySize()))) { - $batt_size = $warranty->getBattyerSize()->getName(); + $batt_size = $warranty->getBatterySize()->getName(); } if (!(is_null($warranty->getSAPBattery()))) { $sap_batt = $warranty->getSAPBattery()->getID(); From 6cde81f0abab7a06caf4b2f247cfede777d36131 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 16 Jul 2019 00:20:22 +0000 Subject: [PATCH 08/15] Fix conflicts with API Controller #227 --- src/Controller/APIController.php | 110 +++++++++++++++---------------- 1 file changed, 54 insertions(+), 56 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 49fe68e8..a89e359f 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -38,13 +38,10 @@ use App\Entity\Promo; use App\Entity\Battery; use App\Entity\RiderRating; use App\Entity\JOEvent; -<<<<<<< HEAD use App\Entity\Warranty; -======= use App\Entity\Service; use App\Entity\Partner; use App\Entity\Review; ->>>>>>> b17a7104d3e116b57dbf2fdc4fe4aa2f8ef3113f use DateTime; use Exception; @@ -1819,21 +1816,14 @@ class APIController extends Controller return $res->getReturnResponse(); } -<<<<<<< HEAD public function activateWarranty(Request $req) { $required_params = ['plate_number']; -======= - public function listServices(Request $req) - { - $required_params = []; ->>>>>>> b17a7104d3e116b57dbf2fdc4fe4aa2f8ef3113f $em = $this->getDoctrine()->getManager(); $res = $this->checkParamsAndKey($req, $em, $required_params); if ($res->isError()) return $res->getReturnResponse(); -<<<<<<< HEAD $plate_number = $req->request->get('plate_number'); // find warranty using plate number @@ -1847,7 +1837,7 @@ class APIController extends Controller ->setErrorMessage('No warranty found for plate number'); return $res->getReturnResponse(); } - + // get first entry $warranty = current($warranty_results); if ($warranty->isActivated()) @@ -1860,52 +1850,11 @@ class APIController extends Controller $warranty->setActivated(); $em->flush(); -======= - // services - $results = $em->getRepository(Service::class)->findAll(); - if (empty($results)) - { - $res->setError(true) - ->setErrorMessage('No services available.'); - return $res->getReturnResponse(); - } - - $services = []; - foreach ($results as $result) - { - // get partners - $partners = []; - $service_partners = $result->getPartners(); - foreach($service_partners as $sp) - { - $partners[] = [ - 'id' => $sp->getID(), - 'name' => $sp->getName(), - 'branch' => $sp->getBranch(), - 'address' => $sp->getAddress(), - 'contact_nums' => $sp->getContactNumbers(), - 'time_open' => $sp->getTimeOpen()->format("g:i A"), - 'time_close' => $sp->getTimeClose()->format("g:i A"), - ]; - } - - $services[] = [ - 'id' => $result->getID(), - 'name' => $result->getName(), - 'partners' => $partners, - ]; - } - - $data['services'] = $services; - - $res->setData($data); ->>>>>>> b17a7104d3e116b57dbf2fdc4fe4aa2f8ef3113f return $res->getReturnResponse(); } -<<<<<<< HEAD - protected function findWarranty($plate_number) + protected function findWarranty($plate_number) { $em = $this->getDoctrine()->getManager(); // NOTE: Modify the search for the latest warranty. This seems hacky. @@ -1969,7 +1918,58 @@ class APIController extends Controller ]; return $warr; -======= + } + + public function listServices(Request $req) + { + $required_params = []; + $em = $this->getDoctrine()->getManager(); + $res = $this->checkParamsAndKey($req, $em, $required_params); + if ($res->isError()) + return $res->getReturnResponse(); + + // services + $results = $em->getRepository(Service::class)->findAll(); + if (empty($results)) + { + $res->setError(true) + ->setErrorMessage('No services available.'); + return $res->getReturnResponse(); + } + + $services = []; + foreach ($results as $result) + { + // get partners + $partners = []; + $service_partners = $result->getPartners(); + foreach($service_partners as $sp) + { + $partners[] = [ + 'id' => $sp->getID(), + 'name' => $sp->getName(), + 'branch' => $sp->getBranch(), + 'address' => $sp->getAddress(), + 'contact_nums' => $sp->getContactNumbers(), + 'time_open' => $sp->getTimeOpen()->format("g:i A"), + 'time_close' => $sp->getTimeClose()->format("g:i A"), + ]; + } + + $services[] = [ + 'id' => $result->getID(), + 'name' => $result->getName(), + 'partners' => $partners, + ]; + } + + $data['services'] = $services; + + $res->setData($data); + + return $res->getReturnResponse(); + } + public function getPartnerInformation(Request $req, $pid) { $required_params = []; @@ -2071,7 +2071,5 @@ class APIController extends Controller $res->setData($data); return $res->getReturnResponse(); - ->>>>>>> b17a7104d3e116b57dbf2fdc4fe4aa2f8ef3113f } } From f43c20482efa8353762cd63b7356edf062982dd1 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 18 Jul 2019 05:59:33 +0000 Subject: [PATCH 09/15] Restructure the response to get vehicle for API. #230 --- src/Controller/CAPI/VehicleController.php | 30 ++++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/Controller/CAPI/VehicleController.php b/src/Controller/CAPI/VehicleController.php index ab0ed286..e28fbe88 100644 --- a/src/Controller/CAPI/VehicleController.php +++ b/src/Controller/CAPI/VehicleController.php @@ -48,19 +48,37 @@ class VehicleController extends APIController { $this->denyAccessUnlessGranted('vehicle.list', null, 'No access.'); + // get manufacturers + $mfgs = $em->getRepository(VehicleManufacturer::class)->findBy([], ['name' => 'ASC']); + + // get vehicles $vehicles = $em->getRepository(Vehicle::class)->findBy([], ['manufacturer' => 'ASC', 'make' => 'ASC']); - $result = []; - foreach ($vehicles as $v) + // process manufacturer results + $mfg_data = []; + foreach($mfgs as $mfg) { - $result[] = [ - 'id' => $v->getID(), - 'name' => $v->getMake() . ' ' . $v->getModelYearFormatted(), + $mfg_data[] = [ + 'id' => $mfg->getID(), + 'name' => $mfg->getName(), + ]; + } + + // process vehicle results + $make_data = []; + foreach($vehicles as $vehicle) + { + $make_data[] = [ + 'id' => $vehicle->getID(), + 'mfg_id' => $vehicle->getManufacturer()->getID(), + 'make' => $vehicle->getMake(), + 'model' => $vehicle->getModelYearFormatted(), ]; } $data = [ - 'vehicles' => $result, + 'manufacturers' => $mfg_data, + 'vehicles' => $make_data, ]; return new APIResponse(true, 'Vehicles loaded.', $data); From f1f1d9253bbff1b26a92467599bca2026d013b37 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Sat, 20 Jul 2019 10:29:52 +0800 Subject: [PATCH 10/15] Remove partner list from get services mobile api call #231 --- src/Controller/APIController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index a89e359f..953a0edd 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -1940,6 +1940,7 @@ class APIController extends Controller $services = []; foreach ($results as $result) { + /* // get partners $partners = []; $service_partners = $result->getPartners(); @@ -1955,11 +1956,12 @@ class APIController extends Controller 'time_close' => $sp->getTimeClose()->format("g:i A"), ]; } + */ $services[] = [ 'id' => $result->getID(), 'name' => $result->getName(), - 'partners' => $partners, + // 'partners' => $partners, ]; } From 7a8ff5bf429e8656709069348e0cf7cf643c0c0d Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Sat, 20 Jul 2019 12:45:28 +0800 Subject: [PATCH 11/15] Add longitude and latitude to partner information in mobile API calls #231 --- src/Controller/APIController.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 953a0edd..7db96743 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -2014,6 +2014,8 @@ class APIController extends Controller 'contact_nums' => $partner->getContactNumbers(), 'time_open' => $partner->getTimeOpen()->format("g:i A"), 'time_close' => $partner->getTimeClose()->format("g:i A"), + 'longitude' => $partner->getCoordinates()->getLongitude(), + 'latitude' => $partner->getCoordinates()->getLatitude(), 'reviews' => $rev, ]; @@ -2051,10 +2053,10 @@ class APIController extends Controller $result = $query->getResult(); $data = []; + $partners = []; foreach($result as $row) { - $partner = []; - $partner[] = [ + $partners[] = [ 'id' => $row[0]->getID(), 'name' => $row[0]->getName(), 'branch' => $row[0]->getBranch(), @@ -2062,14 +2064,14 @@ class APIController extends Controller 'contact_nums' => $row[0]->getContactNumbers(), 'time_open' => $row[0]->getTimeOpen()->format("g:i A"), 'time_close' => $row[0]->getTimeClose()->format("g:i A"), - ]; - - $data[] = [ - 'partner' => $partner, + 'longitude' => $row[0]->getCoordinates()->getLongitude(), + 'latitude' => $row[0]->getCoordinates()->getLatitude(), 'db_distance' => $row['dist'], - ]; + ]; } + $data['partners'] = $partners; + $res->setData($data); return $res->getReturnResponse(); From 54269d54ac5efd143ac4ceccd7c3f2f5d50112d7 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Sat, 20 Jul 2019 12:50:16 +0800 Subject: [PATCH 12/15] Change url of provider info mobile api call #231 --- config/routes/api.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes/api.yaml b/config/routes/api.yaml index 5e04aea3..3b460e42 100644 --- a/config/routes/api.yaml +++ b/config/routes/api.yaml @@ -136,7 +136,7 @@ api_service_list: methods: [GET] api_partner_info: - path: /api/partner/{pid} + path: /api/partners/{pid} controller: App\Controller\APIController:getPartnerInformation methods: [GET] From 899f9df721d7385a740b36a69ae414b4019c48b5 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Sat, 20 Jul 2019 12:51:52 +0800 Subject: [PATCH 13/15] Remove mobile_session from review information in mobile api #231 --- src/Controller/APIController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 7db96743..3d324a0a 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -2001,7 +2001,7 @@ class APIController extends Controller 'rating' => $review->getRating(), 'message' => $review->getMessage(), 'date_create' => $review->getDateCreate()->format("d M Y g:i A"), - 'mobile_session' => $review->getMobileSession()->getID(), + // 'mobile_session' => $review->getMobileSession()->getID(), ]; } } From da32614181e233ea4a689a61264bb4cead72b17e Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Sat, 20 Jul 2019 15:15:47 +0800 Subject: [PATCH 14/15] Add partner review api call #231 --- config/routes/api.yaml | 4 +++ src/Controller/APIController.php | 42 ++++++++++++++++++++++++++++++++ src/Entity/Review.php | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/config/routes/api.yaml b/config/routes/api.yaml index 3b460e42..f55b0d83 100644 --- a/config/routes/api.yaml +++ b/config/routes/api.yaml @@ -145,3 +145,7 @@ api_partner: controller: App\Controller\APIController:getClosestPartners methods: [GET] +api_partner_review: + path: /api/partners/{pid}/review + controller: App\Controller\APIController:reviewPartner + methods: [POST] diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 3d324a0a..f65f0c23 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -5,6 +5,7 @@ namespace App\Controller; use Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; use Doctrine\DBAL\DBALException; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Bundle\FrameworkBundle\Controller\Controller; @@ -2076,4 +2077,45 @@ class APIController extends Controller return $res->getReturnResponse(); } + + public function reviewPartner($pid, Request $req, EntityManagerInterface $em) + { + $required_params = [ + 'rating', + 'message', + ]; + + $res = $this->checkParamsAndKey($req, $em, $required_params); + if ($res->isError()) + return $res->getReturnResponse(); + + $rating = $req->request->get('rating'); + $msg = $req->request->get('message'); + + // TODO: check rating if 1 - 5 + + // check if partner exists + $partner = $em->getRepository(Partner::class)->find($pid); + if ($partner == null) + { + $res->setError(true) + ->setErrorMessage('No partner found.'); + return $res->getReturnResponse(); + } + + $rev = new Review(); + $rev->setRating($rating) + ->setMessage($msg) + ->setPartner($partner) + ->setMobileSession($this->session); + + // save to db + $em->persist($rev); + $em->flush(); + + $data = []; + $res->setData($data); + + return $res->getReturnResponse(); + } } diff --git a/src/Entity/Review.php b/src/Entity/Review.php index 57ee2c6f..9903784e 100644 --- a/src/Entity/Review.php +++ b/src/Entity/Review.php @@ -56,7 +56,7 @@ class Review { $this->date_create = new DateTime(); $this->rating = 0; - $this->comment = ""; + $this->message = ""; } public function getID() From b87242e3561f9d69102e02523a1c42bba44ed0ca Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Sun, 21 Jul 2019 09:50:57 +0800 Subject: [PATCH 15/15] Fix findWarranty bug in API controller #232 --- src/Controller/APIController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index f65f0c23..6d5e295a 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -1863,12 +1863,18 @@ class APIController extends Controller $warranty_results = $em->getRepository(Warranty::class)->findBy(['plate_number' => $plate_number], ['date_create' => 'desc']); + $warr = []; + // check if warranty_results is empty if (empty($warranty_results)) { + /* $res->setError(true) ->setErrorMessage('No warranty found for plate number'); return $res->getReturnResponse(); + */ + + return $warr; } // get first entry @@ -1897,7 +1903,6 @@ class APIController extends Controller $expiry_date = $warranty->getDateExpire()->format("d M Y g:i A"); } - $warr = []; $warr[] = [ 'id' => $warranty->getID(), 'serial' => $warranty->getSerial(),