From 30420975c4c570fe4d2b10153167cf845613e453 Mon Sep 17 00:00:00 2001 From: Jose Pabl Domingo Aramburo Sanchez Date: Mon, 6 Aug 2018 01:52:06 -0600 Subject: [PATCH] [add] Getting employee data --- .../src/application/EmployeeApplication.php | 27 +++++++++++++++++++ api-payroll/src/routes.php | 8 ++++++ 2 files changed, 35 insertions(+) diff --git a/api-payroll/src/application/EmployeeApplication.php b/api-payroll/src/application/EmployeeApplication.php index 4368015..636df92 100644 --- a/api-payroll/src/application/EmployeeApplication.php +++ b/api-payroll/src/application/EmployeeApplication.php @@ -174,5 +174,32 @@ class EmployeeApplication{ return $results[0]['id']; } + + function getEmployeeDataById($idEmployee){ + $stmt = $this->pdo->prepare("SELECT + p.id, + p.firstName, + p.middleName, + IFNULL(p.lastName, '') AS lastName, + p.email, + p.phone, + e.code, + e.contractType + FROM + employees e + INNER JOIN + persons p ON p.id = e.idPerson + WHERE + e.id = :idEmployee"); + + $stmt->execute(array(':idEmployee' => $idEmployee)); + $results = $stmt->fetchAll(); + if(!$results){ + exit($this->databaseSelectQueryErrorMessage); + } + $stmt = null; + + return $results[0]; + } } ?> \ No newline at end of file diff --git a/api-payroll/src/routes.php b/api-payroll/src/routes.php index 6d91c0d..6101d76 100644 --- a/api-payroll/src/routes.php +++ b/api-payroll/src/routes.php @@ -56,3 +56,11 @@ $app->get('/api/employee/type/{code}', function (Request $request, Response $res ->withHeader('Content-Type', 'application/json') ->write(json_encode($this->employeeApplication->getIdEmployeeTypeByCode($code))); }); + +$app->get('/api/employee/{idEmployee}', function (Request $request, Response $response, array $args) { + $idEmployee = $args['idEmployee']; + + return $response->withStatus(200) + ->withHeader('Content-Type', 'application/json') + ->write(json_encode($this->employeeApplication->getEmployeeDataById($idEmployee))); +}); \ No newline at end of file