Added Other AP

This commit is contained in:
dev-chiefworks
2022-04-26 11:30:34 -04:00
parent 5e006a6a21
commit 47f4fad75c
251 changed files with 29298 additions and 4 deletions
+27
View File
@@ -0,0 +1,27 @@
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /SAVVY/callback/
#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"
+129
View File
@@ -0,0 +1,129 @@
<?php
class AccountApi extends Api
{
public $apiName = 'account';
public function indexAction()
{
return $this->response(
array(
'error' => 'Data not found'
), 404);
}
/**
* Method GET
* Get member record (by id)
* http://DOMAIN/trips/1
* @return string
*/
/**
* @OA\Get(
* path="/SAVVY/callback/api/account/:id",
* summary="Get member account data by its unique ID",
* @OA\Parameter(
* name="id",
* in="path",
* required=true,
* @OA\Schema(ref="#/components/schemas/member_id")
* ),
* @OA\Response(
* response="200",
* description="Members data",
* @OA\JsonContent(
* type="object",
* @OA\Schema(ref="#/components/schemas/member_data")
* )
* )
* )
*/
public function viewAction()
{
//id must be the first parameter after /account/x
$id = array_shift($this->requestUri);
if($id && (int)$id>0){
$db = new Db();
$member = Callback::getMemberById($db->getConnect(), (int)$id);
if(is_array($member) && count($member)>0){
return $this->response($member, 200);
}
}
return $this->response(
array(
'error'=> 'Data not found'
), 404);
}
// * description = "curl -d '{\"member_id\":22,\"last_acct\":\"2019-05-06\",\"count_acct\":1}' -X POST https://svrsavvy.sworks.float.sg/SAVVY/callback/api/account",
/**
* @OA\Post(
* path="/SAVVY/callback/api/account",
* summary="Save account data within members record",
* @OA\Parameter(
* name="",
* description = "Account callback data",
* in="body",
* required=true,
* @OA\Schema(ref="#/components/schemas/account_request")
* ),
* @OA\Response(
* response="200",
* description="Members data",
* @OA\JsonContent(
* type="object",
* @OA\Schema(ref="#/components/schemas/member_data")
* )
* )
* )
*/
public function createAction()
{
$message = "Failed to save data";
$member_id = $this->requestParams["member_id"] ?? 0;
$last_acct = $this->requestParams["last_acct"] ?? "";
$count_acct = $this->requestParams["count_acct"] ?? 0;
if ($member_id>0 && $last_acct!="" && strtotime($last_acct)>0 && $count_acct>0) {
$db = new Db();
$member = Callback::getMemberById($db->getConnect(), (int)$member_id);
if (isset($member["id"]) && $member["id"]>0) {
$result = Callback::updateMember(
$db->getConnect(),
(int)$member_id,
$last_acct,
$count_acct);
if (is_array($result) && count($result)>0) {
return $this->response($result, 200);
} else {
$message = "Failed to update member";
}
} else {
$message = "Invalid member id";
}
} else {
$message = "Invalid input $member_id>0 && $last_acct!= $count_acct";
}
return $this->response(
array(
"error" => $message
), 500);
}
public function updateAction()
{
return $this->response(
array(
"error" => "Update error"
), 400);
}
public function deleteAction()
{
return $this->response(
array(
"error" => "Delete error"
), 500);
}
}
+42
View File
@@ -0,0 +1,42 @@
<?php
class Callback {
public function getMemberById($db, $id) {
$result = array();
$db_id = (int)$id;
$q = "SELECT * FROM members WHERE id=${db_id}";
$r = pg_query($db, $q);
if ($r && pg_num_rows($r) && $f=pg_fetch_assoc($r)) {
$result = $f;
}
return $result;
}
public function getMemberByEmail($db, $email) {
$result = array();
$db_email = pg_escape_string(strtolower($email));
$q = "SELECT * FROM members WHERE lower(email)='${db_email}' OR lower(username)='${db_email}'";
$r = pg_query($db, $q);
if ($r && pg_num_rows($r) && $f=pg_fetch_assoc($r)) {
$result = $f;
}
return $result;
}
public function updateMember($db, $member_id, $last_acct, $count_acct) {
$result = array();
$id = (int)$member_id;
$db_last_acct = date("Y-m-d H:i:s",strtotime($last_acct));
$db_count_acct = (int)$count_acct;
$q = "UPDATE members SET last_acct='${db_last_acct}',count_acct=${db_count_acct} WHERE id=${id}";
$r = pg_query($db, $q);
if ($r && pg_affected_rows($r)) {
return Callback::getMemberById($db, $id);
}
return $result;
}
}
// vi:ts=2
+121
View File
@@ -0,0 +1,121 @@
<?php
require_once('../../core/backend.php');
require_once('../constants.php');
require_once('../common/Api.php');
require_once('../common/Db.php');
require_once('Callback.php');
require_once('AccountAPI.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]=='account') {
$api = new AccountApi($requestUri);
}
else {
echo json_encode(Array('error' => 'Invalid API request'));
}
echo $api->run();
}
catch (Exception $e) {
echo json_encode(Array('error' => $e->getMessage()));
}
/**
* @OA\Info(
* title="Call Backend Endpoint API",
* version="0.1",
* @OA\Contact(
* email="support@float.sg"
* )
* )
*/
/**
* @OA\Schema(
* schema="member_id",
* type="integer",
* format="int64",
* description="The unique identifier of a member in our system"
* )
*/
/**
* @OA\Schema(
* schema="account_request",
* type="object",
* @OA\Property(
* property="member_id",
* description="The unique identifier of a member in our system",
* type="int",
* format="int64",
* example=22
* ),
* @OA\Property(
* property="last_acct",
* description="Last date of the account connection",
* type="string",
* format="date-time",
* example="2019-05-06"
* ),
* @OA\Property(
* property="count_acct",
* description="Count of the account items",
* type="int",
* format="int64",
* example=1
* ),
* )
*/
/**
* @OA\Schema(
* schema="member_data",
* type="object",
* @OA\Property(
* property="id",
* description="The unique identifier of a member in our system",
* type="int",
* format="int64",
* example=22
* ),
* @OA\Property(
* property="last_acct",
* description="Last date of the account connection",
* type="string",
* format="date-time",
* example="2019-05-06"
* ),
* @OA\Property(
* property="count_acct",
* description="Count of the account items",
* type="int",
* format="int64",
* example=1
* ),
* )
*/
Binary file not shown.

After

Width:  |  Height:  |  Size: 665 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 628 B

@@ -0,0 +1,60 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="swagger-ui.css" >
<link rel="icon" type="image/png" href="favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="favicon-16x16.png" sizes="16x16" />
<style>
html
{
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
*,
*:before,
*:after
{
box-sizing: inherit;
}
body
{
margin:0;
background: #fafafa;
}
</style>
</head>
<body>
<div id="swagger-ui"></div>
<script src="swagger-ui-bundle.js"> </script>
<script src="swagger-ui-standalone-preset.js"> </script>
<script>
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "../swagger.php",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})
// End Swagger UI call region
window.ui = ui
}
</script>
</body>
</html>
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+6
View File
@@ -0,0 +1,6 @@
<?php
require('../../../adminsavvy/vendor/autoload.php');
$openapi = \OpenApi\scan('.');
header('Content-Type: application/json');
echo $openapi->toJson();
?>