Resolve "New rider api call to return customer hash" #1563

Merged
korina.cordero merged 22 commits from 640-new-rider-api-call-to-return-customer-hash into master-fix 2021-12-03 05:56:58 +00:00
15 changed files with 1165 additions and 769 deletions

View file

@ -2,18 +2,30 @@
"type": "project",
"license": "proprietary",
"repositories": [
{ "type": "vcs", "url": "git@gitlab.com:jankstudio-catalyst/auth-bundle.git" },
{ "type": "vcs", "url": "git@gitlab.com:jankstudio-catalyst/menu-bundle.git" }
{
"type": "vcs",
"url": "git@gitlab.com:jankstudio-catalyst/auth-bundle.git"
},
{
"type": "vcs",
"url": "git@gitlab.com:jankstudio-catalyst/menu-bundle.git"
}
],
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"catalyst/auth-bundle": "dev-master",
"catalyst/menu-bundle": "dev-master",
"composer/package-versions-deprecated": "1.11.99.4",
"creof/doctrine2-spatial": "^1.2",
"data-dog/audit-bundle": "^0.1.10",
"doctrine/common": "^2",
"doctrine/doctrine-bundle": "^2",
"doctrine/doctrine-migrations-bundle": "^2",
"doctrine/orm": "^2",
"edwinhoksberg/php-fcm": "^1.0",
"guzzlehttp/guzzle": "^6.3",
"hashids/hashids": "^4.1",
"microsoft/azure-storage-blob": "^1.5",
"predis/predis": "^1.1",
"sensio/framework-extra-bundle": "^5.1",
@ -26,9 +38,7 @@
"symfony/framework-bundle": "^4.0",
"symfony/maker-bundle": "^1.0",
"symfony/monolog-bundle": "^3.7",
"symfony/orm-pack": "^1.0",
"symfony/process": "^4.0",
"symfony/profiler-pack": "^1.0",
"symfony/security-bundle": "^4.0",
"symfony/translation": "^4.0",
"symfony/twig-bundle": "^4.0",
@ -38,7 +48,9 @@
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0",
"symfony/dotenv": "^4.0",
"symfony/thanks": "^1.0"
"symfony/stopwatch": "^4.0",
"symfony/thanks": "^1.0",
"symfony/web-profiler-bundle": "^4.0"
},
"config": {
"preferred-install": {

1631
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -216,6 +216,11 @@ api_latest_job_order:
controller: App\Controller\APIController::getLatestJobOrder
methods: [GET]
api_customer_hash_get:
path: /api/customer_hash
controller: App\Controller\APIController::getCustomerHash
methods: [GET]
#api_completed_job_orders:
# path: /api/job_orders/completed
# controller: App\Controller\APIController::getCompletedJobOrders

View file

@ -94,4 +94,3 @@ capi_rider_jo_start:
path: /rider_api/start
controller: App\Controller\CAPI\RiderAppController::startJobOrder
methods: [POST]

View file

@ -0,0 +1,44 @@
<?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use App\Service\HashGenerator;
class TestHashGeneratorCommand extends Command
{
protected $hash;
protected function configure()
{
$this->setName('test:hash')
->setDescription('Test hash generator.')
->setHelp('Test hash generator service.');
}
public function __construct(HashGenerator $hash)
{
$this->hash = $hash;
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$orig_id = 39095;
error_log('original id - ' . $orig_id);
$hash_id = $this->hash->getHash($orig_id);
error_log('hash id - ' . $hash_id);
$id = $this->hash->getID($hash_id);
error_log('id - ' . $id);
return 0;
}
}

View file

@ -0,0 +1,135 @@
<?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\ORM\EntityManagerInterface;
use App\Service\MQTTClient;
use App\Entity\JobOrder;
use App\Entity\Rider;
use PDO;
class UpdateUnacceptedJobOrdersCommand extends Command
{
protected $em;
protected $mclient;
public function __construct(EntityManagerInterface $em, MQTTClient $mclient)
{
$this->em = $em;
$this->mclient = $mclient;
parent::__construct();
}
protected function configure()
{
$this->setName('joborder:reassignunaccepted')
->setDescription('Requeue for rider assignment assigned but unaccepted job orders that have been assigned for more than 3 mins.')
->setHelp('Requeue for rider assignment assigned but unaccepted job orders that have been assigned for more than 3 mins.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->em;
$mclient = $this->mclient;
// TODO: get the timeout limit from .env
$timeout = 3;
$current_status = 'assigned';
$new_status = 'rider_assign';
// pdo connection
$db = $em->getConnection();
// since we need the actual job orders for mqtt events, we need to get the ids of the job orders
// that will be updated
// need rider id to set rider to available since rider becomes unavailable
// the minute JO is assigned to rider
$query_sql = 'SELECT id FROM job_order WHERE status = :current_status and TIMESTAMPDIFF(MINUTE, date_assign, NOW()) >= :timeout';
$query_stmt = $db->prepare($query_sql);
$query_stmt->execute([
'current_status' => $current_status,
'timeout' => $timeout,
]);
// go through rows
$requeued_jos = [];
while ($row = $query_stmt->fetch(PDO::FETCH_NUM))
{
// $row[0] is the jo id
// store the jos for now for the event sending after update of JOs
// and the updating of rider's availability
$jo_id = $row[0];
$requeued_jo = $em->getRepository(JobOrder::class)->find($jo_id);
$requeued_jos[] = [
'jo' => $requeued_jo,
];
$update_sql = 'UPDATE job_order SET status = :new_status, rider_id = null WHERE id = :jo_id';
$update_stmt = $db->prepare($update_sql);
$update_stmt->execute([
'new_status' => $new_status,
'jo_id' => $jo_id,
]);
}
foreach ($requeued_jos as $jo_info)
{
$jo = $jo_info['jo'];
if ($jo != null)
{
// $output->writeln('Requeuing for rider assignment ' . $jo->getID());
$id = $jo->getID();
// send notifications to rider app, telling rider that jo has been requeued
$rider_payload = [
'event' => 'cancelled',
'reason' => 'Reassigned',
'jo_id' => $id,
];
$mclient->sendRiderEvent($jo, $rider_payload);
// send outlet assign since order should go back to hub and await reassignment to another rider
$payload = [
'event' => 'outlet_assign',
'jo_id' => $id,
];
$mclient->sendEvent($jo, $payload);
}
$rider = $jo->getRider();
if ($rider != null)
{
// check rider's current job order before changing rider's availability
// since rider's current job order is set when JO is assigned to rider
if ($rider->getCurrentJobOrder() != null)
{
if ($rider->getCurrentJobOrder()->getID() == $jo->getID())
{
// reset rider's availability to true
$rider->setAvailable(true);
// set rider's current job order to null
$rider->setCurrentJobOrder();
}
}
}
}
$em->flush();
return 0;
}
}

View file

@ -47,6 +47,7 @@ use App\Service\HubSelector;
use App\Service\HubDistributor;
use App\Service\HubFilterLogger;
use App\Service\HubFilteringGeoChecker;
use App\Service\HashGenerator;
use App\Entity\MobileSession;
use App\Entity\Customer;
@ -3032,6 +3033,9 @@ class APIController extends Controller implements LoggedController
$jo->setStatusAutoAssign(AutoAssignStatus::HUB_AND_RIDER_ASSIGNED);
$jo->setDeliveryStatus(DeliveryStatus::RIDER_ASSIGN);
// set date_assigned for job order
$jo->setDateAssign(new DateTime());
$assigned_rider->setAvailable(false);
// set rider's current job order
@ -3274,7 +3278,7 @@ class APIController extends Controller implements LoggedController
$schedule_choice = true;
// TODO: remove the time check after ECQ. This will then always return true
// remove the time check after ECQ. This will then always return true
// get current time
$current_datetime = new DateTime();
//$current_datetime = DateTime::createFromFormat('Y-m-d H:i', '2020-04-30 17:01');
@ -3282,8 +3286,10 @@ class APIController extends Controller implements LoggedController
// get the hour
$hour = $current_datetime->format('G');
if (($hour < 8) || ($hour > 16))
$schedule_choice = false;
// commenting out the time check since we can now book 24/7
// this will get uncommented out if and when ECQ will kick in
//if (($hour < 8) || ($hour > 16))
// $schedule_choice = false;
// add checking if customer has a pre-registered hub
$cust = $this->session->getCustomer();
@ -3305,6 +3311,9 @@ class APIController extends Controller implements LoggedController
}
}
// schedule_choice will always be true aka customer can opt to
// Book Now or Schedule Order EXCEPT if customer has customer tag promo
// or ECQ comes back
$data = [
'display_schedule_choice' => $schedule_choice,
];
@ -3840,6 +3849,35 @@ class APIController extends Controller implements LoggedController
return $res->getReturnResponse();
}
public function getCustomerHash(Request $req, EntityManagerInterface $em, HashGenerator $hash)
{
// check required parameters and api key
$res = $this->checkParamsAndKey($req, $em, []);
if ($res->isError())
return $res->getReturnResponse();
// get customer
$cust = $this->session->getCustomer();
if ($cust == null)
{
$res->setError(true)
->setErrorMessage('No customer information found');
return $res->getReturnResponse();
}
// hash customer id
$hashed_id = $hash->getHash($cust->getID());
$data = [
'cust_hash' => $hashed_id,
];
$res->setData($data);
// response
return $res->getReturnResponse();
}
// commenting it out. Modify the getJOHistory instead to just get the fulfilled
// and cancelled job orders, since ongoing is not yet part of history
/*

View file

@ -451,7 +451,8 @@ class RiderAppController extends APIController
$msg = $this->checkJO($req, $required_params, $jo, $rider);
if (!empty($msg))
return new APIResponse(false, $msg);
// TODO: this is a workaround for requeue, because rider app gets stuck in accept / decline screen
return new APIResponse(true, $msg);
// requeue it, instead of cancelling it
$jo->requeue();

View file

@ -565,6 +565,8 @@ class RiderController extends Controller
public function riderActiveJO(EntityManagerInterface $em, MQTTClient $mclient, Rider $rider, $jo_id)
{
$jo = $em->getRepository(JobOrder::class)->find($jo_id);
// TODO: change this to setCurrentJobOrder since this is what is being used to set rider's
// job order. It is no longer using setActiveJobOrder.
$rider->setActiveJobOrder($jo);
$em->flush();

View file

@ -21,7 +21,8 @@ use App\Ramcar\WillingToWaitContent;
* @ORM\Index(name="plate_number_idx", columns={"plate_number"}),
* @ORM\Index(name="first_name_idx", columns={"first_name"}),
* @ORM\Index(name="last_name_idx", columns={"last_name"}),
* @ORM\Index(name="phone_mobile_idx", columns={"phone_mobile"})
* @ORM\Index(name="phone_mobile_idx", columns={"phone_mobile"}),
* @ORM\Index(name="status_idx", columns={"status"}),
* })
*/
class JobOrder

View file

@ -0,0 +1,28 @@
<?php
namespace App\Service;
use Hashids\Hashids;
class HashGenerator
{
// TODO: set in env file and set in constructor
protected $salt = 'salt that should be in the env file 230498';
protected $length = 15;
public function getHash($id)
{
$hi = new Hashids($this->salt, $this->length);
return $hi->encode($id);
}
public function getID($hash)
{
$hi = new Hashids($this->salt, $this->length);
$id_array = $hi->decode($hash);
// first one should be the id
return $id_array[0];
}
}

View file

@ -35,8 +35,8 @@ class MQTTClient
public function sendEvent(JobOrder $job_order, $payload)
{
error_log('sending mqtt event: ');
error_log(print_r($payload, true));
//error_log('sending mqtt event: ');
//error_log(print_r($payload, true));
$sessions = $job_order->getCustomer()->getMobileSessions();
if (count($sessions) == 0)

View file

@ -50,6 +50,8 @@ class ResqRiderAssignmentHandler implements RiderAssignmentHandlerInterface
// send push notification
$this->aclient->sendPush($obj, "A RESQ rider is on his way to you.");
$this->em->flush();
}
}

View file

@ -110,6 +110,9 @@
"guzzlehttp/psr7": {
"version": "1.4.2"
},
"hashids/hashids": {
"version": "4.1.0"
},
"jdorn/sql-formatter": {
"version": "v1.2.17"
},
@ -269,9 +272,6 @@
"config/packages/test/monolog.yaml"
]
},
"symfony/orm-pack": {
"version": "v1.0.5"
},
"symfony/polyfill-ctype": {
"version": "v1.9.0"
},
@ -290,9 +290,6 @@
"symfony/process": {
"version": "v4.4.9"
},
"symfony/profiler-pack": {
"version": "v1.0.3"
},
"symfony/property-access": {
"version": "v4.0.2"
},

View file

@ -0,0 +1 @@
UPDATE job_order SET date_assign = date_create WHERE date_assign is null;