Add get batteries call to rider api #132
This commit is contained in:
parent
393fc525c0
commit
0e42e68b08
2 changed files with 83 additions and 4 deletions
|
|
@ -44,3 +44,13 @@ rapi_promos:
|
|||
path: /rapi/promos
|
||||
controller: App\Controller\RAPIController::getPromos
|
||||
methods: [GET]
|
||||
|
||||
rapi_batteries:
|
||||
path: /rapi/batteries
|
||||
controller: App\Controller\RAPIController::getBatteries
|
||||
methods: [GET]
|
||||
|
||||
rapi_change_service:
|
||||
path: /rapi/service
|
||||
controller: App\Controller\RAPIController::changeService
|
||||
methods: [POST]
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ use App\Entity\CustomerVehicle;
|
|||
use App\Entity\JobOrder;
|
||||
use App\Entity\Promo;
|
||||
use App\Entity\Battery;
|
||||
use App\Entity\BatteryModel;
|
||||
use App\Entity\BatterySize;
|
||||
use App\Entity\RiderRating;
|
||||
use App\Entity\Rider;
|
||||
use App\Entity\User;
|
||||
|
|
@ -366,7 +368,7 @@ class RAPIController extends Controller
|
|||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
protected function checkJO(Request $req, $required_params)
|
||||
protected function checkJO(Request $req, $required_params, &$jo = null)
|
||||
{
|
||||
// set jo status to in transit
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
|
@ -407,7 +409,7 @@ class RAPIController extends Controller
|
|||
public function acceptJobOrder(Request $req)
|
||||
{
|
||||
$required_params = ['jo_id'];
|
||||
$res = $this->checkJO($req, $required_params);
|
||||
$res = $this->checkJO($req, $required_params, $jo);
|
||||
if ($res->isError())
|
||||
return $res->getReturnResponse();
|
||||
|
||||
|
|
@ -426,7 +428,7 @@ class RAPIController extends Controller
|
|||
public function cancelJobOrder(Request $req)
|
||||
{
|
||||
$required_params = ['jo_id'];
|
||||
$res = $this->checkJO($req, $required_params);
|
||||
$res = $this->checkJO($req, $required_params, $jo);
|
||||
if ($res->isError())
|
||||
return $res->getReturnResponse();
|
||||
|
||||
|
|
@ -445,7 +447,7 @@ class RAPIController extends Controller
|
|||
public function arrive(Request $req)
|
||||
{
|
||||
$required_params = ['jo_id'];
|
||||
$res = $this->checkJO($req, $required_params);
|
||||
$res = $this->checkJO($req, $required_params, $jo);
|
||||
if ($res->isError())
|
||||
return $res->getReturnResponse();
|
||||
|
||||
|
|
@ -494,4 +496,71 @@ class RAPIController extends Controller
|
|||
$res->setData($data);
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function getBatteries(Request $req)
|
||||
{
|
||||
// get batteries, models, and sizes
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$required_params = [];
|
||||
$res = $this->checkParamsAndKey($req, $em, $required_params);
|
||||
if ($res->isError())
|
||||
return $res->getReturnResponse();
|
||||
|
||||
$batts = $em->getRepository(Battery::class)->findAll();
|
||||
$models = $em->getRepository(BatteryModel::class)->findAll();
|
||||
$sizes = $em->getRepository(BatterySize::class)->findAll();
|
||||
|
||||
$batt_data = [];
|
||||
foreach ($batts as $batt)
|
||||
{
|
||||
$batt_data[] = [
|
||||
'id' => $batt->getID(),
|
||||
'model_id' => $batt->getModel()->getID(),
|
||||
'size_id' => $batt->getSize()->getID(),
|
||||
'sell_price' => $batt->getSellingPrice(),
|
||||
];
|
||||
}
|
||||
|
||||
$model_data = [];
|
||||
foreach ($models as $model)
|
||||
{
|
||||
$model_data[] = [
|
||||
'id' => $model->getID(),
|
||||
'name' => $model->getName(),
|
||||
];
|
||||
}
|
||||
|
||||
$size_data = [];
|
||||
foreach ($sizes as $size)
|
||||
{
|
||||
$size_data[] = [
|
||||
'id' => $size->getID(),
|
||||
'name' => $size->getName(),
|
||||
];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'batteries' => $batt_data,
|
||||
'models' => $model_data,
|
||||
'sizes' => $size_data,
|
||||
];
|
||||
|
||||
$res->setData($data);
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function changeService(Request $req)
|
||||
{
|
||||
// allow rider to change service, promo, battery and trade-in options
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$required_params = ['jo_id', 'stype_id', 'promo_id', 'battery_id', 'trade_in'];
|
||||
$res = $this->checkJO($req, $required_params, $jo);
|
||||
if ($res->isError())
|
||||
return $res->getReturnResponse();
|
||||
|
||||
|
||||
// TODO: add event
|
||||
|
||||
// TODO: send mqtt event (?)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue