Merge branch 'master' of gitlab.com:jankstudio/resq into 704-capi-call-for-warranty-serial

Conflicts:
	config/api_acl.yaml
	src/Controller/APIUserController.php
This commit is contained in:
Korina Cordero 2022-09-19 07:14:04 +00:00
commit c42d2973f4
10 changed files with 2272 additions and 7 deletions

View file

@ -74,3 +74,51 @@ access_keys:
acls:
- id: warrantyserial.upload
label: Upload
- id: tapi_vmanufacturer
label: Third Party Vehicle Manufacturer Access
acls:
- id: tapi_vmanufacturer.list
label: List Third Party Vehicle Manufacturers
- id: tapi_vehicle
label: Third Party Vehicle Make Access
acls:
- id: tapi_vehicle.list
label: List Third Party Vehicles
- id: tapi_promo
label: Third Party Promo Access
acls:
- id: tapi_promo.list
label: List Third Party Promos
- id: tapi_battery
label: Third Party Battery Access
acls:
- id: tapi_battery_compatible.list
label: List Third Party Compatible Batteries
- id: tapi_jo
label: Third Party Job Order Access
acls:
- id: tapi_jo.request
label: Third Party Request Job Order
- id: tapi_jo.get.estimate
label: Third Party Get Estimate
- id: tapi_jo.get.ongoing
label: Third Party Get Ongoing Job Order
- id: tapi_jo.cancel
label: Third Party Cancel Job Order
- id: tapi_jo.get.invoice
label: Third Party Get Job Order Invoice
- id: tapi_jo.location.support
label: Third Party Check Location Support
- id: tapi_jo.nearest_hub.get
label: Third Party Get Nearest Hub and Slots
- id: tapi_jo.schedule_option.status
label: Third Party Schedule Option Status
- id: tapi_jo.get.info
label: Third Party Get Job Order Info
- id: tapi_service
label: Third Party Service Access
acls:
- id: tapi_service.list
label: List Third Party Services

View file

@ -59,6 +59,14 @@ security:
provider: api_key_user_provider
user_checker: Catalyst\AuthBundle\Service\UserChecker
third_party_api:
pattern: ^\/tapi\/
stateless: true
simple_preauth:
authenticator: Catalyst\APIBundle\Security\APIKeyAuthenticator
provider: api_key_user_provider
user_checker: Catalyst\AuthBundle\Service\UserChecker
main:
provider: user_provider
form_login:

60
config/routes/tapi.yaml Normal file
View file

@ -0,0 +1,60 @@
# third party api
# job order
tapi_jo_request:
path: /tapi/job_order
controller: App\Controller\TAPI\JobOrderController::requestJobOrder
methods: [POST]
tapi_estimate:
path: /tapi/estimate
controller: App\Controller\TAPI\JobOrderController::getEstimate
methods: [POST]
tapi_jo_invoice:
path: /tapi/job_order/invoice/{jo_id}
controller: App\Controller\TAPI\JobOrderController:getJOInvoice
methods: [GET]
tapi_jo_cancel:
path: /tapi/job_order/cancel
controller: App\Controller\TAPI\JobOrderController:cancelJobOrder
methods: [POST]
tapi_jo_info:
path: /tapi/job_order/{jo_id}/info
controller: App\Controller\TAPI\JobOrderController::getJobOrderInfo
methods: [GET]
tapi_location_support:
path: /tapi/location_support
controller: App\Controller\TAPI\JobOrderController:locationSupport
methods: [POST]
tapi_nearest_hub_slots:
path: /tapi/hub_slots
controller: App\Controller\TAPI\JobOrderController::getNearestHubAndSlots
methods: [POST]
# vehicle manufacturer and vehicle
tapi_vehicle_mfg_list:
path: /tapi/vehicle/mfgs
controller: App\Controller\TAPI\VehicleController::listVehicleManufacturers
methods: [GET]
tapi_vehicle_make_list:
path: /tapi/vehicle/mfgs/{mfg_id}/makes
controller: App\Controller\TAPI\VehicleController::listVehicleMakes
methods: [GET]
# battery
tapi_battery_list:
path: /tapi/vehicles/{vid}/compatible_batteries
controller: App\Controller\TAPI\BatteryController::getCompatibleBatteries
methods: [GET]
# promos
tapi_promo_list:
path: /tapi/promos
controller: App\Controller\TAPI\PromoController::listPromos
methods: [GET]

View file

@ -162,9 +162,15 @@ class APIUserController extends Controller
// set api user in rider
$rider->setAPIUser($obj);
<<<<<<< HEAD
$obj->setRider($rider)
->setMetadata($meta);
}
=======
// set api user in rider
if ($rider != null)
$rider->setAPIUser($obj);
>>>>>>> 7416be842559728bbb3743c0035a6d26605eb1be
// set and save values
$obj->setName($req->request->get('name'))

View file

@ -0,0 +1,93 @@
<?php
namespace App\Controller\TAPI;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\Query;
use Doctrine\ORM\EntityManagerInterface;
use Catalyst\APIBundle\Controller\APIController;
use Catalyst\APIBundle\Response\APIResponse;
use App\Ramcar\APIResult;
use App\Entity\Vehicle;
use Catalyst\APIBundle\Access\Generator as ACLGenerator;
class BatteryController extends APIController
{
protected $acl_gen;
public function __construct(ACLGenerator $acl_gen)
{
$this->acl_gen = $acl_gen;
}
public function getCompatibleBatteries(Request $req, $vid, EntityManagerInterface $em)
{
$this->denyAccessUnlessGranted('tapi_battery_compatible.list', null, 'No access.');
// check required parameters and api key
$required_params = [];
$msg = $this->checkRequiredParameters($req, $required_params);
if ($msg)
return new APIResponse(false, $msg);
// get vehicle
$vehicle = $em->getRepository(Vehicle::class)->find($vid);
if ($vehicle == null)
{
$message = 'Invalid vehicle id.';
return new APIResponse(false, $message);
}
// batteries
$batt_list = [];
$batts = $vehicle->getBatteries();
foreach ($batts as $batt)
{
// TODO: Add warranty_tnv to battery information
$batt_list[] = [
'id' => $batt->getID(),
'mfg_id' => $batt->getManufacturer()->getID(),
'mfg_name' => $batt->getManufacturer()->getName(),
'model_id' => $batt->getModel()->getID(),
'model_name' => $batt->getModel()->getName(),
'size_id' => $batt->getSize()->getID(),
'size_name' => $batt->getSize()->getName(),
'price' => $batt->getSellingPrice(),
'wty_private' => $batt->getWarrantyPrivate(),
'wty_commercial' => $batt->getWarrantyCommercial(),
'image_url' => $this->getBatteryImageURL($req, $batt),
];
}
// data
$data = [
'vehicle' => [
'id' => $vehicle->getID(),
'mfg_id' => $vehicle->getManufacturer()->getID(),
'mfg_name' => $vehicle->getManufacturer()->getName(),
'make' => $vehicle->getMake(),
'model_year_from' => $vehicle->getModelYearFrom(),
'model_year_to' => $vehicle->getModelYearTo(),
],
'batteries' => $batt_list,
];
$message = 'Compatible batteries found.';
return new APIResponse(true, $message, $data);
}
// TODO: might have to put this in a common service since JobOrderController also calls this
protected function getBatteryImageURL($req, $batt)
{
// TODO: workaround for now, we get static image of battery based on model name
$filename = trim(strtolower($batt->getModel()->getName())) . '_mobile.jpg';
$file_path = $req->getSchemeAndHttpHost() . $this->generateUrl('static_battery_image') . '/' . $filename;
return $file_path;
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,45 @@
<?php
namespace App\Controller\TAPI;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\Query;
use Doctrine\ORM\EntityManagerInterface;
use Catalyst\APIBundle\Controller\APIController;
use Catalyst\APIBundle\Response\APIResponse;
use App\Entity\Promo;
use Catalyst\APIBundle\Access\Generator as ACLGenerator;
class PromoController extends APIController
{
protected $acl_gen;
public function __construct(ACLGenerator $acl_gen)
{
$this->acl_gen = $acl_gen;
}
public function listPromos(Request $req, EntityManagerInterface $em)
{
$this->denyAccessUnlessGranted('tapi_promo.list', null, 'No access.');
// check required parameters and api key
$required_params = [];
$msg = $this->checkRequiredParameters($req, $required_params);
if ($msg)
return new APIResponse(false, $msg);
$data = [];
// TODO: add call to get promos here
$message = 'Promos found.';
return new APIResponse(true, $message, $data);
}
}

View file

@ -0,0 +1,79 @@
<?php
namespace App\Controller\TAPI;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\Query;
use Doctrine\ORM\EntityManagerInterface;
use Catalyst\APIBundle\Controller\APIController;
use Catalyst\APIBundle\Response\APIResponse;
use App\Entity\Service;
use Catalyst\APIBundle\Access\Generator as ACLGenerator;
class ServiceController extends APIController
{
protected $acl_gen;
public function __construct(ACLGenerator $acl_gen)
{
$this->acl_gen = $acl_gen;
}
public function listServices(Request $req, EntityManagerInterface $em)
{
$this->denyAccessUnlessGranted('tapi_service.list', null, 'No access.');
$required_params = [];
$res = $this->checkParamsAndKey($req, $em, $required_params);
if ($res->isError())
return $res->getReturnResponse();
// services
$results = $em->getRepository(Service::class)->findAll();
if (empty($results))
{
$res->setError(true)
->setErrorMessage('No services available.');
return $res->getReturnResponse();
}
$services = [];
foreach ($results as $result)
{
/*
// get partners
$partners = [];
$service_partners = $result->getPartners();
foreach($service_partners as $sp)
{
$partners[] = [
'id' => $sp->getID(),
'name' => $sp->getName(),
'branch' => $sp->getBranch(),
'address' => $sp->getAddress(),
'contact_nums' => $sp->getContactNumbers(),
'time_open' => $sp->getTimeOpen()->format("g:i A"),
'time_close' => $sp->getTimeClose()->format("g:i A"),
];
}
*/
$services[] = [
'id' => $result->getID(),
'name' => $result->getName(),
// 'partners' => $partners,
];
}
$data['services'] = $services;
$res->setData($data);
return $res->getReturnResponse();
}
}

View file

@ -0,0 +1,107 @@
<?php
namespace App\Controller\TAPI;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\Query;
use Doctrine\ORM\EntityManagerInterface;
use Catalyst\APIBundle\Controller\APIController;
use Catalyst\APIBundle\Response\APIResponse;
use App\Entity\VehicleManufacturer;
use App\Entity\Vehicle;
use Catalyst\APIBundle\Access\Generator as ACLGenerator;
class VehicleController extends APIController
{
protected $acl_gen;
public function __construct(ACLGenerator $acl_gen)
{
$this->acl_gen = $acl_gen;
}
public function listVehicleManufacturers(Request $req, EntityManagerInterface $em)
{
$this->denyAccessUnlessGranted('tapi_vmanufacturer.list', null, 'No access.');
// check required parameters
$required_params = [];
$msg = $this->checkRequiredParameters($req, $required_params);
if ($msg)
return new APIResponse(false, $msg);
// get manufacturer list
$mfgs = $em->getRepository(VehicleManufacturer::class)->findBy(['flag_mobile' => true], ['name' => 'asc']);
$mfg_list = [];
foreach ($mfgs as $mfg)
{
$mfg_list[] = [
'id' => $mfg->getID(),
'name' => $mfg->getName(),
];
}
$data = [
'manufacturers' => $mfg_list
];
$message = 'Vehicle manufacturers found.';
return new APIResponse(true, $message, $data);
}
public function listVehicleMakes(Request $req, $mfg_id, EntityManagerInterface $em)
{
$this->denyAccessUnlessGranted('tapi_vehicle.list', null, 'No access.');
// check required parameters and api key
$required_params = [];
$msg = $this->checkRequiredParameters($req, $required_params);
if ($msg)
return new APIResponse(false, $msg);
// get manufacturer
$mfg = $em->getRepository(VehicleManufacturer::class)->find($mfg_id);
if ($mfg == null)
{
$message = 'Invalid vehicle manufacturer id.';
return new APIResponse(false, $message);
}
// get makes
$vehicles = $em->getRepository(Vehicle::class)->findBy(
[
'flag_mobile' => true,
'manufacturer' => $mfg_id,
],
['make' => 'asc']
);
$vlist = [];
foreach ($vehicles as $v)
{
$vlist[] = [
'id' => $v->getID(),
'make' => trim($v->getMake() . ' ' . $v->getModelYearFormatted(false)),
];
}
$data = [
'manufacturer' => [
'id' => $mfg->getID(),
'name' => $mfg->getName(),
],
'makes' => $vlist,
];
$message = 'Vehicle models found.';
return new APIResponse(true, $message, $data);
}
}

View file

@ -4,13 +4,14 @@ namespace App\Ramcar;
class TransactionOrigin extends NameValue
{
const CALL = 'call';
const ONLINE = 'online';
const FACEBOOK = 'facebook';
const VIP = 'vip';
const MOBILE_APP = 'mobile_app';
const WALK_IN = 'walk_in';
const LAZADA = 'lazada';
const CALL = 'call';
const ONLINE = 'online';
const FACEBOOK = 'facebook';
const VIP = 'vip';
const MOBILE_APP = 'mobile_app';
const WALK_IN = 'walk_in';
const LAZADA = 'lazada';
const THIRD_PARTY = 'third_party';
const YOKOHAMA_OP_FACEBOOK = 'yokohama_op_facebook';
const YOKOHAMA_TWITTER = 'yokohama_twitter';
const YOKOHAMA_INSTAGRAM = 'yokohama_instagram';
@ -26,6 +27,7 @@ class TransactionOrigin extends NameValue
'mobile_app' => 'Mobile App',
'walk_in' => 'Walk-in',
'lazada' => 'Lazada',
'third_party' => 'Third Party',
'yokohama_op_facebook' => 'Yokohama OP Facebook',
'yokohama_twitter' => 'Yokohama Twitter',
'yokohama_instagram' => 'Yokohama Instagram',