wip: added rest api endpoint shiai

This commit is contained in:
marko
2023-12-26 20:24:34 +01:00
parent 49978a48df
commit f2cf7ff764
12 changed files with 245 additions and 44 deletions

View File

@@ -1,70 +1,81 @@
<?php
setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/'. PATH_SEPARATOR. '..');
setlocale(LC_ALL, "de_DE@euro", "de_DE", "de", "ge");
set_include_path(
get_include_path() . PATH_SEPARATOR . "../lib/" . PATH_SEPARATOR . ".."
);
require_once 'config/participo.php';
require_once 'local/cwsvJudo.php';
require_once "config/participo.php";
require_once "local/cwsvJudo.php";
require_once 'participoLib/participo.php';
require_once "participoLib/participo.php";
$db = dbConnector::connect(
$cwsvJudoConfig['db']['host'],
$cwsvJudoConfig['db']['name'],
$cwsvJudoConfig['db']['user'],
$cwsvJudoConfig['db']['password']
);
function init($config)
{
dbConnector::connect(
$config["db"]["host"],
$config["db"]["name"],
$config["db"]["user"],
$config["db"]["password"]
);
}
function authorize(){
if(array_key_exists("HTTP_AUTHORIZATION", $_SERVER)){
if(!empty($_SERVER["HTTP_AUTHORIZATION"])){
function authorize()
{
if (array_key_exists("HTTP_AUTHORIZATION", $_SERVER)) {
if (!empty($_SERVER["HTTP_AUTHORIZATION"])) {
$auth = explode(" ", $_SERVER["HTTP_AUTHORIZATION"]);
if($auth[0]="Basic"){
if ($auth[0] = "Basic") {
$allowKey = ApiKey::loadFromDb($auth[1]);
}
}
}
if (!$allowKey || !$allowKey->isValidFor('api')) {
die(json_encode(['success' => false]));
if (!$allowKey || !$allowKey->isValidFor("api")) {
die(
json_encode([
"success" => false,
"reason" => "apiKey not sufficient or no api key provided",
])
);
}
}
function get(){
$wkSqlQuery = "SELECT DISTINCT"
." `wkParticipo_Users`.* "
." FROM `wkParticipo_Users`"
." JOIN `vormundschaft`"
." ON `wkParticipo_Users`.`id` =`vormundschaft`.`userId`"
." JOIN `wkParticipo_user<=>userAttributes`"
." ON `wkParticipo_user<=>userAttributes`.`userId` = `vormundschaft`.`kidId`"
." WHERE `wkParticipo_user<=>userAttributes`.`attributeId` = 4"
." ORDER BY `wkParticipo_Users`.`id` ASC;";
function get()
{
$wkSqlQuery =
"SELECT DISTINCT" .
" `wkParticipo_Users`.* " .
" FROM `wkParticipo_Users`" .
" JOIN `vormundschaft`" .
" ON `wkParticipo_Users`.`id` =`vormundschaft`.`userId`" .
" JOIN `wkParticipo_user<=>userAttributes`" .
" ON `wkParticipo_user<=>userAttributes`.`userId` = `vormundschaft`.`kidId`" .
" WHERE `wkParticipo_user<=>userAttributes`.`attributeId` = 4" .
" ORDER BY `wkParticipo_Users`.`id` ASC;";
$wkSqlResponse = dbConnector::query($wkSqlQuery);
// Postprocessing
// - convert the comma separated list into an array
foreach( $wkSqlResponse as &$user){
$user['eMail'] = explode(",", $user['eMail']);
foreach( $user['eMail'] as &$email){
foreach ($wkSqlResponse as &$user) {
$user["eMail"] = explode(",", $user["eMail"]);
foreach ($user["eMail"] as &$email) {
$email = trim($email);
}
}
return $wkSqlResponse;
}
init($cwsvJudoConfig);
authorize();
$wkSqlResponse = get();
// Sending Response
// - setting header
header('Content-Type: application/json');
header("Content-Type: application/json");
// - sending body payload
// @todo die() seems to be more a error handling function. But echo+exit doesn't seem to close the connection (?). What leads to pythons requests.get() always wait for the complete timeout.
die(
json_encode($wkSqlResponse)
);
echo json_encode($wkSqlResponse);
// @todo Should not be necessary. But until the problem with the timeout time of the requesting client is solved, this explicit exit() stands!
exit(0);
?>
// exit(0);
?>