Add uploadArrivePhotos API call. #421
This commit is contained in:
parent
8f108c18cb
commit
ce64a1b64d
5 changed files with 277 additions and 1 deletions
|
|
@ -119,3 +119,13 @@ cmb_rapi_jo_odometer:
|
|||
path: /cmbrapi/odometer
|
||||
controller: App\Controller\CMBRAPIController::setOdometer
|
||||
methods: [POST]
|
||||
|
||||
cmb_rapi_jo_arrive_photos_upload:
|
||||
path: /cmbrapi/uploadarrivephotos
|
||||
controller: App\Controller\CMBRAPIController::uploadArrivePhotos
|
||||
methods: [POST]
|
||||
|
||||
cmb_rapi_jo_finish_photos_upload:
|
||||
path: /cmbrapi/uploadfinishphotos
|
||||
controller: App\Controller\CMBRAPIController::uploadFinishPhotos
|
||||
methods: [POST]
|
||||
|
|
|
|||
|
|
@ -547,5 +547,50 @@ class CMBRAPIController extends Controller
|
|||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function uploadArrivePhotos(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
||||
{
|
||||
$res = new APIResult();
|
||||
|
||||
$data = $rapi_handler->uploadArrivePhotos($req);
|
||||
|
||||
if (isset($data['error']))
|
||||
{
|
||||
$message = $data['error'];
|
||||
|
||||
$res->setError(true)
|
||||
->setErrorMessage($message);
|
||||
}
|
||||
else
|
||||
{
|
||||
$res->setData($data);
|
||||
}
|
||||
|
||||
// response
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
public function uploadFinishPhotos(Request $req, RiderAPIHandlerInterface $rapi_handler)
|
||||
{
|
||||
$res = new APIResult();
|
||||
|
||||
$data = $rapi_handler->uploadFinishPhotos($req);
|
||||
|
||||
if (isset($data['error']))
|
||||
{
|
||||
$message = $data['error'];
|
||||
|
||||
$res->setError(true)
|
||||
->setErrorMessage($message);
|
||||
}
|
||||
else
|
||||
{
|
||||
$res->setData($data);
|
||||
}
|
||||
|
||||
// response
|
||||
return $res->getReturnResponse();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
122
src/Entity/JOExtra.php
Normal file
122
src/Entity/JOExtra.php
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Table(name="jo_extra")
|
||||
*/
|
||||
class JOExtra
|
||||
{
|
||||
// unique id
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", nullable=true)
|
||||
*/
|
||||
protected $before_speed_image_filename;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", nullable=true)
|
||||
*/
|
||||
protected $before_plate_num_image_filename;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", nullable=true)
|
||||
*/
|
||||
protected $before_batt_image_filename;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", nullable=true)
|
||||
*/
|
||||
protected $after_speed_image_filename;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", nullable=true)
|
||||
*/
|
||||
protected $after_plate_num_image_filename;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", nullable=true)
|
||||
*/
|
||||
protected $after_batt_image_filename;
|
||||
|
||||
public function getID()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setBeforeSpeedImageFilename($image_filename)
|
||||
{
|
||||
$this->before_speed_image_filename = $image_filename;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBeforeSpeedImageFilename($image_filename)
|
||||
{
|
||||
return $this->before_speed_image_filename;
|
||||
}
|
||||
|
||||
public function setBeforePlateNumImageFilename($image_filename)
|
||||
{
|
||||
$this->before_plate_num_image_filename = $image_filename;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBeforePlateNumImageFilename($image_filename)
|
||||
{
|
||||
return $this->before_plate_num_image_filename;
|
||||
}
|
||||
|
||||
public function setBeforeBattImageFilename($image_filename)
|
||||
{
|
||||
$this->before_batt_image_filename = $image_filename;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBeforeBattImageFilename($image_filename)
|
||||
{
|
||||
return $this->before_batt_image_filename;
|
||||
}
|
||||
public function setAfterSpeedImageFilename($image_filename)
|
||||
{
|
||||
$this->after_speed_image_filename = $image_filename;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAfterSpeedImageFilename($image_filename)
|
||||
{
|
||||
return $this->after_speed_image_filename;
|
||||
}
|
||||
|
||||
public function setAfterPlateNumImageFilename($image_filename)
|
||||
{
|
||||
$this->after_plate_num_image_filename = $image_filename;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAfterPlateNumImageFilename($image_filename)
|
||||
{
|
||||
return $this->after_plate_num_image_filename;
|
||||
}
|
||||
|
||||
public function setAfterBattImageFilename($image_filename)
|
||||
{
|
||||
$this->after_batt_image_filename = $image_filename;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAfterBattImageFilename($image_filename)
|
||||
{
|
||||
return $this->after_batt_image_filename;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -334,6 +334,12 @@ class JobOrder
|
|||
*/
|
||||
protected $phone_mobile;
|
||||
|
||||
// link to JOExtra
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="JOExtra")
|
||||
*/
|
||||
protected $jo_extra;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date_create = new DateTime();
|
||||
|
|
@ -962,5 +968,15 @@ class JobOrder
|
|||
return $this->phone_mobile;
|
||||
}
|
||||
|
||||
public function setJOExtra(JOExtra $jo_extra)
|
||||
{
|
||||
$this->jo_extra = $jo_extra;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getJOExtra()
|
||||
{
|
||||
return $this->jo_extra;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ use App\Entity\Battery;
|
|||
use App\Entity\BatteryModel;
|
||||
use App\Entity\BatterySize;
|
||||
use App\Entity\JobOrder;
|
||||
use App\Entity\JOExtra;
|
||||
|
||||
use DateTime;
|
||||
use DateInterval;
|
||||
|
|
@ -49,12 +50,13 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
protected $jo_handler;
|
||||
protected $ic;
|
||||
protected $session;
|
||||
protected $upload_dir;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, RedisClientProvider $redis,
|
||||
EncoderFactoryInterface $ef, RiderCache $rcache,
|
||||
string $country_code, MQTTClient $mclient,
|
||||
WarrantyHandler $wh, JobOrderHandlerInterface $jo_handler,
|
||||
InvoiceGeneratorInterface $ic)
|
||||
InvoiceGeneratorInterface $ic, string $upload_dir)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->redis = $redis;
|
||||
|
|
@ -65,6 +67,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
$this->wh = $wh;
|
||||
$this->jo_handler = $jo_handler;
|
||||
$this->ic = $ic;
|
||||
$this->upload_dir = $upload_dir;
|
||||
|
||||
// one device = one session, since we have control over the devices
|
||||
// when a rider logs in, we just change the rider assigned to the device
|
||||
|
|
@ -1313,6 +1316,86 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface
|
|||
return $data;
|
||||
}
|
||||
|
||||
public function uploadArrivePhotos(Request $req)
|
||||
{
|
||||
$required_params = [
|
||||
'jo_id',
|
||||
];
|
||||
$data = $this->checkActiveJO($req, $required_params, $jo);
|
||||
if (isset($data['error']))
|
||||
return $data;
|
||||
|
||||
$dest = $this->upload_dir;
|
||||
|
||||
$speed_img_file = $req->files->get('speedomtr_img');
|
||||
$batt_img_file = $req->files->get('battery_img');
|
||||
$plate_num_img_file = $req->files->get('plate_number_img');
|
||||
|
||||
if ((empty($speed_img_file)) &&
|
||||
(empty($batt_img_file)) &&
|
||||
(empty($plate_num_img_file)))
|
||||
{
|
||||
$data = [
|
||||
'error' => 'No image files received.'
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
// save speedometer file
|
||||
$orig_speed_filename = pathinfo($speed_img_file->getClientOriginalName(), PATHINFO_FILENAME);
|
||||
$new_speed_filename = uniqid() . '-'. $orig_speed_filename . '.' . $speed_img_file->guessClientExtension();
|
||||
|
||||
// save battery file
|
||||
$orig_batt_filename = pathinfo($batt_img_file->getClientOriginalName(), PATHINFO_FILENAME);
|
||||
$new_batt_filename = uniqid() . '-' . $orig_batt_filename . '.' . $batt_img_file->guessClientExtension();
|
||||
|
||||
// save plate number file
|
||||
$orig_plate_num_filename = pathinfo($plate_num_img_file->getClientOriginalName(), PATHINFO_FILENAME);
|
||||
$new_plate_num_filename = uniqid() . '-' . $orig_plate_num_filename . '.' . $plate_num_img_file->guessClientExtension();
|
||||
|
||||
try
|
||||
{
|
||||
$speed_img_file->move($dest, $new_speed_filename);
|
||||
$batt_img_file->move($dest, $new_batt_filename);
|
||||
$plate_num_img_file->move($dest, $new_plate_num_filename);
|
||||
}
|
||||
catch (FileException $e)
|
||||
{
|
||||
$data = [
|
||||
'error' => 'Error saving image files.'
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
// create JOExtra entity
|
||||
$jo_extra = new JOExtra();
|
||||
|
||||
$jo_extra->setBeforeSpeedImageFilename($new_speed_filename);
|
||||
$jo_extra->setBeforeBattImageFilename($new_batt_filename);
|
||||
$jo_extra->setBeforePlateNumImageFilename($new_plate_num_filename);
|
||||
|
||||
$jo->setJOExtra($jo_extra);
|
||||
|
||||
$this->em->persist($jo_extra);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function uploadFinishPhotos(Request $req)
|
||||
{
|
||||
$required_params = [
|
||||
'jo_id',
|
||||
];
|
||||
$data = $this->checkActiveJO($req, $required_params, $jo);
|
||||
if (isset($data['error']))
|
||||
return $data;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function checkMissingParameters(Request $req, $params = [])
|
||||
{
|
||||
$missing = [];
|
||||
|
|
|
|||
Loading…
Reference in a new issue