Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM webdevops/php-nginx:7.2

RUN pecl install xdebug-2.9.8 && docker-php-ext-enable xdebug
43 changes: 43 additions & 0 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: '3.1'
services:
apache2:
container_name: docker_apache2_php
build: .
ports:
- 80:80
- 443:443
volumes:
- ../:/app/
depends_on:
- mariadb
links:
- mariadb
environment:
PHP_IDE_CONFIG: 'serverName=postman'
XDEBUG_CONFIG: 'remote_mode=req remote_enable=1 remote_connect_back=0 remote_autostart=1 remote_host=172.17.0.1 remote_port=9000 idekey=PHPSTORM'
restart: always
networks:
zssn_net:
ipv4_address: 12.7.0.4
mariadb:
image: mariadb
restart: always
environment:
MYSQL_DATABASE: 'zssn'
MYSQL_ROOT_PASSWORD: 'root'
ports:
- '3307:3306'
expose:
- '3307'
volumes:
- ./db:/var/lib/mysql
- ./dumps/db.sql:/usr/db.sql
networks:
zssn_net:
ipv4_address: 12.7.0.5
networks:
zssn_net:
driver: bridge
ipam:
config:
- subnet: 12.7.0.0/16
101 changes: 101 additions & 0 deletions .docker/dumps/db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
SQLyog Ultimate v13.1.2 (64 bit)
MySQL - 10.5.9-MariaDB-1:10.5.9+maria~focal : Database - zssn
*********************************************************************
*/

/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`zssn` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;

USE `zssn`;

/*Table structure for table `inventory` */

DROP TABLE IF EXISTS `inventory`;

CREATE TABLE `inventory` (
`id_inventory` int(11) NOT NULL AUTO_INCREMENT,
`id_survivor` int(11) DEFAULT NULL,
`item` text DEFAULT NULL,
`qty` int(11) DEFAULT NULL,
PRIMARY KEY (`id_inventory`),
KEY `id_survivor` (`id_survivor`),
CONSTRAINT `inventory_ibfk_1` FOREIGN KEY (`id_survivor`) REFERENCES `survivors` (`id_survivor`)
) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=utf8mb4;

/*Data for the table `inventory` */

insert into `inventory`(`id_inventory`,`id_survivor`,`item`,`qty`) values
(27,42,'water',6),
(28,42,'food',0),
(29,42,'medication',3),
(30,42,'ammunition',0),
(31,43,'water',2),
(32,43,'food',0),
(33,43,'medication',5),
(34,43,'ammunition',3),
(35,44,'water',0),
(36,44,'food',5),
(37,44,'medication',2),
(38,44,'ammunition',5),
(39,45,'water',8),
(40,45,'food',1),
(41,45,'medication',0),
(42,45,'ammunition',4),
(43,46,'water',1),
(44,46,'food',1),
(45,46,'medication',2),
(46,46,'ammunition',4);

/*Table structure for table `survivors` */

DROP TABLE IF EXISTS `survivors`;

CREATE TABLE `survivors` (
`id_survivor` int(11) NOT NULL AUTO_INCREMENT,
`name` text DEFAULT NULL,
`age` int(11) DEFAULT NULL,
`gender` text DEFAULT NULL,
`location` text DEFAULT NULL,
`infected` smallint(6) DEFAULT NULL,
`reported` smallint(6) DEFAULT NULL,
PRIMARY KEY (`id_survivor`)
) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=utf8mb4;

/*Data for the table `survivors` */

insert into `survivors`(`id_survivor`,`name`,`age`,`gender`,`location`,`infected`,`reported`) values
(42,'testerino',12,'male','+1234/+8901',0,0),
(43,'testerina',39,'female','-9298338/+1234900',0,0),
(44,'gigi',17,'female','+12345/-14',0,6),
(45,'gigi2',98,'male','+4321/+9382',0,2),
(46,'franco',24,'male','+0391/+933838',0,0);

/*Table structure for table `trade_points` */

DROP TABLE IF EXISTS `trade_points`;

CREATE TABLE `trade_points` (
`item` text DEFAULT NULL,
`points` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

/*Data for the table `trade_points` */

insert into `trade_points`(`item`,`points`) values
('water',4),
('food',3),
('medication',2),
('ammunition',1);

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
5 changes: 5 additions & 0 deletions .env.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_HOST=mariadb
DB_PORT=3306
DB_DATABASE=zssn
DB_USERNAME=root
DB_PASSWORD=root
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.docker/db
/.env
/vendor
20 changes: 20 additions & 0 deletions HOW_TO_RUN_PROJECT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## How to run project
1. From project root: `composer install`
2. `composer dump-autoload -o`
3. `cp .env.docker .env`
4. `cd .docker/`
5. `docker-compose up -d`
6. Connect to Mariadb Docker image:
`docker exec -it $(docker ps -qf expose=3306) bash`
7. Import db to mariadb:
`mysql -uroot -proot zssn < /usr/db.sql`
8. Once it's done, you can `exit` from machine
9. Import ./ZSSN.postman_collection.json file into your Postman app
10. If it's all done, you can try api calls from postman
11. You can connect to the database using this parameters:
* DB_HOST=127.0.0.1
* DB_PORT=3307
* DB_DATABASE=zssn
* DB_USERNAME=root
* DB_PASSWORD=root

210 changes: 210 additions & 0 deletions ZSSN.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
{
"info": {
"_postman_id": "b417f438-139c-4071-b6d3-d6c3faf8d2e0",
"name": "ZSSN",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "addSurvivor",
"request": {
"method": "POST",
"header": [
{
"key": "name",
"value": "ciccio",
"type": "text"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "name",
"value": "franco",
"type": "text"
},
{
"key": "age",
"value": "24",
"type": "text"
},
{
"key": "gender",
"value": "male",
"type": "text"
},
{
"key": "location",
"value": "+0391/+933838",
"type": "text"
},
{
"key": "water",
"value": "1",
"type": "text"
},
{
"key": "food",
"value": "1",
"type": "text"
},
{
"key": "medication",
"value": "2",
"type": "text"
},
{
"key": "ammunition",
"value": "4",
"type": "text"
}
]
},
"url": {
"raw": "http://127.0.0.1/api.php/addSurvivor",
"protocol": "http",
"host": [
"127",
"0",
"0",
"1"
],
"path": [
"api.php",
"addSurvivor"
]
}
},
"response": []
},
{
"name": "tradeItems",
"request": {
"method": "PUT",
"header": [
{
"key": "name",
"value": "ciccio",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"buyer\": {\n \"name\": \"gigi\",\n \"water\": \"1\"\n }, \n \"seller\": {\n \"name\": \"testerino\",\n \"food\": \"1\",\n \"ammunition\": \"1\"\n }\n}"
},
"url": {
"raw": "http://127.0.0.1/api.php/tradeItems",
"protocol": "http",
"host": [
"127",
"0",
"0",
"1"
],
"path": [
"api.php",
"tradeItems"
]
}
},
"response": []
},
{
"name": "updateLocation",
"request": {
"method": "PUT",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"name\":\"testerina\",\n \"location\":{\n \"longitude\":\"-093245\",\n \"latitude\":\"+101010\"\n }\n}"
},
"url": {
"raw": "http://127.0.0.1/api.php/updateLocation",
"protocol": "http",
"host": [
"127",
"0",
"0",
"1"
],
"path": [
"api.php",
"updateLocation"
]
}
},
"response": []
},
{
"name": "reportInfected",
"request": {
"method": "PUT",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"name\":\"gigi2\"\n}"
},
"url": {
"raw": "http://127.0.0.1/api.php/reportInfected",
"protocol": "http",
"host": [
"127",
"0",
"0",
"1"
],
"path": [
"api.php",
"reportInfected"
]
}
},
"response": []
},
{
"name": "getInfectedPercentage",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://127.0.0.1/api.php/getInfectedPercentage",
"protocol": "http",
"host": [
"127",
"0",
"0",
"1"
],
"path": [
"api.php",
"getInfectedPercentage"
]
}
},
"response": []
},
{
"name": "getNonInfectedPercentage",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://127.0.0.1/api.php/getNonInfectedPercentage",
"protocol": "http",
"host": [
"127",
"0",
"0",
"1"
],
"path": [
"api.php",
"getNonInfectedPercentage"
]
}
},
"response": []
}
]
}
Loading