From 943c01e5d9846f77bb45b9a4bfe79e9d3729f77e Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Sat, 20 Jun 2020 16:38:08 +0800 Subject: [PATCH] Add jo perform rider api call for CMB #424 --- config/routes/cmb_rider_api.yaml | 5 ++++ src/Controller/CMBRAPIController.php | 29 +++++++++++++++++++ src/Entity/JobOrder.php | 5 ++++ src/Ramcar/JOStatus.php | 18 +++++++----- .../RiderAPIHandler/CMBRiderAPIHandler.php | 22 ++++++++++++++ 5 files changed, 72 insertions(+), 7 deletions(-) diff --git a/config/routes/cmb_rider_api.yaml b/config/routes/cmb_rider_api.yaml index 77942ca2..24b2e63d 100644 --- a/config/routes/cmb_rider_api.yaml +++ b/config/routes/cmb_rider_api.yaml @@ -35,6 +35,11 @@ cmb_rapi_arrive: controller: App\Controller\CMBRAPIController::arrive methods: [POST] +cmb_rapi_performed: + path: /cmbrapi/joperform + controller: App\Controller\CMBRAPIController::performJobOrder + methods: [POST] + cmb_rapi_payment: path: /cmbrapi/jopayment controller: App\Controller\CMBRAPIController::payment diff --git a/src/Controller/CMBRAPIController.php b/src/Controller/CMBRAPIController.php index 328b7952..e7dba85a 100644 --- a/src/Controller/CMBRAPIController.php +++ b/src/Controller/CMBRAPIController.php @@ -134,6 +134,26 @@ class CMBRAPIController extends Controller return $res->getReturnResponse(); } + protected function generateResultFromHandler($data) + { + $res = new NewAPIResult(); + + if (isset($data['error'])) + { + $message = $data['error']; + $title = $data['title']; + + $res->setError(true) + ->setErrorTitle($title) + ->setErrorMessage($message); + } + else + { + $res->setData($data); + + return $res; + } + public function cancelJobOrder(Request $req, RiderAPIHandlerInterface $rapi_handler) { $res = new NewAPIResult(); @@ -183,6 +203,15 @@ class CMBRAPIController extends Controller return $res->getReturnResponse(); } + public function performJobOrder(Request $req, RiderAPIHandlerInterface $rapi_handler) + { + $data = $rapi_handler->performJobOrder($req); + + $res = $this->generateResultFromHandler($data); + + return $res->getReturnResponse(); + } + public function hubArrive(Request $req, RiderAPIHandlerInterface $rapi_handler) { $res = new NewAPIResult(); diff --git a/src/Entity/JobOrder.php b/src/Entity/JobOrder.php index a174fb96..4793571d 100644 --- a/src/Entity/JobOrder.php +++ b/src/Entity/JobOrder.php @@ -802,6 +802,11 @@ class JobOrder $this->makeRiderAvailable(); } + public function perform() + { + $this->setStatus(JOStatus::PERFORM) + } + public function fulfill() { $this->setStatus(JOStatus::FULFILLED) diff --git a/src/Ramcar/JOStatus.php b/src/Ramcar/JOStatus.php index 5ba8f5d1..14574845 100644 --- a/src/Ramcar/JOStatus.php +++ b/src/Ramcar/JOStatus.php @@ -4,13 +4,15 @@ namespace App\Ramcar; class JOStatus extends NameValue { - const PENDING = 'pending'; // NOTE: JO has no hub assigned - const RIDER_ASSIGN = 'rider_assign'; // NOTE: JO has hub assigned but no rider assigned - const ASSIGNED = 'assigned'; // NOTE: JO has hub and rider assigned - const IN_TRANSIT = 'in_transit'; // NOTE: JO's rider is on his way - const IN_PROGRESS = 'in_progress'; // NOTE: JO fulfillment in progress - const CANCELLED = 'cancelled'; // NOTE: JO is cancelled - const FULFILLED = 'fulfilled'; // NOTE: JO is fulfilled + const PENDING = 'pending'; // JO has no hub assigned + const RIDER_ASSIGN = 'rider_assign'; // JO has hub assigned but no rider assigned + const ASSIGNED = 'assigned'; // JO has hub and rider assigned + const IN_TRANSIT = 'in_transit'; // JO's rider is on his way + const IN_PROGRESS = 'in_progress'; // JO fulfillment in progress + const PERFORMED = 'performed'; // Rider has finished performing JO task / service + const PAID = 'paid'; // Rider has finished collecting payment for JO + const CANCELLED = 'cancelled'; // JO is cancelled + const FULFILLED = 'fulfilled'; // JO is fulfilled const COLLECTION = [ 'pending' => 'For Dispatch', @@ -18,6 +20,8 @@ class JOStatus extends NameValue 'assigned' => 'Assigned', 'in_transit' => 'In Transit', 'in_progress' => 'In Progress', + 'performed' => 'Service Performed', + 'paid' => 'Customer Paid', 'cancelled' => 'Cancelled', 'fulfilled' => 'Completed', ]; diff --git a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php index b5ccdfdd..267f3849 100644 --- a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php @@ -801,6 +801,28 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + public function performJobOrder(Request $req) + { + $required_params = [ + 'jo_id', + ]; + + $data = $this->checkJO($req, $required_params, $jo); + if (isset($data['error'])) + { + $data['title'] = 'Failed Job Order Perform'; + return $data; + } + + $jo->perform() + + // TODO: make event for this? + + $this->em->flush(); + + return $data; + } + public function rejectJobOrder(Request $req) { $required_params = [