Added Other AP
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
|
||||
RewriteEngine On
|
||||
RewriteBase /SAVVY/cityservices/
|
||||
#RewriteBase /
|
||||
|
||||
#Checks to
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule ^(.*)$ index.php?/$1 [L]
|
||||
|
||||
</IfModule>
|
||||
|
||||
<IfModule !mod_rewrite.c>
|
||||
# If we don't have mod_rewrite installed, all 404's
|
||||
# can be sent to index.php, and everything works as normal.
|
||||
# Submitted by: ElliotHaughin
|
||||
|
||||
ErrorDocument 404 /index.php
|
||||
|
||||
</IfModule>
|
||||
|
||||
#Header add Access-Control-Allow-Origin "*"
|
||||
#Header add Access-Control-Expose-Headers "Access-Control-Allow-Origin"
|
||||
#Header add Access-Control-Allow-Headers "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With"
|
||||
#Header add Access-Control-Allow-Methods "POST, GET, PUT, DELETE, OPTIONS"
|
||||
#Header add Content-type "application/json"
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
class CityServiceApi extends Api {
|
||||
|
||||
public $apiName = 'cityservices';
|
||||
|
||||
public function __construct($requestUri, $encryption=true) {
|
||||
$encryption = false; // We do not need encryption for this class
|
||||
parent::__construct($requestUri, $encryption);
|
||||
//$this->encryption = $encryption;
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\Get(
|
||||
* path="/SAVVY/touristattraction/api/touristattraction?city={city}&country={country}",
|
||||
* security={{"token": {}}},
|
||||
* summary="Get geofenceareacity by city and country code",
|
||||
* @OA\Response(
|
||||
* response="200",
|
||||
* description="Found geofence area city",
|
||||
* @OA\JsonContent(
|
||||
* type="object"
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function indexAction() {
|
||||
$message = 'No locations found';
|
||||
|
||||
$city = $this->requestParams['city'] ?? '';
|
||||
$results = [];
|
||||
$res_status = 404;
|
||||
|
||||
try {
|
||||
if (empty($city)) {
|
||||
throw new Exception("Invalid city");
|
||||
}
|
||||
|
||||
$db = new Db();
|
||||
list($results, $err) = CityServiceModel::get( $db->getConnect(), $city );
|
||||
if (!empty($err)) {
|
||||
$result = [
|
||||
"services" => NULL,
|
||||
"error" => $err
|
||||
];
|
||||
} else {
|
||||
$result = [
|
||||
"services" => $results,
|
||||
];
|
||||
$res_status = 200;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$message = $e->getMessage();
|
||||
$result = [
|
||||
"services" => NULL,
|
||||
"error" => $message
|
||||
];
|
||||
}
|
||||
|
||||
return $this->response($result, $res_status);
|
||||
}
|
||||
|
||||
public function viewAction() {}
|
||||
|
||||
public function createAction() {}
|
||||
|
||||
public function updateAction() {}
|
||||
|
||||
public function deleteAction() {}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
class CityServiceModel {
|
||||
|
||||
public static function get($db, $city) {
|
||||
$city = (int)$city;
|
||||
|
||||
// Step 1: Load address
|
||||
$q = "SELECT *FROM city_services WHERE city_id = ${city}";
|
||||
$r = pg_query($db, $q);
|
||||
if ($r && pg_num_rows($r)) {
|
||||
$results = pg_fetch_all($r);
|
||||
} else {
|
||||
return [NULL, "Services not found"];
|
||||
}
|
||||
|
||||
return [$results, NULL];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
require_once '../../core/backend.php';
|
||||
|
||||
require_once '../common/Api.php';
|
||||
require_once '../common/Db.php';
|
||||
|
||||
require_once 'CityServiceModel.php';
|
||||
require_once 'CityServiceApi.php';
|
||||
|
||||
$httpAuthToken = $savvyext->cfgReadChar('system.oauth2_token');
|
||||
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
|
||||
header("Access-Control-Allow-Headers: Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With, client_id");
|
||||
header("Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS");
|
||||
header('Content-type: application/json');
|
||||
|
||||
if ("OPTIONS" === $_SERVER['REQUEST_METHOD']) {
|
||||
exit();
|
||||
}
|
||||
|
||||
$headers = getallheaders();
|
||||
if ((!isset($headers["Authorization"]) || substr($headers["Authorization"], -strlen($httpAuthToken)) != $httpAuthToken) &&
|
||||
(!isset($headers["authorization"]) || substr($headers["authorization"], -strlen($httpAuthToken)) != $httpAuthToken)) {
|
||||
header('HTTP/1.1 401 Unauthorized');
|
||||
header('Status: 401 Unauthorized');
|
||||
echo "{\"status\":\"Missing authorization\"}";
|
||||
exit();
|
||||
}
|
||||
|
||||
try {
|
||||
if (strpos($_SERVER['REQUEST_URI'], '/api/') === false) {
|
||||
throw new Exception("Invalid API request");
|
||||
}
|
||||
$requestUri = explode('/', trim($_SERVER['REQUEST_URI'], '/'));
|
||||
while (array_shift($requestUri) !== 'api') {
|
||||
};
|
||||
|
||||
if ($requestUri[0] == 'cityservices') {
|
||||
$api = new CityServiceApi($requestUri, false);
|
||||
}
|
||||
echo $api->run();
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(array('error' => $e->getMessage()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @OA\Info(
|
||||
* title="Geofence Area City Endpoint API",
|
||||
* version="1.0",
|
||||
* @OA\Contact(
|
||||
* email="support@float.sg"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
/**
|
||||
* @OA\SecurityScheme(
|
||||
* securityScheme="token",
|
||||
* type="apiKey",
|
||||
* name="Authorization",
|
||||
* in="header"
|
||||
* )
|
||||
*/
|
||||
Reference in New Issue
Block a user