-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
33 lines (31 loc) · 1.02 KB
/
api.php
File metadata and controls
33 lines (31 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
require_once 'functionsApi.php';
$method = $_SERVER['REQUEST_METHOD'];
$apiDpto = new restApiDpto();
switch ($method) {
case 'GET':
if(isset($_GET["department_id"]) && !empty($_GET["department_id"]))
{
$department_id=$_GET["department_id"];
$apiDpto->get_departments($department_id);
}else { $apiDpto->get_departments(); }
break;
case 'POST':
$apiDpto->add_department();
break;
case 'PUT':
parse_str(file_get_contents("php://input"),$post_vars);
$apiDpto->update_department($post_vars);
break;
case 'DELETE':
$post_vars = json_decode(file_get_contents("php://input"));
$department_id = isset($post_vars) ? $post_vars->department_id : false;
if(!$department_id){
$department_id= isset($_GET["department_id"]) ? $_GET["department_id"] : false;
}
$apiDpto->delete_department($department_id);
break;
default:
header("HTTP/1.0 405 Method Not Allowed");
break;
}