Compare commits
32 Commits
cors
...
adaptingMy
| Author | SHA1 | Date | |
|---|---|---|---|
| f16e9fe72c | |||
| d2b9163537 | |||
| 403541580d | |||
| 663ea7cc3e | |||
| f93b41f14e | |||
| 24f1ce1ed7 | |||
| b25346e3d5 | |||
| f2237d9209 | |||
| 7fc9ca8c75 | |||
| 97fca1d7d3 | |||
| 058e19a49a | |||
| bffeb6e9f4 | |||
| 9a3e876afe | |||
| dadea504d0 | |||
| 1390427ec0 | |||
| 6c4e42e337 | |||
| f4d1ce1ab7 | |||
| ba307555f0 | |||
| 57ee1fbd72 | |||
| 63a7186464 | |||
| 4a8df33184 | |||
| 0deb89ed53 | |||
| f441696b96 | |||
| 666b17c0dc | |||
| 30420975c4 | |||
| 2d3f52372c | |||
| 3d7a574396 | |||
| 90f11867a5 | |||
| 69b636620a | |||
| 304e3045c7 | |||
| 692f52b533 | |||
| 6b289695c7 |
5
api-payroll/.dockerignore
Normal file
5
api-payroll/.dockerignore
Normal file
@@ -0,0 +1,5 @@
|
||||
Dockerfile
|
||||
README.md
|
||||
buildspec.yml
|
||||
CONTRIBUTING.md
|
||||
docker-compose.yml
|
||||
1
api-payroll/.htaccess
Normal file
1
api-payroll/.htaccess
Normal file
@@ -0,0 +1 @@
|
||||
Options -Indexes
|
||||
43
api-payroll/Dockerfile
Normal file
43
api-payroll/Dockerfile
Normal file
@@ -0,0 +1,43 @@
|
||||
FROM ubuntu:16.04
|
||||
|
||||
# Updating
|
||||
RUN apt-get -y update && apt-get -y upgrade
|
||||
|
||||
# Installing php, apache and supplementary software
|
||||
RUN apt-get -y install apache2 php7.0 libapache2-mod-php7.0 php7.0-cli php7.0-common php7.0-mbstring php7.0-gd php7.0-intl php7.0-xml php7.0-mysql php7.0-mcrypt php7.0-zip curl git unzip composer
|
||||
|
||||
# Enable apache mods
|
||||
RUN a2enmod php7.0
|
||||
RUN a2enmod rewrite
|
||||
|
||||
# Update the PHP.ini file, enable <? ?> tags and quieten logging
|
||||
RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/7.0/apache2/php.ini
|
||||
RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" /etc/php/7.0/apache2/php.ini
|
||||
|
||||
# Manually set up the apache environment variables
|
||||
ENV APACHE_RUN_USER www-data
|
||||
ENV APACHE_RUN_GROUP www-data
|
||||
ENV APACHE_LOG_DIR /var/log/apache2
|
||||
ENV APACHE_LOCK_DIR /var/lock/apache2
|
||||
|
||||
# Expose apache
|
||||
EXPOSE 80
|
||||
|
||||
# Copy this repo into place.
|
||||
ADD . /var/www/site
|
||||
WORKDIR /var/www/site
|
||||
|
||||
# Testing permisions
|
||||
RUN chmod 777 -R .
|
||||
|
||||
# Installing dependencies
|
||||
RUN composer install
|
||||
|
||||
# Unit tests
|
||||
RUN composer test
|
||||
|
||||
# Update the default apache site with the config we created.
|
||||
ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf
|
||||
|
||||
# By default start up apache in the foreground, override with /bin/bash for interative
|
||||
CMD /usr/sbin/apache2ctl -D FOREGROUND
|
||||
15
api-payroll/apache-config.conf
Normal file
15
api-payroll/apache-config.conf
Normal file
@@ -0,0 +1,15 @@
|
||||
<VirtualHost *:80>
|
||||
ServerAdmin me@mydomain.com
|
||||
DocumentRoot /var/www/site
|
||||
|
||||
<Directory /var/www/site/>
|
||||
Options Indexes FollowSymLinks MultiViews
|
||||
AllowOverride All
|
||||
Order deny,allow
|
||||
Allow from all
|
||||
</Directory>
|
||||
|
||||
ErrorLog ${APACHE_LOG_DIR}/error.log
|
||||
CustomLog ${APACHE_LOG_DIR}/access.log combined
|
||||
|
||||
</VirtualHost>
|
||||
@@ -14,8 +14,9 @@ phases:
|
||||
- echo Entered the build phase...
|
||||
- echo Build started on `date`
|
||||
- composer test
|
||||
- sudo docker-compose up --build -d
|
||||
post_build:
|
||||
commands:
|
||||
- echo Entered the post_build phase...
|
||||
- sudo docker-compose down --rmi all -v
|
||||
- echo Build completed on `date`
|
||||
|
||||
|
||||
457
api-payroll/src/application/EmployeeApplication.php
Normal file
457
api-payroll/src/application/EmployeeApplication.php
Normal file
@@ -0,0 +1,457 @@
|
||||
<?php
|
||||
namespace App\Application;
|
||||
|
||||
use phpDocumentor\Reflection\Types\Integer;
|
||||
|
||||
class EmployeeApplication{
|
||||
private $pdo;
|
||||
private $cryptographyService;
|
||||
private $asserts;
|
||||
private $settings;
|
||||
|
||||
function __construct($employeeSettings, $mysql, $cryptographyService, $asserts){
|
||||
$this->settings = $employeeSettings;
|
||||
|
||||
$this->cryptographyService = $cryptographyService;
|
||||
$this->pdo = $mysql;
|
||||
$this->asserts = $asserts;
|
||||
|
||||
$this->databaseSelectQueryErrorMessage = 'There was an error inserting the record.';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $firstName binary
|
||||
* @param $middleName binary
|
||||
* @param $lastName binary or null
|
||||
* @param $birthDate date yyyy-mm-dd
|
||||
* @param $email string
|
||||
* @param $phone string
|
||||
* @return integer
|
||||
*/
|
||||
function saveNewPerson($firstName, $middleName, $lastName, $birthDate, $email, $phone){
|
||||
$this->asserts->firstName($firstName);
|
||||
$this->asserts->middleName($middleName);
|
||||
$this->asserts->birthDate($birthDate);
|
||||
$this->asserts->email($email);
|
||||
$this->asserts->phone($phone);
|
||||
|
||||
try {
|
||||
$stmt = $this->pdo->prepare("INSERT INTO persons (firstName, middleName, lastName, birthDate, email, phone)
|
||||
VALUES (:firstName, :middleName, :lastName, :birthDate, :email, :phone)");
|
||||
$this->pdo->beginTransaction();
|
||||
$stmt->execute(array(':firstName' => $firstName, ':middleName' => $middleName, ':lastName' => $lastName,
|
||||
':birthDate' => $birthDate, ':email' => $email, ':phone' => $phone));
|
||||
$id = $this->pdo->lastInsertId();
|
||||
$this->pdo->commit();
|
||||
|
||||
return $id;
|
||||
|
||||
$stmt = null;
|
||||
} catch( PDOExecption $e ) {
|
||||
$this->pdo->rollback();
|
||||
throw new Exception('There was an error while trying to save a new person.');
|
||||
$this->logger->warning("There was an error in the EmployeeApplication->saveNewPerson caused by: $e ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idEmployeeType integer
|
||||
* @param $idPerson integer
|
||||
* @param $code string
|
||||
* @param $contractType string
|
||||
* @return mixed
|
||||
*/
|
||||
function savePersonAsEmployee($idEmployeeType, $idPerson, $code, $contractType){
|
||||
try {
|
||||
$stmt = $this->pdo->prepare("INSERT INTO employees (idEmployeeType, idPerson, code, contractType)
|
||||
VALUES (:idEmployeeType, :idPerson, :code, :contractType)");
|
||||
$this->pdo->beginTransaction();
|
||||
$stmt->execute(array(':idEmployeeType' => $idEmployeeType, ':idPerson' => $idPerson, ':code' => $code,
|
||||
':contractType' => $contractType));
|
||||
$id = $this->pdo->lastInsertId();
|
||||
$this->pdo->commit();
|
||||
|
||||
return $id;
|
||||
|
||||
$stmt = null;
|
||||
} catch( PDOExecption $e ) {
|
||||
$this->pdo->rollback();
|
||||
throw new Exception('There was an error while trying to save a new employee.');
|
||||
$this->logger->warning("There was an error in the EmployeeApplication->savePersonAsEmployee caused by: $e ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $requestData object
|
||||
* @return array
|
||||
*/
|
||||
function saveNewEmployee($requestData){
|
||||
// Getting and validating the data
|
||||
$firstName = $requestData['firstName'];
|
||||
$this->asserts->firstName($firstName);
|
||||
|
||||
$middleName = $requestData['middleName'];
|
||||
$this->asserts->middleName($middleName);
|
||||
|
||||
$lastName = isset($requestData['lastName']) ? $requestData['lastName'] : null;
|
||||
|
||||
$birthDate = $requestData['birthDate'];
|
||||
$this->asserts->birthDate($birthDate);
|
||||
|
||||
$email = $requestData['email'];
|
||||
$this->asserts->email($email);
|
||||
|
||||
$phone = $requestData['phone'];
|
||||
$this->asserts->phone($phone);
|
||||
|
||||
$idEmployeeType = $requestData{'idEmployeeType'};
|
||||
$contractType = $requestData{'contractType'};
|
||||
|
||||
// Encrypting the sensitive data
|
||||
$securedFirstName = $this->cryptographyService->encryptString($firstName);
|
||||
$securedMiddleName = $this->cryptographyService->encryptString($middleName);
|
||||
|
||||
if (isset($lastName)) {
|
||||
$securedLastName = $this->cryptographyService->encryptString($lastName);
|
||||
} else {
|
||||
$securedLastName = null;
|
||||
}
|
||||
|
||||
$securedEmail = $this->cryptographyService->encryptString($email);
|
||||
|
||||
// Here begins the saving process
|
||||
$idNewPerson = $this->saveNewPerson($securedFirstName, $securedMiddleName, $securedLastName,
|
||||
$birthDate, $securedEmail, $phone);
|
||||
|
||||
$employeeCode = $this->cryptographyService->pseudoRandomStringOpenssl($this->settings['codeLength']);
|
||||
$idEmployee = $this->savePersonAsEmployee($idEmployeeType, $idNewPerson, $employeeCode, $contractType);
|
||||
|
||||
$response = array(
|
||||
"fullName" => "$firstName $middleName $lastName",
|
||||
"employeeCode" => $employeeCode,
|
||||
"idEmployee" => $idEmployee,
|
||||
"email" => $email,
|
||||
"phone" => $phone
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idEmployee
|
||||
* @return Integer
|
||||
*/
|
||||
function getIdPersonByIdEmployee($idEmployee){
|
||||
$stmt = $this->pdo->prepare("SELECT
|
||||
COALESCE((SELECT
|
||||
idPerson
|
||||
FROM
|
||||
employees
|
||||
WHERE
|
||||
id = :idEmployee),
|
||||
0) AS id");
|
||||
|
||||
$stmt->execute(array(':idEmployee' => $idEmployee));
|
||||
$results = $stmt->fetchAll();
|
||||
if(!$results){
|
||||
exit($this->databaseSelectQueryErrorMessage);
|
||||
}
|
||||
$stmt = null;
|
||||
|
||||
return $results[0]['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data associated with the employee
|
||||
*
|
||||
* @param $idEmployee
|
||||
* @return array
|
||||
*/
|
||||
function getEmployeeDataById($idEmployee){
|
||||
$stmt = $this->pdo->prepare("SELECT
|
||||
p.id AS idPerson,
|
||||
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];
|
||||
}
|
||||
|
||||
/**
|
||||
* Acts as a man in the middle for the getEmployeeDataById method to decrypt the contents
|
||||
* and make the necesary data manipulations
|
||||
*
|
||||
* @param $idEmployee
|
||||
* @return array
|
||||
*/
|
||||
function proxyGetEmployeeDataById($idEmployee){
|
||||
$employeeData = $this->getEmployeeDataById($idEmployee);
|
||||
|
||||
$response = array(
|
||||
"idPerson" => (int)$employeeData['idPerson'],
|
||||
"firstName" => $this->cryptographyService->decryptString($employeeData['firstName']),
|
||||
"middleName" => $this->cryptographyService->decryptString($employeeData['middleName']),
|
||||
|
||||
"lastName" => strlen($employeeData['lastName']) > 0
|
||||
? $this->cryptographyService->decryptString($employeeData['lastName'])
|
||||
: '',
|
||||
|
||||
"email" => $this->cryptographyService->decryptString($employeeData['email']),
|
||||
"phone" => $employeeData['phone'],
|
||||
"code" => $employeeData['code'],
|
||||
"contractType" => $employeeData['contractType']
|
||||
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $code string
|
||||
* @return array
|
||||
*/
|
||||
function getEmployeeDataByCode($code){
|
||||
$idEmployee = $this->getIdEmployeeTypeByCode($code);
|
||||
|
||||
return $this->proxyGetEmployeeDataById($idEmployee);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idPerson integer
|
||||
* @param $firstName binary
|
||||
* @param $middleName binary
|
||||
* @param $lastName binary
|
||||
* @param $birthDate date
|
||||
* @param $email binary
|
||||
* @param $phone string
|
||||
*/
|
||||
function updatePerson($idPerson, $firstName, $middleName, $lastName, $birthDate, $email, $phone){
|
||||
try {
|
||||
$stmt = $this->pdo->prepare("UPDATE persons
|
||||
SET
|
||||
firstName = :firstName,
|
||||
middleName = :middleName,
|
||||
lastName = :lastName,
|
||||
birthDate = :birthDate,
|
||||
email = :email,
|
||||
phone = :phone
|
||||
WHERE
|
||||
id = :idPerson");
|
||||
$this->pdo->beginTransaction();
|
||||
$stmt->execute(array(':firstName' => $firstName, ':middleName' => $middleName, ':lastName' => $lastName,
|
||||
':birthDate' => $birthDate, ':email' => $email, ':phone' => $phone, ':idPerson' => $idPerson));
|
||||
$this->pdo->commit();
|
||||
|
||||
$stmt = null;
|
||||
} catch( PDOExecption $e ) {
|
||||
$this->pdo->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idEmployee integer
|
||||
* @param $code string
|
||||
* @param $idEmployeeType integer
|
||||
* @param $contractType string
|
||||
*/
|
||||
function updateEmployee($idEmployee, $code, $idEmployeeType, $contractType){
|
||||
try {
|
||||
$stmt = $this->pdo->prepare("UPDATE employees
|
||||
SET
|
||||
idEmployeeType = :idEmployeeType,
|
||||
code = :code,
|
||||
contractType = :contractType
|
||||
WHERE
|
||||
id = :idEmployee");
|
||||
$this->pdo->beginTransaction();
|
||||
$stmt->execute(array(':idEmployeeType' => $idEmployeeType, ':code' => $code, ':contractType' => $contractType,
|
||||
':idEmployee' => $idEmployee));
|
||||
$this->pdo->commit();
|
||||
|
||||
$stmt = null;
|
||||
} catch( PDOExecption $e ) {
|
||||
$this->pdo->rollback();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $requestData object
|
||||
* @return array
|
||||
*/
|
||||
function updateEmployeeData($requestData){
|
||||
// Getting and validating the data
|
||||
$idEmployee = $requestData['idEmployee'];
|
||||
$idPerson = $this->getIdPersonByIdEmployee($idEmployee);
|
||||
$code = $requestData['code'];
|
||||
|
||||
$firstName = $requestData['firstName'];
|
||||
$this->asserts->firstName($firstName);
|
||||
|
||||
$middleName = $requestData['middleName'];
|
||||
$this->asserts->middleName($middleName);
|
||||
|
||||
$lastName = isset($requestData['lastName']) ? $requestData['lastName'] : null;
|
||||
|
||||
$birthDate = $requestData['birthDate'];
|
||||
$this->asserts->birthDate($birthDate);
|
||||
|
||||
$email = $requestData['email'];
|
||||
$this->asserts->email($email);
|
||||
|
||||
$phone = $requestData['phone'];
|
||||
$this->asserts->phone($phone);
|
||||
|
||||
$idEmployeeType = $requestData{'idEmployeeType'};
|
||||
$contractType = $requestData{'contractType'};
|
||||
|
||||
// Encrypting the sensitive data
|
||||
$securedFirstName = $this->cryptographyService->encryptString($firstName);
|
||||
$securedMiddleName = $this->cryptographyService->encryptString($middleName);
|
||||
|
||||
if (isset($lastName)) {
|
||||
$securedLastName = $this->cryptographyService->encryptString($lastName);
|
||||
} else {
|
||||
$securedLastName = null;
|
||||
}
|
||||
|
||||
$securedEmail = $this->cryptographyService->encryptString($email);
|
||||
|
||||
// Update process
|
||||
$this->updatePerson($idPerson, $securedFirstName, $securedMiddleName, $securedLastName,
|
||||
$birthDate, $securedEmail, $phone);
|
||||
|
||||
$this->updateEmployee($idEmployee, $code, $idEmployeeType, $contractType);
|
||||
|
||||
$response = array(
|
||||
"fullName" => "$firstName $middleName $lastName",
|
||||
"idEmployee" => $idEmployee,
|
||||
"email" => $email,
|
||||
"phone" => $phone,
|
||||
"birthDate" => $birthDate,
|
||||
"idEmployeeType" => $idEmployeeType,
|
||||
"contractType" => $contractType
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
function disableEmployeeRecord($idEmployee){
|
||||
try {
|
||||
$stmt = $this->pdo->prepare("UPDATE employees
|
||||
SET
|
||||
status = 'INACTIVE'
|
||||
WHERE
|
||||
id = :idEmployee");
|
||||
$this->pdo->beginTransaction();
|
||||
$stmt->execute(array(':idEmployee' => $idEmployee));
|
||||
$this->pdo->commit();
|
||||
|
||||
$stmt = null;
|
||||
} catch( PDOExecption $e ) {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -24,6 +24,7 @@ $container['mysql'] = function ($c) {
|
||||
|
||||
// The database parameters
|
||||
$host = $mysqlSettings['host'];
|
||||
$port = $mysqlSettings['port'];
|
||||
$database = $mysqlSettings['database'];
|
||||
$user = $mysqlSettings['user'];
|
||||
$password = $mysqlSettings['password'];
|
||||
@@ -34,7 +35,7 @@ $container['mysql'] = function ($c) {
|
||||
$databaseConnectionErrorMessage = $mysqlSettings['databaseConnectionErrorMessage'];
|
||||
|
||||
// Initiate the connection
|
||||
$dsn = "mysql:host=$host;dbname=$database;charset=$charset";
|
||||
$dsn = "mysql:host=$host;port=$port;dbname=$database;charset=$charset";
|
||||
try {
|
||||
$pdo = new PDO($dsn, $user, $password, $pdoConnectionOptions);
|
||||
} catch (Exception $e) {
|
||||
@@ -62,3 +63,11 @@ $container['sessionApplication'] = function ($c) {
|
||||
$sessionApplication = new App\Application\SessionApplication($c['mysql'], $c['cryptographyService'], $c['asserts']);
|
||||
return $sessionApplication;
|
||||
};
|
||||
|
||||
// The employee application
|
||||
$container['employeeApplication'] = function ($c) {
|
||||
$employeeSettings = $c->get('settings')['employee'];
|
||||
$employeeApplication = new App\Application\EmployeeApplication($employeeSettings,
|
||||
$c['mysql'], $c['cryptographyService'], $c['asserts']);
|
||||
return $employeeApplication;
|
||||
};
|
||||
|
||||
@@ -20,9 +20,9 @@ $app->get('/api/session', function (Request $request, Response $response, array
|
||||
});
|
||||
|
||||
$app->post('/api/session/login', function ($request, $response) {
|
||||
$RequestData = $request->getParsedBody();
|
||||
$requestData = $request->getParsedBody();
|
||||
|
||||
$data = $this->sessionApplication->newSession($RequestData['userName'], $RequestData['password']);
|
||||
$data = $this->sessionApplication->newSession($requestData['userName'], $requestData['password']);
|
||||
|
||||
return $response->withStatus(200)
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
@@ -33,4 +33,64 @@ $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()));
|
||||
});
|
||||
|
||||
$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();
|
||||
|
||||
return $response->withStatus(200)
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->write(json_encode($this->employeeApplication->saveNewEmployee($requestData)));
|
||||
});
|
||||
|
||||
$app->put('/api/employee', function ($request, $response) {
|
||||
$requestData = $request->getParsedBody();
|
||||
|
||||
return $response->withStatus(200)
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->write(json_encode($this->employeeApplication->updateEmployeeData($requestData)));
|
||||
});
|
||||
|
||||
$app->DELETE('/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->disableEmployeeRecord($idEmployee)));
|
||||
});
|
||||
|
||||
$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)));
|
||||
});
|
||||
|
||||
$app->get('/api/employee/id/{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->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)));
|
||||
});
|
||||
@@ -85,4 +85,18 @@ class CryptographyService{
|
||||
function decryptPassword($plainPassword, $encryptedPassword) {
|
||||
return password_verify($plainPassword, $encryptedPassword);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a psudo random string using openssl
|
||||
*
|
||||
* @param $length integer
|
||||
* @return string
|
||||
*/
|
||||
function pseudoRandomStringOpenssl($length){
|
||||
|
||||
$string = openssl_random_pseudo_bytes($length);
|
||||
$string = bin2hex($string);
|
||||
|
||||
return substr($string, 0, $length);
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,8 @@ return [
|
||||
|
||||
// Datanase settings
|
||||
'mysql' => [
|
||||
'host' => 'localhost',
|
||||
'host' => 'mysql',
|
||||
'port' => '3307',
|
||||
'database' => 'payroll',
|
||||
'user' => 'root',
|
||||
'password' => '12345678',
|
||||
@@ -40,5 +41,10 @@ return [
|
||||
'databaseSelectQueryErrorMessage' => 'There was an error fetching the data.',
|
||||
'databaseInsertQueryErrorMessage' => 'There was an error inserting the record.',
|
||||
],
|
||||
|
||||
// Employee settings
|
||||
'employee' => [
|
||||
'codeLength' => '3',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
1
database/.dockerignore
Normal file
1
database/.dockerignore
Normal file
@@ -0,0 +1 @@
|
||||
Dockerfile
|
||||
7
database/Dockerfile
Normal file
7
database/Dockerfile
Normal file
@@ -0,0 +1,7 @@
|
||||
FROM mysql:5.7
|
||||
|
||||
# Starting scripts
|
||||
ADD . /docker-entrypoint-initdb.d
|
||||
|
||||
# Config
|
||||
ADD my.cnf /etc/mysql
|
||||
@@ -16,8 +16,7 @@ CREATE TABLE IF NOT EXISTS `persons` (
|
||||
`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 (`phone`),
|
||||
UNIQUE (`firstName`,`middleName`,`lastName`,`birthDate`)
|
||||
UNIQUE (`phone`)
|
||||
);
|
||||
|
||||
INSERT INTO persons (firstName, middleName, lastName, birthDate, email, phone)
|
||||
@@ -45,3 +44,32 @@ 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');
|
||||
|
||||
DROP TABLE IF EXISTS employees;
|
||||
CREATE TABLE IF NOT EXISTS `employees` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`idEmployeeType` INT UNSIGNED NOT NULL comment 'Defines the rol within the company',
|
||||
`idPerson` INT UNSIGNED NOT NULL comment 'Defines the rol within the company',
|
||||
`code` VARCHAR(100) NOT NULL comment 'A code to reference the employee',
|
||||
`contractType` ENUM('INTERNO', 'EXTERNO') NOT NULL comment 'The type of contract',
|
||||
`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 (`code`)
|
||||
);
|
||||
|
||||
20
database/my.cnf
Normal file
20
database/my.cnf
Normal file
@@ -0,0 +1,20 @@
|
||||
# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; version 2 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
[mysqld]
|
||||
port = 3307
|
||||
|
||||
!includedir /etc/mysql/conf.d/
|
||||
!includedir /etc/mysql/mysql.conf.d/
|
||||
28
docker-compose.yml
Normal file
28
docker-compose.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
version: '3'
|
||||
services:
|
||||
api:
|
||||
container_name: payroll_api
|
||||
build: api-payroll/
|
||||
ports:
|
||||
- "8085:80"
|
||||
volumes:
|
||||
- api-payroll:/var/www/site
|
||||
depends_on:
|
||||
- mysql
|
||||
mysql:
|
||||
container_name: payroll_mysql
|
||||
restart: always
|
||||
build: database
|
||||
expose:
|
||||
- "3307"
|
||||
ports:
|
||||
- "3307:3307"
|
||||
volumes:
|
||||
- my-datavolume:/var/lib/mysql
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: '12345678'
|
||||
MYSQL_USER: 'sloth'
|
||||
MYSQL_PASS: '12345678'
|
||||
volumes:
|
||||
api-payroll:
|
||||
my-datavolume:
|
||||
Reference in New Issue
Block a user