Add get all warranties api call #171
This commit is contained in:
parent
28fdba3872
commit
e4cedd9e4d
3 changed files with 53 additions and 0 deletions
|
|
@ -39,6 +39,7 @@ class TestCommand extends Command
|
||||||
// test
|
// test
|
||||||
$api->get('/capi/test');
|
$api->get('/capi/test');
|
||||||
|
|
||||||
|
/*
|
||||||
// TODO: shift this out of the bundle, since it's project specific
|
// TODO: shift this out of the bundle, since it's project specific
|
||||||
// warranty register
|
// warranty register
|
||||||
$serial = 'AJ34LJADR12134LKJL';
|
$serial = 'AJ34LJADR12134LKJL';
|
||||||
|
|
@ -53,6 +54,12 @@ class TestCommand extends Command
|
||||||
'date_expire' => '20191001',
|
'date_expire' => '20191001',
|
||||||
];
|
];
|
||||||
$api->post('/capi/warranties', $params);
|
$api->post('/capi/warranties', $params);
|
||||||
|
*/
|
||||||
|
|
||||||
|
// get all warranties
|
||||||
|
$api->get('/capi/warranties');
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
// warranty find
|
// warranty find
|
||||||
$api->get('/capi/warranties/' . $serial);
|
$api->get('/capi/warranties/' . $serial);
|
||||||
|
|
@ -62,6 +69,7 @@ class TestCommand extends Command
|
||||||
|
|
||||||
// plate warranty
|
// plate warranty
|
||||||
$api->get('/capi/plates/' . $plate_num . '/warranties');
|
$api->get('/capi/plates/' . $plate_num . '/warranties');
|
||||||
|
*/
|
||||||
|
|
||||||
// battery
|
// battery
|
||||||
// $api->get('/capi/battery_models');
|
// $api->get('/capi/battery_models');
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,12 @@ capi_warranty_claim:
|
||||||
controller: App\Controller\CAPI\WarrantyController::claim
|
controller: App\Controller\CAPI\WarrantyController::claim
|
||||||
methods: [POST]
|
methods: [POST]
|
||||||
|
|
||||||
|
# get warranties
|
||||||
|
capi_warranty_get_all:
|
||||||
|
path: /capi/warranties
|
||||||
|
controller: App\Controller\CAPI\WarrantyController::getAll
|
||||||
|
methods: [GET]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# customer vehicle api
|
# customer vehicle api
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,45 @@ class WarrantyController extends APIController
|
||||||
return new APIResponse(true, 'Warranty found.', $data);
|
return new APIResponse(true, 'Warranty found.', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAll(Request $req, EntityManagerInterface $em)
|
||||||
|
{
|
||||||
|
error_log('HERE - getAll');
|
||||||
|
|
||||||
|
|
||||||
|
$order = $req->query->get('order');
|
||||||
|
if ($order == null)
|
||||||
|
$order = 'ASC';
|
||||||
|
|
||||||
|
$max = $req->query->get('limit');
|
||||||
|
if ($max == null)
|
||||||
|
$max = 20;
|
||||||
|
|
||||||
|
$start = $req->query->get('start');
|
||||||
|
if ($start == null)
|
||||||
|
$start = 0;
|
||||||
|
|
||||||
|
$qb = $em->createQueryBuilder();
|
||||||
|
|
||||||
|
$query = $qb->select('w')
|
||||||
|
->from('App\\Entity\\Warranty', 'w')
|
||||||
|
->orderBy('w.serial', $order)
|
||||||
|
->setFirstResult($start)
|
||||||
|
->setMaxResults($max)
|
||||||
|
->getQuery();
|
||||||
|
|
||||||
|
$warrs = $query->getResult();
|
||||||
|
|
||||||
|
$warr_data = [];
|
||||||
|
foreach ($warrs as $warr)
|
||||||
|
$warr_data[] = $this->generateWarrantyData($warr);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'warranties' => $warr_data,
|
||||||
|
];
|
||||||
|
|
||||||
|
return new APIResponse(true, 'Warranties found.', $data);
|
||||||
|
}
|
||||||
|
|
||||||
public function register(Request $req, EntityManagerInterface $em)
|
public function register(Request $req, EntityManagerInterface $em)
|
||||||
{
|
{
|
||||||
// required parameters
|
// required parameters
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue