Data from employee #6

Merged
PootisPenserHere merged 5 commits from dataFromEmployee into master 2018-08-06 08:18:25 +00:00
2 changed files with 32 additions and 0 deletions
Showing only changes of commit 2d3f52372c - Show all commits

View File

@ -150,5 +150,29 @@ class EmployeeApplication{
return $response; return $response;
} }
/**
* @param $code
* @return mixed
*/
function getIdEmployeeTypeByCode($code){
$stmt = $this->pdo->prepare("SELECT COALESCE((SELECT
et.id
FROM
employees e
INNER JOIN
employeeType et ON et.id = e.idEmployeeType
WHERE
e.code = :code), 0) AS id");
$stmt->execute(array(':code' => $code));
$results = $stmt->fetchAll();
if(!$results){
exit($this->databaseSelectQueryErrorMessage);
}
$stmt = null;
return $results[0]['id'];
}
} }
?> ?>

View File

@ -48,3 +48,11 @@ $app->post('/api/employee', function ($request, $response) {
->withHeader('Content-Type', 'application/json') ->withHeader('Content-Type', 'application/json')
->write(json_encode($this->employeeApplication->saveNewEmployee($requestData))); ->write(json_encode($this->employeeApplication->saveNewEmployee($requestData)));
}); });
$app->get('/api/employee/type/{code}', function (Request $request, Response $response, array $args) {
$code = $args['code'];
return $response->withStatus(200)
->withHeader('Content-Type', 'application/json')
->write(json_encode($this->employeeApplication->getIdEmployeeTypeByCode($code)));
});