diff --git a/catalyst/api-bundle/Command/TestCommand.php b/catalyst/api-bundle/Command/TestCommand.php index ae99f6cd..e1512157 100644 --- a/catalyst/api-bundle/Command/TestCommand.php +++ b/catalyst/api-bundle/Command/TestCommand.php @@ -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'); } } diff --git a/config/routes/warranty_api.yaml b/config/routes/warranty_api.yaml index bd607ef5..6414c97e 100644 --- a/config/routes/warranty_api.yaml +++ b/config/routes/warranty_api.yaml @@ -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] diff --git a/src/Controller/CAPI/BatteryController.php b/src/Controller/CAPI/BatteryController.php index af2361e2..f99d0ad5 100644 --- a/src/Controller/CAPI/BatteryController.php +++ b/src/Controller/CAPI/BatteryController.php @@ -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); } } diff --git a/src/Controller/CAPI/VehicleController.php b/src/Controller/CAPI/VehicleController.php new file mode 100644 index 00000000..67527bb3 --- /dev/null +++ b/src/Controller/CAPI/VehicleController.php @@ -0,0 +1,55 @@ +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); + } +}