Commit 296f9812 authored by Georgios Tsakalos's avatar Georgios Tsakalos

add create/update staff action

parent 62c62028
......@@ -23,8 +23,19 @@ class StaffCreate
public function __invoke(Request $req, Response $res, array $args = [])
{
$staff = $this->staffservice->getTeacherById(1);
$res = $res->withJson($staff->export());
$params = $req->getParams();
if (array_key_exists('id', $params)){
$id = $params['id'];
unset($params['id']);
$id = $this->staffservice->updateTeacher($params, $id);
$teacher = $this->staffservice->getTeacherById($id);
}
else{
$id = $this->staffservice->createTeacher($params);
$teacher = $this->staffservice->getTeacherById($id);
}
$res = $res->withJson($teacher->export());
return $res;
}
}
......@@ -44,6 +44,15 @@ class StaffService implements StaffServiceInterface
return $id;
}
public function updateTeacher(array $data, $id){
$teacher = R::load('teacher', $id);
foreach ($data as $key => $value){
$teacher[$key] = $value;
}
$id = R::store($teacher);
return $id;
}
public function getTeacherById($id)
{
$teacher = R::load('teacher', $id);
......
......@@ -14,4 +14,5 @@ interface StaffServiceInterface
public function createTeacher(array $data);
public function getTeacherById($id);
public function getTeachersBySchoolId($id);
public function updateTeacher(array $data, $id);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment