Merge branch '171-add-resq-api-calls-for-pop-up-shop' into 'master'
Resolve "Add Resq API calls for pop up shop" Closes #171 See merge request jankstudio/resq!204
This commit is contained in:
commit
aac2030be0
4 changed files with 115 additions and 7 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
|
||||
$serial = 'AJ34LJADR12134LKJL';
|
||||
|
|
@ -53,15 +54,30 @@ class TestCommand extends Command
|
|||
'date_expire' => '20191001',
|
||||
];
|
||||
$api->post('/capi/warranties', $params);
|
||||
*/
|
||||
|
||||
// get all warranties
|
||||
$api->get('/capi/warranties');
|
||||
|
||||
/*
|
||||
|
||||
// warranty find
|
||||
$api->get('/capi/warranties/' . $serial);
|
||||
*/
|
||||
|
||||
// warranty claim
|
||||
$api->post('/capi/warranties/' . $serial . '/claim');
|
||||
$id = 86811;
|
||||
$serial = 'TEST001';
|
||||
$params = [
|
||||
'serial' => $serial,
|
||||
];
|
||||
$api->post('/capi/warranties/' . $id . '/claim', $params);
|
||||
|
||||
/*
|
||||
|
||||
// plate warranty
|
||||
$api->get('/capi/plates/' . $plate_num . '/warranties');
|
||||
*/
|
||||
|
||||
// battery
|
||||
// $api->get('/capi/battery_models');
|
||||
|
|
|
|||
|
|
@ -56,10 +56,16 @@ capi_warranty_register:
|
|||
|
||||
# claim warranty
|
||||
capi_warranty_claim:
|
||||
path: /capi/warranties/{serial}/claim
|
||||
path: /capi/warranties/{id}/claim
|
||||
controller: App\Controller\CAPI\WarrantyController::claim
|
||||
methods: [POST]
|
||||
|
||||
# get warranties
|
||||
capi_warranty_get_all:
|
||||
path: /capi/warranties
|
||||
controller: App\Controller\CAPI\WarrantyController::getAll
|
||||
methods: [GET]
|
||||
|
||||
|
||||
|
||||
# customer vehicle api
|
||||
|
|
|
|||
|
|
@ -72,6 +72,45 @@ class WarrantyController extends APIController
|
|||
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)
|
||||
{
|
||||
// required parameters
|
||||
|
|
@ -155,23 +194,52 @@ class WarrantyController extends APIController
|
|||
return new APIResponse(true, 'Warranty registered.', $data);
|
||||
}
|
||||
|
||||
public function claim(Request $req, EntityManagerInterface $em, $serial)
|
||||
public function claim(Request $req, EntityManagerInterface $em, $id)
|
||||
{
|
||||
$clean_serial = $this->cleanSerial($serial);
|
||||
$warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $clean_serial]);
|
||||
// required parameters
|
||||
$params = [
|
||||
'serial',
|
||||
];
|
||||
$msg = $this->checkRequiredParameters($req, $params);
|
||||
if ($msg)
|
||||
return new APIResponse(false, $msg);
|
||||
|
||||
// no warranty
|
||||
$warr = $em->getRepository(Warranty::class)->find($id);
|
||||
if ($warr == null)
|
||||
return new APIResponse(false, 'No warranty found with that serial number.', null, 404);
|
||||
return new APIResponse(false, 'No warranty found with that id.', null, 404);
|
||||
|
||||
// warranty is not active
|
||||
if (!$warr->canClaim())
|
||||
return new APIResponse(false, 'Warranty is not active.');
|
||||
|
||||
|
||||
// check if new serial has been used
|
||||
$serial = $req->request->get('serial');
|
||||
$clean_serial = $this->cleanSerial($serial);
|
||||
$check_warr = $em->getRepository(Warranty::class)->findOneBy(['serial' => $clean_serial]);
|
||||
if ($check_warr != null)
|
||||
return new APIResponse(false, 'Serial for replacement has already been used.');
|
||||
|
||||
// set status to claim
|
||||
$warr->setStatus(WarrantyStatus::CLAIMED)
|
||||
->setDateClaim(new DateTime());
|
||||
|
||||
// make replacement warranty
|
||||
$new_warr = new Warranty();
|
||||
$new_warr->setSerial($clean_serial)
|
||||
->setWarrantyClass($warr->getWarrantyClass())
|
||||
->setPlateNumber($warr->getPlateNumber())
|
||||
->setBatteryModel($warr->getBatteryModel())
|
||||
->setBatterySize($warr->getBatterySize())
|
||||
->setDatePurchase($warr->getDatePurchase())
|
||||
->setDateClaim(null)
|
||||
->setDateExpire($warr->getDateExpire())
|
||||
->setClaimedFrom($warr);
|
||||
|
||||
$em->persist($new_warr);
|
||||
|
||||
|
||||
$em->flush();
|
||||
|
||||
// TODO: claim log
|
||||
|
|
|
|||
|
|
@ -89,6 +89,13 @@ class Warranty
|
|||
*/
|
||||
protected $date_claim;
|
||||
|
||||
// claimed from
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="Warranty")
|
||||
* @ORM\JoinColumn(name="claim_id", referencedColumnName="id", nullable=true)
|
||||
*/
|
||||
protected $claim_from;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date_create = new DateTime();
|
||||
|
|
@ -250,8 +257,19 @@ class Warranty
|
|||
return true;
|
||||
|
||||
if ($this->status == WarrantyStatus::CLAIMED)
|
||||
return true;
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function setClaimedFrom($claim_from)
|
||||
{
|
||||
$this->claim_form = $claim_from;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getClaimedFrom()
|
||||
{
|
||||
return $this->claim_from;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue