Add battery model and size to warranty and change warranty routes #166
This commit is contained in:
parent
2a24567c4c
commit
d78e30c9c2
4 changed files with 74 additions and 7 deletions
|
|
@ -41,20 +41,23 @@ class TestCommand extends Command
|
|||
|
||||
// TODO: shift this out of the bundle, since it's project specific
|
||||
// warranty register
|
||||
$serial = 'AJ34LJADR12134LKJL';
|
||||
$params = [
|
||||
'serial' => 'LJ34LJADR12SDLKJL',
|
||||
'serial' => $serial,
|
||||
'plate_number' => 'XEN918',
|
||||
'warranty_class' => 'private',
|
||||
'battery_model_id' => 438,
|
||||
'battery_size_id' => 1171,
|
||||
'date_purchase' => '20181001',
|
||||
'date_expire' => '20191001',
|
||||
];
|
||||
$api->post('/capi/warranty', $params);
|
||||
$api->post('/capi/warranties', $params);
|
||||
|
||||
// warranty find
|
||||
$api->get('/capi/warranty/LJ34LJADR12SDLKJL');
|
||||
$api->get('/capi/warranties/' . $serial);
|
||||
|
||||
// warranty claim
|
||||
$api->post('/capi/warranty/LJ34LJADR12SDLKJL/claim');
|
||||
$api->post('/capi/warranties/' . $serial . '/claim');
|
||||
|
||||
// battery
|
||||
// $api->get('/capi/battery_models');
|
||||
|
|
|
|||
|
|
@ -36,19 +36,19 @@ capi_vehicle_list:
|
|||
|
||||
# check warranty by serial
|
||||
capi_warranty_find:
|
||||
path: /capi/warranty/{serial}
|
||||
path: /capi/warranties/{serial}
|
||||
controller: App\Controller\CAPI\WarrantyController::find
|
||||
methods: [GET]
|
||||
|
||||
# register battery
|
||||
capi_warranty_register:
|
||||
path: /capi/warranty
|
||||
path: /capi/warranties
|
||||
controller: App\Controller\CAPI\WarrantyController::register
|
||||
methods: [POST]
|
||||
|
||||
# claim warranty
|
||||
capi_warranty_claim:
|
||||
path: /capi/warranty/{serial}/claim
|
||||
path: /capi/warranties/{serial}/claim
|
||||
controller: App\Controller\CAPI\WarrantyController::claim
|
||||
methods: [POST]
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
|||
use Catalyst\APIBundle\Controller\APIController;
|
||||
use Catalyst\APIBundle\Response\APIResponse;
|
||||
use App\Entity\Warranty;
|
||||
use App\Entity\BatteryModel;
|
||||
use App\Entity\BatterySize;
|
||||
use App\Ramcar\NameValue;
|
||||
use App\Ramcar\WarrantyClass;
|
||||
use App\Ramcar\WarrantyStatus;
|
||||
|
|
@ -56,11 +58,21 @@ class WarrantyController extends Controller implements APIController
|
|||
|
||||
protected function generateWarrantyData(Warranty $warr)
|
||||
{
|
||||
$model = $warr->getBatteryModel();
|
||||
$size = $warr->getBatterySize();
|
||||
$data = [
|
||||
'id' => (int) $warr->getID(),
|
||||
'serial' => (string) $warr->getSerial(),
|
||||
'warranty_class' => (string) $warr->getWarrantyClass(),
|
||||
'plate_number' => (string) $warr->getPlateNumber(),
|
||||
'battery_model' => [
|
||||
(int) ($model == null ? 0 : $model->getID()),
|
||||
(string) ($model == null ? '' : $model->getName()),
|
||||
],
|
||||
'battery_size' => [
|
||||
(int) ($size == null ? 0 : $size->getID()),
|
||||
(string) ($size == null ? '' : $size->getName()),
|
||||
],
|
||||
'status' => (string) $warr->getStatus(),
|
||||
'date_create' => (string) $warr->getDateCreate()->format('YmdHis'),
|
||||
'date_purchase' => (string) $warr->getDatePurchase()->format('Ymd'),
|
||||
|
|
@ -101,6 +113,8 @@ class WarrantyController extends Controller implements APIController
|
|||
'plate_number',
|
||||
'date_expire',
|
||||
'date_purchase',
|
||||
'battery_model_id',
|
||||
'battery_size_id',
|
||||
];
|
||||
$msg = $this->checkRequiredParameters($req, $params);
|
||||
error_log('msg - ' . $msg);
|
||||
|
|
@ -112,6 +126,8 @@ class WarrantyController extends Controller implements APIController
|
|||
$date_pur_string = $req->request->get('date_purchase');
|
||||
$warr_class = $req->request->get('warranty_class');
|
||||
$plate = $req->request->get('plate_number');
|
||||
$bmodel_id = $req->request->get('battery_model_id');
|
||||
$bsize_id = $req->request->get('battery_size_id');
|
||||
|
||||
// wrong date expire format
|
||||
$date_expire = DateTime::createFromFormat('Ymd', $date_expire_string);
|
||||
|
|
@ -132,11 +148,23 @@ class WarrantyController extends Controller implements APIController
|
|||
if (!$plate)
|
||||
return new APIResponse(false, 'Invalid plate number.');
|
||||
|
||||
// battery model
|
||||
$model = $em->getRepository(BatteryModel::class)->find($bmodel_id);
|
||||
if ($model == null)
|
||||
return new APIResponse(false, 'Invalid battery model id.');
|
||||
|
||||
// battery size
|
||||
$size = $em->getRepository(BatterySize::class)->find($bsize_id);
|
||||
if ($size == null)
|
||||
return new APIResponse(false, 'Invalid battery size id.');
|
||||
|
||||
// warranty
|
||||
$warr = new Warranty();
|
||||
$warr->setSerial($serial)
|
||||
->setWarrantyClass($warr_class)
|
||||
->setPlateNumber($plate)
|
||||
->setBatteryModel($model)
|
||||
->setBatterySize($size)
|
||||
->setDatePurchase($date_pur)
|
||||
->setDateClaim(null)
|
||||
->setDateExpire($date_expire);
|
||||
|
|
|
|||
|
|
@ -45,6 +45,20 @@ class Warranty
|
|||
*/
|
||||
protected $plate_number;
|
||||
|
||||
// battery model
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="BatteryModel", inversedBy="warranties")
|
||||
* @ORM\JoinColumn(name="bty_model_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $bty_model;
|
||||
|
||||
// battery size
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="BatterySize", inversedBy="warranties")
|
||||
* @ORM\JoinColumn(name="bty_size_id", referencedColumnName="id")
|
||||
*/
|
||||
protected $bty_size;
|
||||
|
||||
// status
|
||||
/**
|
||||
* @ORM\Column(type="string", length=25)
|
||||
|
|
@ -145,6 +159,28 @@ class Warranty
|
|||
return $this->plate_number;
|
||||
}
|
||||
|
||||
public function setBatteryModel(BatteryModel $model)
|
||||
{
|
||||
$this->bty_model = $model;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBatteryModel()
|
||||
{
|
||||
return $this->bty_model;
|
||||
}
|
||||
|
||||
public function setBatterySize(BatterySize $size)
|
||||
{
|
||||
$this->bty_size = $size;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBatterySize()
|
||||
{
|
||||
return $this->bty_size;
|
||||
}
|
||||
|
||||
public function setStatus($status)
|
||||
{
|
||||
$this->status = $status;
|
||||
|
|
|
|||
Loading…
Reference in a new issue