Add API call to return battery data given a serial. #783
This commit is contained in:
parent
b123be25cc
commit
ae46d64f5b
2 changed files with 46 additions and 1 deletions
|
|
@ -99,4 +99,9 @@ capi_rider_jo_start:
|
|||
capi_rider_battery_sizes:
|
||||
path: /rider_api/battery_sizes
|
||||
controller: App\Controller\CAPI\RiderAppController::getBatterySizes
|
||||
methods: [GET]
|
||||
methods: [GET]
|
||||
|
||||
capi_rider_battery_info:
|
||||
path: /rider_api/battery/{serial}
|
||||
controller: App\Controller\CAPI\RiderAppController::getBatteryInfo
|
||||
methods: [GET]
|
||||
|
|
|
|||
|
|
@ -1126,6 +1126,46 @@ class RiderAppController extends ApiController
|
|||
return new APIResponse(true, 'Batteries found.', $data);
|
||||
}
|
||||
|
||||
public function getBatteryInfo(Request $req, $serial, EntityManagerInterface $em)
|
||||
{
|
||||
if (empty($serial))
|
||||
{
|
||||
return new APIResponse(false, 'Missing parameter(s): serial');
|
||||
}
|
||||
|
||||
// get capi user
|
||||
$capi_user = $this->getUser();
|
||||
if ($capi_user == null)
|
||||
return new APIResponse(false, 'User not found.');
|
||||
|
||||
// get rider id from capi user metadata
|
||||
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
||||
if ($rider == null)
|
||||
return new APIResponse(false, 'No rider found.');
|
||||
|
||||
// find battery given serial/sap_code and flag_active is true
|
||||
$batts = $em->getRepository(Battery::class)->findBy(['flag_active' => true, 'sap_code' => $serial]);
|
||||
|
||||
$batt_data = [];
|
||||
foreach ($batts as $batt)
|
||||
{
|
||||
$batt_data[] = [
|
||||
'id' => $batt->getID(),
|
||||
'model_id' => $batt->getModel()->getID(),
|
||||
'model_name' => $batt->getModel()->getName(),
|
||||
'size_id' => $batt->getSize()->getID(),
|
||||
'size_name' => $batt->getSize()->getName(),
|
||||
'selling_price' => $batt->getSellingPrice(),
|
||||
];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'batteries' => $batt_data,
|
||||
];
|
||||
|
||||
return new APIResponse(true, 'Battery info found.', $data);
|
||||
}
|
||||
|
||||
public function changeService(Request $req, EntityManagerInterface $em, InvoiceGeneratorInterface $ic)
|
||||
{
|
||||
// $this->debugRequest($req);
|
||||
|
|
|
|||
Loading…
Reference in a new issue