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
|
||||
// $api->get('/capi/battery_models');
|
||||
// $api->get('/capi/battery_sizes');
|
||||
$api->get('/capi/battery_brands');
|
||||
$api->get('/capi/battery_sizes');
|
||||
$api->get('/capi/batteries');
|
||||
|
||||
// vehicle
|
||||
// $api->get('/capi/vehicle_manufacturers');
|
||||
|
|
|
|||
|
|
@ -7,9 +7,21 @@ capi_test:
|
|||
# battery api
|
||||
|
||||
# battery models
|
||||
capi_battery_models:
|
||||
path: /capi/battery_models
|
||||
controller: App\Controller\CAPI\BatteryController::getModels
|
||||
#capi_battery_models:
|
||||
# path: /capi/battery_models
|
||||
# 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]
|
||||
|
||||
# battery sizes
|
||||
|
|
|
|||
|
|
@ -8,34 +8,57 @@ use Doctrine\ORM\Query;
|
|||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Catalyst\APIBundle\Controller\APIController;
|
||||
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
|
||||
{
|
||||
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 = [];
|
||||
foreach ($models as $model)
|
||||
foreach ($batteries as $batt)
|
||||
{
|
||||
$result[] = [
|
||||
'id' => $model->getID(),
|
||||
'name' => $model->getName(),
|
||||
'id' => $batt->getID(),
|
||||
'size' => $batt->getSize()->getID(),
|
||||
'brand' => $batt->getBrand()->getID(),
|
||||
];
|
||||
}
|
||||
|
||||
$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)
|
||||
{
|
||||
$sizes = $em->getRepository(BatterySize::class)->findBy([], ['name' => 'ASC']);
|
||||
$sizes = $em->getRepository(SAPBatterySize::class)->findBy([], ['name' => 'ASC']);
|
||||
|
||||
$result = [];
|
||||
foreach ($sizes as $size)
|
||||
|
|
|
|||
Loading…
Reference in a new issue