Add status change calls for rider api #119
This commit is contained in:
parent
d5fb5222ca
commit
00f602e0d7
2 changed files with 101 additions and 3 deletions
|
|
@ -32,10 +32,10 @@ rapi_jo_cancel:
|
||||||
|
|
||||||
rapi_arrive:
|
rapi_arrive:
|
||||||
path: /rapi/arrive
|
path: /rapi/arrive
|
||||||
controller: App\Controller\RAPIController::cancelJobOrder
|
controller: App\Controller\RAPIController::arrive
|
||||||
methods: [POST]
|
methods: [POST]
|
||||||
|
|
||||||
rapi_payment:
|
rapi_payment:
|
||||||
path: /rapi/payment
|
path: /rapi/payment
|
||||||
controller: App\Controller\RAPIController::cancelJobOrder
|
controller: App\Controller\RAPIController::payment
|
||||||
methods: [POST]
|
methods: [POST]
|
||||||
|
|
|
||||||
|
|
@ -349,7 +349,105 @@ class RAPIController extends Controller
|
||||||
return $res->getReturnResponse();
|
return $res->getReturnResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setStatus(Request $req)
|
protected function checkJO(Request $req, $required_params)
|
||||||
{
|
{
|
||||||
|
// set jo status to in transit
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$res = $this->checkParamsAndKey($req, $em, $required_params);
|
||||||
|
if ($res->isError())
|
||||||
|
return $res;
|
||||||
|
|
||||||
|
// are we logged in?
|
||||||
|
if (!$this->session->hasRider())
|
||||||
|
{
|
||||||
|
$res->setError(true)
|
||||||
|
->setErrorMessage('No logged in rider.');
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rider = $this->session->getRider();
|
||||||
|
|
||||||
|
// check if we have an active JO
|
||||||
|
$jo = $rider->getActiveJobOrder();
|
||||||
|
if ($jo == null)
|
||||||
|
{
|
||||||
|
$res->setError(true)
|
||||||
|
->setErrorMessage('No active job order.');
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if the jo_id sent is the same as our active jo
|
||||||
|
if ($req->request->get('jo_id') != $jo->getID())
|
||||||
|
{
|
||||||
|
$res->setError(true)
|
||||||
|
->setErrorMessage('Job order selected is not active job order.');
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function acceptJobOrder(Request $req)
|
||||||
|
{
|
||||||
|
$required_params = ['jo_id'];
|
||||||
|
$res = $this->checkJO($req, $required_params);
|
||||||
|
if ($res->isError())
|
||||||
|
return $res->getReturnResponse();
|
||||||
|
|
||||||
|
// TODO: refactor this into a jo handler class, so we don't have to repeat for control center
|
||||||
|
|
||||||
|
// set jo status to in transit
|
||||||
|
$jo->setStatus(JOStatus::IN_TRANSIT);
|
||||||
|
|
||||||
|
// TODO: send mqtt event
|
||||||
|
|
||||||
|
// TODO: add event
|
||||||
|
|
||||||
|
return $res->getReturnResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cancelJobOrder(Request $req)
|
||||||
|
{
|
||||||
|
$required_params = ['jo_id'];
|
||||||
|
$res = $this->checkJO($req, $required_params);
|
||||||
|
if ($res->isError())
|
||||||
|
return $res->getReturnResponse();
|
||||||
|
|
||||||
|
// TODO: refactor this into a jo handler class, so we don't have to repeat for control center
|
||||||
|
|
||||||
|
// set jo status to cancelled
|
||||||
|
$jo->setStatus(JOStatus::CANCELLED);
|
||||||
|
|
||||||
|
// TODO: send mqtt event
|
||||||
|
|
||||||
|
// TODO: add event
|
||||||
|
|
||||||
|
return $res->getReturnResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function arrive(Request $req)
|
||||||
|
{
|
||||||
|
$required_params = ['jo_id'];
|
||||||
|
$res = $this->checkJO($req, $required_params);
|
||||||
|
if ($res->isError())
|
||||||
|
return $res->getReturnResponse();
|
||||||
|
|
||||||
|
// TODO: refactor this into a jo handler class, so we don't have to repeat for control center
|
||||||
|
|
||||||
|
// set jo status to in progress
|
||||||
|
$jo->setStatus(JOStatus::IN_PROGRESS);
|
||||||
|
|
||||||
|
// TODO: send mqtt event
|
||||||
|
|
||||||
|
// TODO: add event
|
||||||
|
|
||||||
|
return $res->getReturnResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function payment(Request $req)
|
||||||
|
{
|
||||||
|
// set invoice to paid
|
||||||
|
|
||||||
|
// set jo status to fulfilled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue