From 692f52b533e6a5715ec24070616b73f2d56bec5a Mon Sep 17 00:00:00 2001 From: Jose Pabl Domingo Aramburo Sanchez Date: Sun, 5 Aug 2018 22:31:40 -0600 Subject: [PATCH] [add] Listing of employee types --- .../src/application/EmployeeApplication.php | 31 +++++++++++++++++++ api-payroll/src/dependencies.php | 6 ++++ api-payroll/src/routes.php | 6 ++++ database/database.sql | 15 +++++++++ 4 files changed, 58 insertions(+) create mode 100644 api-payroll/src/application/EmployeeApplication.php diff --git a/api-payroll/src/application/EmployeeApplication.php b/api-payroll/src/application/EmployeeApplication.php new file mode 100644 index 0000000..51f74d3 --- /dev/null +++ b/api-payroll/src/application/EmployeeApplication.php @@ -0,0 +1,31 @@ +cryptographyService = $cryptographyService; + $this->pdo = $mysql; + $this->asserts = $asserts; + + $this->databaseSelectQueryErrorMessage = 'There was an error inserting the record.'; + } + + function listEmployeeTypes(){ + $stmt = $this->pdo->prepare("SELECT id, name FROM employeeType WHERE status = 'ACTIVE'"); + $stmt->execute(); + + $results = $stmt->fetchAll(); + + if(!$results){ + exit($this->databaseSelectQueryErrorMessage); + } + $stmt = null; + + return $results; + } +} +?> \ No newline at end of file diff --git a/api-payroll/src/dependencies.php b/api-payroll/src/dependencies.php index 9b14dd6..cb1fa94 100644 --- a/api-payroll/src/dependencies.php +++ b/api-payroll/src/dependencies.php @@ -62,3 +62,9 @@ $container['sessionApplication'] = function ($c) { $sessionApplication = new App\Application\SessionApplication($c['mysql'], $c['cryptographyService'], $c['asserts']); return $sessionApplication; }; + +// The employee application +$container['employeeApplication'] = function ($c) { + $employeeApplication = new App\Application\EmployeeApplication($c['mysql'], $c['cryptographyService'], $c['asserts']); + return $employeeApplication; +}; \ No newline at end of file diff --git a/api-payroll/src/routes.php b/api-payroll/src/routes.php index 680333b..53e5f5a 100644 --- a/api-payroll/src/routes.php +++ b/api-payroll/src/routes.php @@ -33,4 +33,10 @@ $app->post('/api/session/logout', function (Request $request, Response $response return $response->withStatus(200) ->withHeader('Content-Type', 'application/json') ->write(json_encode($this->sessionApplication->destroySession())); +}); + +$app->get('/api/employee/types', function (Request $request, Response $response, array $args) { + return $response->withStatus(200) + ->withHeader('Content-Type', 'application/json') + ->write(json_encode($this->employeeApplication->listEmployeeTypes())); }); \ No newline at end of file diff --git a/database/database.sql b/database/database.sql index 930a97a..8b311b7 100644 --- a/database/database.sql +++ b/database/database.sql @@ -45,3 +45,18 @@ CREATE TABLE IF NOT EXISTS `users` ( INSERT INTO users (idPerson, name, password) VALUES (1, 'sloth', '$2y$12$51mfESaLEGXDT4u9Bd9kiOHEpaJ1Bx4SEcVwsU5K6jVPMNkrnpJAa'); + +DROP TABLE IF EXISTS employeeType; +CREATE TABLE IF NOT EXISTS `employeeType` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `name` VARCHAR(100) NOT NULL comment 'Type or rol that the employee can be', + `status` ENUM('ACTIVE', 'INACTIVE') NOT NULL DEFAULT 'ACTIVE', + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment 'The date on which the registry was created', + `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment 'The date of the last time the row was modified', + PRIMARY KEY (`id`), + UNIQUE (`name`) +); + +INSERT INTO employeeType (name) VALUES ('Chofer'), + ('Cargador'), + ('Auxiliar');