Add vehicle and battery apis #164
This commit is contained in:
parent
959d2c6efc
commit
9fcae0f05b
4 changed files with 120 additions and 27 deletions
|
|
@ -39,6 +39,7 @@ class TestCommand extends Command
|
|||
// test
|
||||
$api->get('/capi/test');
|
||||
|
||||
// TODO: shift this out of the bundle, since it's project specific
|
||||
// warranty register
|
||||
$params = [
|
||||
];
|
||||
|
|
@ -47,5 +48,12 @@ class TestCommand extends Command
|
|||
// warranty find
|
||||
$api->get('/capi/warranty/LJ34LJADR12SDLKJL');
|
||||
|
||||
// battery
|
||||
$api->get('/capi/battery_models');
|
||||
$api->get('/capi/battery_sizes');
|
||||
|
||||
// vehicle
|
||||
$api->get('/capi/vehicle_manufacturers');
|
||||
$api->get('/capi/vehicles');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,16 +6,29 @@ capi_test:
|
|||
|
||||
# battery api
|
||||
|
||||
# find battery
|
||||
capi_battery_find:
|
||||
path: /capi/battery/{id}
|
||||
controller: App\Controller\CAPI\BatteryController::find
|
||||
# battery models
|
||||
capi_battery_models:
|
||||
path: /capi/battery_models
|
||||
controller: App\Controller\CAPI\BatteryController::getModels
|
||||
methods: [GET]
|
||||
|
||||
# search battery
|
||||
capi_battery_search:
|
||||
path: /capi/battery/search
|
||||
controller: App\Controller\CAPI\BatteryController::search
|
||||
# battery sizes
|
||||
capi_battery_sizes:
|
||||
path: /capi/battery_sizes
|
||||
controller: App\Controller\CAPI\BatteryController::getSizes
|
||||
methods: [GET]
|
||||
|
||||
|
||||
# vehicle api
|
||||
|
||||
capi_vehicle_mfgs:
|
||||
path: /capi/vehicle_manufacturers
|
||||
controller: App\Controller\CAPI\VehicleController::getManufacturers
|
||||
methods: [GET]
|
||||
|
||||
capi_vehicle_list:
|
||||
path: /capi/vehicles
|
||||
controller: App\Controller\CAPI\VehicleController::list
|
||||
methods: [GET]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,35 +4,52 @@ namespace App\Controller\CAPI;
|
|||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use Catalyst\APIBundle\Controller\APIController;
|
||||
|
||||
use App\Entity\Battery;
|
||||
use Catalyst\APIBundle\Response\APIResponse;
|
||||
use App\Entity\BatteryModel;
|
||||
use App\Entity\BatterySize;
|
||||
|
||||
class BatteryController extends Controller implements APIController
|
||||
{
|
||||
public function find($serial, EntityManagerInterface $em)
|
||||
public function getModels(EntityManagerInterface $em)
|
||||
{
|
||||
}
|
||||
$models = $em->getRepository(BatteryModel::class)->findBy([], ['name' => 'ASC']);
|
||||
|
||||
public function register()
|
||||
{
|
||||
}
|
||||
$result = [];
|
||||
foreach ($models as $model)
|
||||
{
|
||||
$result[] = [
|
||||
'id' => $model->getID(),
|
||||
'name' => $model->getName(),
|
||||
];
|
||||
}
|
||||
|
||||
public function claim($serial)
|
||||
{
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
$data = [
|
||||
'success' => true,
|
||||
'models' => $result,
|
||||
];
|
||||
return new JsonResponse($data);
|
||||
|
||||
return new APIResponse(true, 'Battery models loaded.', $data);
|
||||
}
|
||||
|
||||
public function getSizes(EntityManagerInterface $em)
|
||||
{
|
||||
$sizes = $em->getRepository(BatterySize::class)->findBy([], ['name' => 'ASC']);
|
||||
|
||||
$result = [];
|
||||
foreach ($sizes as $size)
|
||||
{
|
||||
$result[] = [
|
||||
'id' => $size->getID(),
|
||||
'name' => $size->getName(),
|
||||
];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'sizes' => $result,
|
||||
];
|
||||
|
||||
return new APIResponse(true, 'Battery sizes loaded.', $data);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
55
src/Controller/CAPI/VehicleController.php
Normal file
55
src/Controller/CAPI/VehicleController.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller\CAPI;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Catalyst\APIBundle\Controller\APIController;
|
||||
use Catalyst\APIBundle\Response\APIResponse;
|
||||
use App\Entity\Vehicle;
|
||||
use App\Entity\VehicleManufacturer;
|
||||
|
||||
class VehicleController extends Controller implements APIController
|
||||
{
|
||||
public function getManufacturers(EntityManagerInterface $em)
|
||||
{
|
||||
$mfgs = $em->getRepository(VehicleManufacturer::class)->findBy([], ['name' => 'ASC']);
|
||||
|
||||
$result = [];
|
||||
foreach ($mfgs as $mfg)
|
||||
{
|
||||
$result[] = [
|
||||
'id' => $mfg->getID(),
|
||||
'name' => $mfg->getName(),
|
||||
];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'manufacturers' => $result,
|
||||
];
|
||||
|
||||
return new APIResponse(true, 'Vehicle manufacturers loaded.', $data);
|
||||
}
|
||||
|
||||
public function list(EntityManagerInterface $em)
|
||||
{
|
||||
$vehicles = $em->getRepository(Vehicle::class)->findBy([], ['manufacturer' => 'ASC', 'make' => 'ASC']);
|
||||
|
||||
$result = [];
|
||||
foreach ($vehicles as $v)
|
||||
{
|
||||
$result[] = [
|
||||
'id' => $v->getID(),
|
||||
'name' => $v->getMake() . ' ' . $v->getModelYearFormatted(),
|
||||
];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'vehicles' => $result,
|
||||
];
|
||||
|
||||
return new APIResponse(true, 'Vehicles loaded.', $data);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue