Compare commits

..

4 Commits

3 changed files with 65 additions and 2 deletions

View File

@@ -269,6 +269,16 @@ class EmployeeApplication{
return $response; return $response;
} }
/**
* @param $code string
* @return array
*/
function getEmployeeDataByCode($code){
$idEmployee = $this->getIdEmployeeTypeByCode($code);
return $this->proxyGetEmployeeDataById($idEmployee);
}
/** /**
* @param $idPerson integer * @param $idPerson integer
* @param $firstName binary * @param $firstName binary
@@ -404,5 +414,44 @@ class EmployeeApplication{
$this->pdo->rollback(); $this->pdo->rollback();
} }
} }
/**
* Intended for internal use
*
* This method will bring a list of ids of all the employees that are
* currently active in the system
*
* @return array
*/
function getIdEmployeeFromAllActiveEmployees(){
$stmt = $this->pdo->prepare("SELECT
id
FROM
employees
WHERE
status = 'ACTIVE';");
$stmt->execute();
$results = $stmt->fetchAll();
if(!$results){
exit($this->databaseSelectQueryErrorMessage);
}
$stmt = null;
return $results;
}
function listAllActiveEmployees(){
$ids = $this->getIdEmployeeFromAllActiveEmployees();
$result = array();
foreach($ids as $row){
$result[] = $this->proxyGetEmployeeDataById($row['id']);
}
return $result;
}
} }
?> ?>

View File

@@ -41,6 +41,12 @@ $app->get('/api/employee/types', function (Request $request, Response $response,
->write(json_encode($this->employeeApplication->listEmployeeTypes())); ->write(json_encode($this->employeeApplication->listEmployeeTypes()));
}); });
$app->get('/api/employee/all', function (Request $request, Response $response, array $args) {
return $response->withStatus(200)
->withHeader('Content-Type', 'application/json')
->write(json_encode($this->employeeApplication->listAllActiveEmployees()));
});
$app->post('/api/employee', function ($request, $response) { $app->post('/api/employee', function ($request, $response) {
$requestData = $request->getParsedBody(); $requestData = $request->getParsedBody();
@@ -73,10 +79,18 @@ $app->get('/api/employee/type/{code}', function (Request $request, Response $res
->write(json_encode($this->employeeApplication->getIdEmployeeTypeByCode($code))); ->write(json_encode($this->employeeApplication->getIdEmployeeTypeByCode($code)));
}); });
$app->get('/api/employee/{idEmployee}', function (Request $request, Response $response, array $args) { $app->get('/api/employee/id/{idEmployee}', function (Request $request, Response $response, array $args) {
$idEmployee = $args['idEmployee']; $idEmployee = $args['idEmployee'];
return $response->withStatus(200) return $response->withStatus(200)
->withHeader('Content-Type', 'application/json') ->withHeader('Content-Type', 'application/json')
->write(json_encode($this->employeeApplication->proxyGetEmployeeDataById($idEmployee))); ->write(json_encode($this->employeeApplication->proxyGetEmployeeDataById($idEmployee)));
});
$app->get('/api/employee/code/{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->getEmployeeDataByCode($code)));
}); });

View File

@@ -43,7 +43,7 @@ return [
// Employee settings // Employee settings
'employee' => [ 'employee' => [
'codeLength' => '5', 'codeLength' => '3',
], ],
], ],
]; ];