WIP: posting shiai to the wkKalendar via api

This commit is contained in:
marko
2024-01-07 18:36:43 +01:00
parent 4bf364c83b
commit 14108660f9
6 changed files with 150 additions and 24 deletions

View File

@@ -3,14 +3,52 @@ require_once("inc/bootstrap.php");
require_once("participoLib/shiai.php");
$method = $_SERVER['REQUEST_METHOD'];
// Sending Response
// - setting header
// - we send a json-formatted response
// - we send a json-formatted response
header("Content-Type: application/json");
// - sending body payload
echo(
json_encode(
Shiai::dbSelect()
)
);
// - check if an valid api key was send
authorize();
// - depending on the method we perform different actions
switch($method){
// Create
case 'POST':
$postData = json_decode(file_get_contents('php://input'), true);
if(!$postData){
die(json_encode([
'error'=>$postData . " not valid json data!"
]));
}
die(json_encode(
Shiai::fromArray($postData)->asArray()
));
break;
// Read
case 'GET':
echo(json_encode(
Shiai::dbSelect()
));
break;
// Update
case 'PUT':
die(json_encode([
'success'=>false,
'reason'=>$method.".not supported yet."
]));
break;
// Delete
case 'DELETE':
die(json_encode([
'success'=>false,
'reason'=>$method.".not supported yet."
]));
break;
// all other methods not supported
default:
die(json_encode([
'success'=>false,
'reason'=>$method.".not supported."
]));
}
?>