317 lines
8.5 KiB
PHP
317 lines
8.5 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
|
|
use App\Ramcar\NewAPIResult;
|
|
|
|
use App\Service\RiderAPIHandlerInterface;
|
|
|
|
// Rider API controller for CMB
|
|
class CMBRAPIController extends Controller
|
|
{
|
|
public function register(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->register($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function login(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->login($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function logout(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->logout($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function getJobOrder(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->getJobOrder($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function acceptJobOrder(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->acceptJobOrder($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function cancelJobOrder(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->cancelJobOrder($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function arrive(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->arrive($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
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)
|
|
{
|
|
$data = $rapi_handler->hubArrive($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function payment(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->payment($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function available(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->available($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function getPromos(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->getPromos($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function getBatteries(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->getBatteries($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function changeService(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->changeService($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function getJobOrderHistory(Request $req, $period, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->getJobOrderHistory($req, $period);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function getAssignedJobOrders(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->getAssignedJobOrders($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function setJobOrderInTransit(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->setJobOrderInTransit($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function generateInvoice(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->generateInvoice($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function goOnline(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->goOnline($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function goOffline(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->goOffline($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function startJobOrder(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->startJobOrder($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function completeJobOrder(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->completeJobOrder($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function setActiveJobOrder(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->setActiveJobOrder($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function rejectJobOrder(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->rejectJobOrder($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function setOdometer(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->setOdometer($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function uploadFinishPhotos(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->uploadFinishPhotos($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function getStatus(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->getStatus($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function getOngoingJobOrder(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->getOngoingJobOrder($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function getPaymentMethods(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->getPaymentMethods($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function getCancelReasons(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->getCancelReasons($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
return $res->getReturnResponse();
|
|
}
|
|
|
|
public function verifyJobOrder(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
|
{
|
|
$data = $rapi_handler->verifyJobOrder($req);
|
|
|
|
$res = $this->generateResultFromHandler($data);
|
|
|
|
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;
|
|
}
|
|
|
|
}
|