WIP: posting shiai to the wkKalendar via api
This commit is contained in:
@@ -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."
|
||||
]));
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user