Merge branch '333-rider-assignment-handler-for-resq' into '329-transition-branch-for-cmb-and-resq-merging'
Add rider assignment handler for resq. #333 See merge request jankstudio/resq!373
This commit is contained in:
commit
d62a36b6db
5 changed files with 94 additions and 27 deletions
|
|
@ -179,6 +179,12 @@ services:
|
|||
# customer generator interface
|
||||
App\Service\CustomerHandlerInterface: "@App\\Service\\CustomerHandler\\ResqCustomerHandler"
|
||||
|
||||
# rider assignment
|
||||
App\Service\RiderAssignmentHandler\ResqRiderAssignmentHandler: ~
|
||||
|
||||
# rider assignment interface
|
||||
App\Service\RiderAssignmentHandlerInterface: "@App\\Service\\RiderAssignmentHandler\\ResqRiderAssignmentHandler"
|
||||
|
||||
# map manager
|
||||
#App\Service\GISManager\Bing: ~
|
||||
App\Service\GISManager\OpenStreet: ~
|
||||
|
|
|
|||
|
|
@ -731,7 +731,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
|||
}
|
||||
|
||||
// assign job order
|
||||
public function assignJobOrder(Request $req, $id, MQTTCLient $mclient, APNSClient $aclient)
|
||||
public function assignJobOrder(Request $req, $id)
|
||||
{
|
||||
// get object data
|
||||
$em = $this->em;
|
||||
|
|
@ -827,7 +827,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface
|
|||
}
|
||||
|
||||
// fulfill job order
|
||||
public function fulfillJobOrder(Request $req, $id, MQTTClient $mclient)
|
||||
public function fulfillJobOrder(Request $req, $id)
|
||||
{
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ use App\Entity\Hub;
|
|||
use App\Entity\Promo;
|
||||
use App\Entity\Rider;
|
||||
use App\Entity\JORejection;
|
||||
use App\Entity\Warranty;
|
||||
|
||||
use App\Ramcar\InvoiceCriteria;
|
||||
use App\Ramcar\ServiceType;
|
||||
|
|
@ -38,6 +39,7 @@ use App\Ramcar\JORejectionReason;
|
|||
|
||||
use App\Service\InvoiceGeneratorInterface;
|
||||
use App\Service\JobOrderHandlerInterface;
|
||||
use App\Service\RiderAssignmentHandlerInterface;
|
||||
use App\Service\WarrantyHandler;
|
||||
use App\Service\MQTTClient;
|
||||
use App\Service\APNSClient;
|
||||
|
|
@ -59,6 +61,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
protected $security;
|
||||
protected $validator;
|
||||
protected $translator;
|
||||
protected $rah;
|
||||
protected $country_code;
|
||||
protected $wh;
|
||||
|
||||
|
|
@ -66,14 +69,15 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
|
||||
public function __construct(Security $security, EntityManagerInterface $em,
|
||||
InvoiceGeneratorInterface $ic, ValidatorInterface $validator,
|
||||
TranslatorInterface $translator, string $country_code,
|
||||
WarrantyHandler $wh)
|
||||
TranslatorInterface $translator, RiderAssignmentHandlerInterface $rah,
|
||||
string $country_code, WarrantyHandler $wh)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->ic = $ic;
|
||||
$this->security = $security;
|
||||
$this->validator = $validator;
|
||||
$this->translator = $translator;
|
||||
$this->rah = $rah;
|
||||
$this->country_code = $country_code;
|
||||
$this->wh = $wh;
|
||||
|
||||
|
|
@ -515,7 +519,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
}
|
||||
|
||||
// assign job order
|
||||
public function assignJobOrder(Request $req, $id, MQTTCLient $mclient, APNSClient $aclient)
|
||||
public function assignJobOrder(Request $req, $id)
|
||||
{
|
||||
// get object data
|
||||
$em = $this->em;
|
||||
|
|
@ -606,22 +610,15 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
// validated! save the entity
|
||||
$em->flush();
|
||||
|
||||
// send event to mobile app
|
||||
$payload = [
|
||||
'event' => 'driver_assigned'
|
||||
];
|
||||
$mclient->sendEvent($obj, $payload);
|
||||
$mclient->sendRiderEvent($obj, $payload);
|
||||
|
||||
// sned push notification
|
||||
$aclient->sendPush($obj, "A RESQ rider is on his way to you.");
|
||||
// call rider assignment handler's assignJobOrder
|
||||
$this->rah->assignJobOrder($obj, $rider);
|
||||
}
|
||||
|
||||
return $error_array;
|
||||
}
|
||||
|
||||
// fulfill job order
|
||||
public function fulfillJobOrder(Request $req, $id, MQTTClient $mclient)
|
||||
public function fulfillJobOrder(Request $req, $id)
|
||||
{
|
||||
// initialize error list
|
||||
$error_array = [];
|
||||
|
|
@ -697,16 +694,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
|||
if ($rider->getImageFile() != null)
|
||||
$image_url = $req->getScheme() . '://' . $req->getHttpHost() . $req->getBasePath() . '/uploads/' . $rider->getImageFile();
|
||||
|
||||
// send to mqtt
|
||||
$payload = [
|
||||
'event' => 'fulfilled',
|
||||
'jo_id' => $obj->getID(),
|
||||
'driver_image' => $image_url,
|
||||
'driver_name' => $rider->getFullName(),
|
||||
'driver_id' => $rider->getID(),
|
||||
];
|
||||
$mclient->sendEvent($obj, $payload);
|
||||
$mclient->sendRiderEvent($obj, $payload);
|
||||
// call rider assignment handler's fulfillJobOrder
|
||||
$this->rah->fulfillJobOrder($obj, $image_url, $rider);
|
||||
|
||||
// create the warranty if new battery only
|
||||
if ($obj->getServiceType () == ServiceType::BATTERY_REPLACEMENT_NEW)
|
||||
|
|
|
|||
|
|
@ -31,10 +31,10 @@ interface JobOrderHandlerInterface
|
|||
public function dispatchJobOrder(Request $req, int $id, MQTTClient $mclient);
|
||||
|
||||
// assign job order
|
||||
public function assignJobOrder(Request $req, int $id, MQTTCLient $mclient, APNSClient $aclient);
|
||||
public function assignJobOrder(Request $req, int $id);
|
||||
|
||||
// fulfill job order
|
||||
public function fulfillJobOrder(Request $req, int $id, MQTTClient $mclient);
|
||||
public function fulfillJobOrder(Request $req, int $id);
|
||||
|
||||
// cancel job order
|
||||
public function cancelJobOrder(Request $req, int $id, MQTTClient $mclient);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service\RiderAssignmentHandler;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use App\Service\RiderAssignmentHandlerInterface;
|
||||
use App\Service\MQTTClient;
|
||||
use App\Service\APNSClient;
|
||||
|
||||
use App\Entity\JobOrder;
|
||||
use App\Entity\Rider;
|
||||
|
||||
use App\Ramcar\JOStatus;
|
||||
|
||||
class ResqRiderAssignmentHandler implements RiderAssignmentHandlerInterface
|
||||
{
|
||||
protected $em;
|
||||
protected $aclient;
|
||||
protected $mclient;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, MQTTClient $mclient,
|
||||
APNSClient $aclient)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->mclient = $mclient;
|
||||
$this->aclient = $aclient;
|
||||
}
|
||||
|
||||
// assign job order to rider
|
||||
public function assignJobOrder(JobOrder $obj, Rider $rider)
|
||||
{
|
||||
// create the payload
|
||||
$payload = [
|
||||
'event' => 'driver_assigned'
|
||||
];
|
||||
|
||||
// send event
|
||||
$this->mclient->sendEvent($obj, $payload);
|
||||
|
||||
// check if rider is available
|
||||
if ($rider->isAvailable())
|
||||
{
|
||||
error_log('set rider availability to false');
|
||||
// set rider to unavailable
|
||||
$rider->setAvailable(false);
|
||||
|
||||
// send event to rider
|
||||
$this->mclient->sendRiderEvent($obj, $payload);
|
||||
|
||||
// send push notification
|
||||
$this->aclient->sendPush($obj, "A RESQ rider is on his way to you.");
|
||||
}
|
||||
}
|
||||
|
||||
// complete job order
|
||||
public function fulfillJobOrder(JobOrder $obj, string $image_url, Rider $rider)
|
||||
{
|
||||
// send to mqtt
|
||||
$payload = [
|
||||
'event' => 'fulfilled',
|
||||
'jo_id' => $obj->getID(),
|
||||
'driver_image' => $image_url,
|
||||
'driver_name' => $rider->getFullName(),
|
||||
'driver_id' => $rider->getID(),
|
||||
];
|
||||
$this->mclient->sendEvent($obj, $payload);
|
||||
|
||||
// send fulfill/complete event to rider
|
||||
$this->mclient->sendRiderEvent($obj, $payload);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue