From 6c4e42e337e06bf84923c4b8ac2af84224f37a0a Mon Sep 17 00:00:00 2001 From: Jose Pabl Domingo Aramburo Sanchez Date: Mon, 6 Aug 2018 03:49:42 -0600 Subject: [PATCH] [add] List of all active employees --- .../src/application/EmployeeApplication.php | 39 +++++++++++++++++++ api-payroll/src/routes.php | 6 +++ 2 files changed, 45 insertions(+) diff --git a/api-payroll/src/application/EmployeeApplication.php b/api-payroll/src/application/EmployeeApplication.php index 6cf237a..5573b9b 100644 --- a/api-payroll/src/application/EmployeeApplication.php +++ b/api-payroll/src/application/EmployeeApplication.php @@ -404,5 +404,44 @@ class EmployeeApplication{ $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; + } } ?> \ No newline at end of file diff --git a/api-payroll/src/routes.php b/api-payroll/src/routes.php index 7c3337e..f36b17a 100644 --- a/api-payroll/src/routes.php +++ b/api-payroll/src/routes.php @@ -41,6 +41,12 @@ $app->get('/api/employee/types', function (Request $request, Response $response, ->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) { $requestData = $request->getParsedBody();