Update battery api controller, routes and test scripts #172
This commit is contained in:
parent
081d9cb93c
commit
85121a973d
3 changed files with 51 additions and 15 deletions
|
|
@ -80,8 +80,9 @@ class TestCommand extends Command
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// battery
|
// battery
|
||||||
// $api->get('/capi/battery_models');
|
$api->get('/capi/battery_brands');
|
||||||
// $api->get('/capi/battery_sizes');
|
$api->get('/capi/battery_sizes');
|
||||||
|
$api->get('/capi/batteries');
|
||||||
|
|
||||||
// vehicle
|
// vehicle
|
||||||
// $api->get('/capi/vehicle_manufacturers');
|
// $api->get('/capi/vehicle_manufacturers');
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,21 @@ capi_test:
|
||||||
# battery api
|
# battery api
|
||||||
|
|
||||||
# battery models
|
# battery models
|
||||||
capi_battery_models:
|
#capi_battery_models:
|
||||||
path: /capi/battery_models
|
# path: /capi/battery_models
|
||||||
controller: App\Controller\CAPI\BatteryController::getModels
|
# controller: App\Controller\CAPI\BatteryController::getModels
|
||||||
|
# methods: [GET]
|
||||||
|
|
||||||
|
# battery models
|
||||||
|
capi_battery_brands:
|
||||||
|
path: /capi/battery_brands
|
||||||
|
controller: App\Controller\CAPI\BatteryController::getBrands
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
# batteries
|
||||||
|
capi_batteries:
|
||||||
|
path: /capi/batteries
|
||||||
|
controller: App\Controller\CAPI\BatteryController::getBatteries
|
||||||
methods: [GET]
|
methods: [GET]
|
||||||
|
|
||||||
# battery sizes
|
# battery sizes
|
||||||
|
|
|
||||||
|
|
@ -8,34 +8,57 @@ use Doctrine\ORM\Query;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Catalyst\APIBundle\Controller\APIController;
|
use Catalyst\APIBundle\Controller\APIController;
|
||||||
use Catalyst\APIBundle\Response\APIResponse;
|
use Catalyst\APIBundle\Response\APIResponse;
|
||||||
use App\Entity\BatteryModel;
|
|
||||||
use App\Entity\BatterySize;
|
use App\Entity\SAPBattery;
|
||||||
|
use App\Entity\SAPBatterySize;
|
||||||
|
use App\Entity\SAPBatteryBrand;
|
||||||
|
|
||||||
class BatteryController extends APIController
|
class BatteryController extends APIController
|
||||||
{
|
{
|
||||||
public function getModels(EntityManagerInterface $em)
|
public function getBatteries(EntityManagerInterface $em)
|
||||||
{
|
{
|
||||||
$models = $em->getRepository(BatteryModel::class)->findBy([], ['name' => 'ASC']);
|
$batteries = $em->getRepository(SAPBattery::class)->findBy([], ['id' => 'ASC']);
|
||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($models as $model)
|
foreach ($batteries as $batt)
|
||||||
{
|
{
|
||||||
$result[] = [
|
$result[] = [
|
||||||
'id' => $model->getID(),
|
'id' => $batt->getID(),
|
||||||
'name' => $model->getName(),
|
'size' => $batt->getSize()->getID(),
|
||||||
|
'brand' => $batt->getBrand()->getID(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'models' => $result,
|
'batt' => $result,
|
||||||
];
|
];
|
||||||
|
|
||||||
return new APIResponse(true, 'Battery models loaded.', $data);
|
return new APIResponse(true, 'Batteries loaded.', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBrands(EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
$brands = $em->getRepository(SAPBatteryBrand::class)->findBy([], ['name' => 'ASC']);
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
foreach ($brands as $brand)
|
||||||
|
{
|
||||||
|
$result[] = [
|
||||||
|
'id' => $brand->getID(),
|
||||||
|
'name' => $brand->getName(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'brands' => $result,
|
||||||
|
];
|
||||||
|
|
||||||
|
return new APIResponse(true, 'Battery brands loaded.', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSizes(EntityManagerInterface $em)
|
public function getSizes(EntityManagerInterface $em)
|
||||||
{
|
{
|
||||||
$sizes = $em->getRepository(BatterySize::class)->findBy([], ['name' => 'ASC']);
|
$sizes = $em->getRepository(SAPBatterySize::class)->findBy([], ['name' => 'ASC']);
|
||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($sizes as $size)
|
foreach ($sizes as $size)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue