Compare commits
17 Commits
updatingEm
...
adaptingMy
| Author | SHA1 | Date | |
|---|---|---|---|
| f16e9fe72c | |||
| d2b9163537 | |||
| 403541580d | |||
| 663ea7cc3e | |||
| f93b41f14e | |||
| 24f1ce1ed7 | |||
| b25346e3d5 | |||
| f2237d9209 | |||
| 7fc9ca8c75 | |||
| 97fca1d7d3 | |||
| 058e19a49a | |||
| bffeb6e9f4 | |||
| 9a3e876afe | |||
| dadea504d0 | |||
| 1390427ec0 | |||
| 6c4e42e337 | |||
| f4d1ce1ab7 |
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`
|
||||
|
||||
|
||||
@@ -269,6 +269,16 @@ class EmployeeApplication{
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $code string
|
||||
* @return array
|
||||
*/
|
||||
function getEmployeeDataByCode($code){
|
||||
$idEmployee = $this->getIdEmployeeTypeByCode($code);
|
||||
|
||||
return $this->proxyGetEmployeeDataById($idEmployee);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idPerson integer
|
||||
* @param $firstName binary
|
||||
@@ -404,5 +414,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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -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) {
|
||||
@@ -69,4 +70,4 @@ $container['employeeApplication'] = function ($c) {
|
||||
$employeeApplication = new App\Application\EmployeeApplication($employeeSettings,
|
||||
$c['mysql'], $c['cryptographyService'], $c['asserts']);
|
||||
return $employeeApplication;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -73,10 +79,18 @@ $app->get('/api/employee/type/{code}', function (Request $request, Response $res
|
||||
->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'];
|
||||
|
||||
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)));
|
||||
});
|
||||
@@ -26,7 +26,8 @@ return [
|
||||
|
||||
// Datanase settings
|
||||
'mysql' => [
|
||||
'host' => 'localhost',
|
||||
'host' => 'mysql',
|
||||
'port' => '3307',
|
||||
'database' => 'payroll',
|
||||
'user' => 'root',
|
||||
'password' => '12345678',
|
||||
@@ -43,7 +44,7 @@ return [
|
||||
|
||||
// Employee settings
|
||||
'employee' => [
|
||||
'codeLength' => '5',
|
||||
'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
|
||||
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