-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP API Endpoints for Organization management #276
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -311,6 +311,15 @@ | |
$route['api/rejectleave/(:num)'] = 'api/rejectleave/$1'; | ||
//v0.6.0 | ||
$route['api/users/ext'] = 'api/usersExt'; | ||
//MRM | ||
$route['api/organization_node/(:num)'] = 'api/organization_node/$1'; | ||
$route['api/organization_children/(:num)'] = 'api/organization_children/$1'; | ||
$route['api/createnodeorganization/'] = 'api/createnodeorganization'; | ||
$route['api/movenodeorganization/(:num)/(:num)'] = 'api/movenodeorganization/$1/$2'; | ||
$route['api/deletenodeorganization/(:num)'] = 'api/deletenodeorganization/$1'; | ||
$route['api/renamenodeorganization/(:num)'] = 'api/renamenodeorganization/$1'; | ||
$route['api/attachEmployee/(:num)/(:num)'] = 'api/attachEmployee/$1/$2'; | ||
$route['api/detachEmployee/(:num)/(:num)'] = 'api/detachEmployee/$1/$2'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The route has two parameters but only one is used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. REST: api/entities/employees/(:num)/detach |
||
|
||
//_______________________________________________ | ||
//ICS Feeds | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1792,4 +1792,131 @@ private function validateDate($date, $format = 'Y-m-d') | |
return $d && $d->format($format) === $date; | ||
} | ||
|
||
/** | ||
* Get one node of the organization | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing OpenAPI notation, see 32dbe5a |
||
* @author Mickael ROMMME | ||
*/ | ||
public function organization_node($id) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use underscore and use meaningful name, such as getEntity as Organization is composed of entities |
||
if (!$this->server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) { | ||
$this->server->getResponse()->send(); | ||
} else { | ||
$this->load->model('Organization_model'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Organization_model should be in lower case everywhere |
||
$result = $this->Organization_model->getName($id); | ||
echo json_encode($result); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The MIMETYPE (output encoding) is not set. You should rely on the framework, e.g.:
|
||
} | ||
} | ||
|
||
/** | ||
* Get id of all childrem of one node of the organization | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment more clearly with expected parameters passed in POST request |
||
* @author Mickael ROMMME | ||
*/ | ||
public function organization_children($id) { | ||
if (!$this->server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) { | ||
$this->server->getResponse()->send(); | ||
} else { | ||
$this->load->model('Organization_model'); | ||
$result = $this->Organization_model->getAllChildren($id); | ||
echo json_encode($result); | ||
} | ||
} | ||
|
||
/** | ||
* Create one node of the organization | ||
* @author Mickael ROMMME | ||
*/ | ||
public function createnodeorganization() { | ||
if (!$this->server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) { | ||
$this->server->getResponse()->send(); | ||
} else { | ||
$this->load->model('Organization_model'); | ||
|
||
$name = $this->input->post('name'); | ||
$parent_id = $this->input->post('parent_id'); | ||
|
||
//Check mandatory fields | ||
if ($name == FALSE || $parent_id == FALSE) { | ||
$this->output->set_header("HTTP/1.1 422 Unprocessable entity"); | ||
log_message('error', 'Mandatory fields are missing.'); | ||
} else { | ||
$result = $this->Organization_model->create($parent_id, $name); | ||
echo json_encode($result); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Move one node of the organization | ||
* @author Mickael ROMMME | ||
*/ | ||
public function movenodeorganization($id, $parent_id) { | ||
if (!$this->server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) { | ||
$this->server->getResponse()->send(); | ||
} else { | ||
$this->load->model('Organization_model'); | ||
$result = $this->Organization_model->move($id, $parent_id); | ||
echo json_encode($result); | ||
} | ||
} | ||
|
||
/** | ||
* Delete one node of the organization | ||
* Delete all children and unset organization id for user | ||
* @author Mickael ROMMME | ||
*/ | ||
public function deletenodeorganization($id) { | ||
if (!$this->server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) { | ||
$this->server->getResponse()->send(); | ||
} else { | ||
$this->load->model('Organization_model'); | ||
$result = $this->Organization_model->delete($id); | ||
echo json_encode($result); | ||
} | ||
} | ||
|
||
/** | ||
* Rename one node of the organization | ||
* @author Mickael ROMMME | ||
*/ | ||
public function renamenodeorganization($id) { | ||
if (!$this->server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) { | ||
$this->server->getResponse()->send(); | ||
} else { | ||
$this->load->model('Organization_model'); | ||
$name = $this->input->post('name'); | ||
$result = $this->Organization_model->rename($id, $name); | ||
if (empty($result)) { | ||
$this->output->set_header("HTTP/1.1 422 Unprocessable entity"); | ||
} else { | ||
echo json_encode($result); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Attach an employee to one node of the organization | ||
* @author Mickael ROMMME | ||
*/ | ||
public function attachEmployee($id, $entity) { | ||
if (!$this->server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) { | ||
$this->server->getResponse()->send(); | ||
} else { | ||
$this->load->model('Organization_model'); | ||
$result = $this->Organization_model->attachEmployee($id, $entity); | ||
echo json_encode($result); | ||
} | ||
} | ||
|
||
/** | ||
* Detach an employee to one node of the organization | ||
* @author Mickael ROMMME | ||
*/ | ||
public function detachEmployee($id) { | ||
if (!$this->server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) { | ||
$this->server->getResponse()->send(); | ||
} else { | ||
$this->load->model('Organization_model'); | ||
$result = $this->Organization_model->detachEmployee($id); | ||
echo json_encode($result); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
REST: api/entities/(:num)/employees/(:num)/attach Or (POST) api/entities/(:num)/employees/(:num)