Add API call to list other services. #228
This commit is contained in:
parent
19325761db
commit
4782bd7fe8
2 changed files with 56 additions and 0 deletions
|
|
@ -124,3 +124,8 @@ api_location_support:
|
||||||
path: /api/location_support
|
path: /api/location_support
|
||||||
controller: App\Controller\APIController:locationSupport
|
controller: App\Controller\APIController:locationSupport
|
||||||
methods: [GET]
|
methods: [GET]
|
||||||
|
|
||||||
|
api_service_list:
|
||||||
|
path: /api/services
|
||||||
|
controller: App\Controller\APIController:listServices
|
||||||
|
methods: [GET]
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ use App\Entity\Promo;
|
||||||
use App\Entity\Battery;
|
use App\Entity\Battery;
|
||||||
use App\Entity\RiderRating;
|
use App\Entity\RiderRating;
|
||||||
use App\Entity\JOEvent;
|
use App\Entity\JOEvent;
|
||||||
|
use App\Entity\Service;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
@ -1802,4 +1803,54 @@ class APIController extends Controller
|
||||||
|
|
||||||
return $res->getReturnResponse();
|
return $res->getReturnResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function listServices(Request $req)
|
||||||
|
{
|
||||||
|
$required_params = [];
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
$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("d M Y g:i A"),
|
||||||
|
'time_close' => $sp->getTimeClose()->format("d M Y g:i A"),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$services[] = [
|
||||||
|
'id' => $result->getID(),
|
||||||
|
'name' => $result->getName(),
|
||||||
|
'partners' => $partners,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['services'] = $services;
|
||||||
|
|
||||||
|
$res->setData($data);
|
||||||
|
|
||||||
|
return $res->getReturnResponse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue