Add support for warranty registration via capi #540
This commit is contained in:
parent
9f00d8ded7
commit
f08d7e03aa
3 changed files with 88 additions and 3 deletions
|
|
@ -155,3 +155,9 @@ capi_cwarr_check:
|
|||
path: /capi/customer_warranty/{serial}
|
||||
controller: App\Controller\CAPI\CustomerWarrantyController::check
|
||||
methods: [GET]
|
||||
|
||||
capi_cwarr_register:
|
||||
path: /capi/customer_warranty/{serial}
|
||||
controller: App\Controller\CAPI\CustomerWarrantyController::register
|
||||
methods: [POST]
|
||||
|
||||
|
|
|
|||
|
|
@ -2954,8 +2954,6 @@ class APIController extends Controller implements LoggedController
|
|||
}
|
||||
}
|
||||
|
||||
error_log('HERE');
|
||||
|
||||
// move file
|
||||
$filename = $name . '.' . $file->getClientOriginalExtension();
|
||||
$file->move($target_dir . '/' . $serial, $filename);
|
||||
|
|
@ -2992,7 +2990,7 @@ class APIController extends Controller implements LoggedController
|
|||
return $res->getReturnResponse();
|
||||
|
||||
// update customer information
|
||||
$cust = $this->updateCustomerInfo($req, $em);
|
||||
// $cust = $this->updateCustomerInfo($req, $em);
|
||||
|
||||
// update warranty
|
||||
$res = $this->updateWarranty($res, $em, $req, $serial, $inv_filename, $wcard_filename);
|
||||
|
|
|
|||
|
|
@ -205,4 +205,85 @@ class CustomerWarrantyController extends APIController
|
|||
return new APIResponse(true, 'Warranty found.', $data);
|
||||
}
|
||||
|
||||
|
||||
public function register($serial, EntityManagerInterface $em, Request $req)
|
||||
{
|
||||
// check required parameters
|
||||
$required_params = [
|
||||
'first_name',
|
||||
'last_name',
|
||||
'plate_num'
|
||||
];
|
||||
$res = $this->checkRequiredParams($req, $required_params);
|
||||
if (!$res)
|
||||
return $res;
|
||||
|
||||
|
||||
$first_name = $req->request->get('first_name');
|
||||
$last_name = $req->request->get('last_name');
|
||||
$email = $req->request->get('email');
|
||||
$plate_num = $req->request->get('plate_num');
|
||||
$odometer = $req->request->get('odometer');
|
||||
$date_purchase = $req->request->get('date_purchase');
|
||||
|
||||
// file uploads
|
||||
$invoice = $req->files->get('invoice');
|
||||
$warr_card = $req->files->get('warr_card');
|
||||
|
||||
// process picture uploads
|
||||
$upload_dir = $kernel->getProjectDir() . '/public/warranty_uploads';
|
||||
$inv_filename = $this->handlePictureUpload($invoice, $upload_dir, $serial, 'invoice');
|
||||
$wcard_filename = $this->handlePictureUpload($warr_card, $upload_dir, $serial, 'wcard');
|
||||
|
||||
|
||||
$data = [
|
||||
'first_name' => $first_name,
|
||||
'last_name' => $last_name,
|
||||
'email' => $email,
|
||||
'plate_num' => $plate_num,
|
||||
'odometer' => $odometer,
|
||||
'date_purchase' => $date_purchase,
|
||||
];
|
||||
|
||||
error_log(print_r($data, true));
|
||||
|
||||
// do actual registering
|
||||
|
||||
|
||||
$data = [];
|
||||
|
||||
return new APIResponse(true, 'Warranty registered.', $data);
|
||||
}
|
||||
|
||||
// TODO: move this to a service, since it's shared by all warranty updaters
|
||||
protected function handlePictureUpload($file, $target_dir, $serial, $name)
|
||||
{
|
||||
error_log("handling $name upload");
|
||||
// no file sent
|
||||
if ($file == null)
|
||||
{
|
||||
error_log('no file');
|
||||
return null;
|
||||
}
|
||||
|
||||
// create target dir if it doesn't exist
|
||||
if (!file_exists($target_dir))
|
||||
{
|
||||
if (!mkdir($target_dir, 0744, true))
|
||||
{
|
||||
error_log('failed to create folder for warranty pictures');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// move file
|
||||
$filename = $name . '.' . $file->getClientOriginalExtension();
|
||||
$file->move($target_dir . '/' . $serial, $filename);
|
||||
|
||||
error_log("filename - $filename");
|
||||
error_log($target_dir . '/' . $serial . '/' . $filename);
|
||||
|
||||
return $serial . '/' . $filename;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue