Skip to content

Commit

Permalink
Merge branch 'master' into php-8
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	composer.lock
#	migrations/db-config.php
  • Loading branch information
Daniel Lima committed Jan 13, 2021
2 parents 415052d + e133ba4 commit fbc598e
Show file tree
Hide file tree
Showing 26 changed files with 253 additions and 69 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/continuous-delivery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: CD

on:
push:
branches: [ master, feature/**, bugfix/** ]
pull_request:
branches: [ master ]
env:
COVERAGE: '0'

jobs:
phpunit:
name: PHPUnit (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
services:
mysql:
image: bitnami/mysql:5.7
env:
ALLOW_EMPTY_PASSWORD: false
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: cafe-db
MYSQL_AUTHENTICATION_PLUGIN: mysql_native_password
ports:
- 3306/tcp
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
strategy:
matrix:
php:
- '7.4'
#- '8.0'
include:
- php: '7.4'
coverage: xdebug
fail-fast: false
steps:
- uses: actions/checkout@v2
- name: setup-php
id: setup-php
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: intl, bcmath, curl, openssl, mbstring
ini-values: memory_limit=-1
tools: composer
coverage: ${{ matrix.coverage }}
- name: Install Composer dependencies
run: composer install --no-interaction --no-progress --ansi
- name: Enable code coverage for PHP-7.4
if: ${{ matrix.php == '7.4' }}
run: echo "COVERAGE=1" >> $GITHUB_ENV
- name: Run Migration
run: vendor/bin/doctrine-migrations migrations:migrate --configuration migrations/migrations-config.php --db-configuration migrations/db-config.php --no-interaction --ansi || echo "No migrations found or migration failed"
env:
CAFE_DATABASE_URL: mysql://root:password@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/cafe-db?serverVersion=5.7&charset=UTF8
- name: Run PHPUnit tests
run: |
mkdir -p reports/phpunit
if [ "$COVERAGE" = '1' ]; then
vendor/bin/phpunit --coverage-clover reports/phpunit/clover.xml --log-junit reports/phpunit/junit.xml --colors=always
else
vendor/bin/phpunit --colors=always
fi
env:
CAFE_DATABASE_URL: mysql://root:password@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/cafe-db?serverVersion=5.7&charset=UTF8
- name: Upload coverage results to Codecov
if: matrix.coverage
uses: codecov/codecov-action@v1
with:
directory: ./reports/phpunit/
name: phpunit-php${{ matrix.php }}
flags: phpunit
fail_ci_if_error: true
continue-on-error: true
77 changes: 77 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
SHELL=/bin/bash

ifndef PHP_DOCKER_COMMAND
PHP_DOCKER_COMMAND=docker-compose exec php-fpm
endif

# Mute all `make` specific output. Comment this out to get some debug information.
.SILENT:

.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'



.PHONY: up
up: ## start docker containers
- docker-compose up -d

.PHONY: down
down: ## stop docker containers
- docker-compose down -v

.PHONY: status
status: ## List containers
- docker-compose ps



.PHONY: install-dependencies
install-dependencies: ## Run composer install
- ${PHP_DOCKER_COMMAND} composer install

.PHONY: migrations-run
migrations-run: ## Run database migrations
- ${PHP_DOCKER_COMMAND} vendor/bin/doctrine-migrations migrations:migrate --configuration migrations/migrations-config.php --db-configuration migrations/db-config.php --no-interaction --ansi

.PHONY: prune
prune: ## Delete cache and log files
- ${MAKE} prune-cache
- ${MAKE} prune-logs

.PHONY: prune-all
prune-all: ## Delete vendor folder, cache and log files
- sudo rm -fR vendor/*
- ${MAKE} prune-cache
- ${MAKE} prune-logs


.PHONY: prune-cache
prune-cache:
- ${PHP_DOCKER_COMMAND} rm -fR var/cache/*

.PHONY: prune-logs
prune-logs:
- ${PHP_DOCKER_COMMAND} rm -fR var/log/*



.PHONY: test
test: ## Run phpunit
- ${PHP_DOCKER_COMMAND} vendor/bin/phpunit

# TODO STATIC ANALYSE
#.PHONY: analyse
#analyse: ## Run static analyse
# - ${PHP_DOCKER_COMMAND} ...dev tool command

# TODO CODE STYLE CHECK
#.PHONY: cs
#cs: ## Check code style
# - ${PHP_DOCKER_COMMAND} ...dev tool command --dry-run

# TODO CODE STYLE FIX
#.PHONY: cs-fix
#cs-fix: ## Fix code style
# - ${PHP_DOCKER_COMMAND} ...dev tool command
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,31 @@ Finally, the visitors close the tab by paying what is owed, possibly with a tip
Upon closing a tab, it must be paid for in full. A tab with unserved items cannot be closed unless the items are either
marked as served or cancelled first.

### Screenshots
![Screenshot](screenshots/1-home.png)
![Screenshot](screenshots/2-opening-tab.png)
![Screenshot](screenshots/3-ordering.png)
![Screenshot](screenshots/4-tab-status.png)
![Screenshot](screenshots/5-chef-todo.png)
![Screenshot](screenshots/5-chef-todo.png)
![Screenshot](screenshots/7-home-some-opened.png)
![Screenshot](screenshots/8-status-2.png)
![Screenshot](screenshots/9-cant-close-tab.png)
![Screenshot](screenshots/10-closing-tab.png)

### Requirements
- Docker

### Installation
- Clone this repository: `git clone git@github.com:yourwebmaker/cqrs.nu-php.git`
- Install the containers: `docker-compose up -d`
- Access the container: `docker exec -it cafe-fpm bash`
- Install dependencies: `composer install`
- Setup database: `php migrations/doctrine-migrations.phar migrations:migrate --configuration migrations/migrations-config.php --db-configuration migrations/db-config.php --no-interaction`
- Start the containers: `make up`
- Install dependencies: `make install-dependencies`
- Setup database: `make migrations-run`
- Open your browser on `http://0.0.0.0:8001/tab/open`

### Usage
- See full commands list `make help`
- Access the container: `docker exec -it cafe-fpm bash`

### Testing
- Inside the container: `vendor/bin/phpunit tests`
- Run command: `make test`
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"symfony/form": "5.1.*",
"symfony/framework-bundle": "5.1.*",
"symfony/twig-bundle": "5.1.*",
"symfony/yaml": "5.1.*"
"symfony/yaml": "5.1.*",
"twig/intl-extra": "^3.1"
},
"require-dev": {
"phpunit/phpunit": "^9.3",
Expand Down
3 changes: 3 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ services:

# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones

Twig\Extra\Intl\IntlExtension:
tags: [ twig.extension ]
3 changes: 1 addition & 2 deletions migrations/db-config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

return [
//todo use dotenv
'url' => 'mysql://cafe-user:cafe-pass@cafe-mysql/cafe-db?charset=UTF8'
'url' => getenv('CAFE_DATABASE_URL')
];
8 changes: 8 additions & 0 deletions public/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
.container-fluid {
margin-top: 15px;
}

.open-table {
border: 1px solid black;
text-align: center;
font-size: xxx-large;
margin-bottom: 30px;
border-radius: 10px;
}
Binary file added screenshots/1-home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/10-closing-tab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/2-opening-tab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/3-ordering.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/4-tab-status.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/5-chef-todo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/6-chef-todo-all-prepared.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/7-home-some-opened.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/8-status-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/9-cant-close-tab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions src/Infra/Read/OpenTabsQueriesDBAL.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ public function __construct(Connection $connection)
*/
public function activeTableNumbers(): array
{
$sql = 'select table_number from read_model_tab';
$tableNumbers = $this->connection->fetchNumeric($sql);
$sql = 'select table_number from read_model_tab order by table_number asc';

$tableNumbers = $this->connection->fetchFirstColumn($sql);

if (! $tableNumbers) {
return [];
Expand Down
12 changes: 1 addition & 11 deletions src/UserInterface/Web/Templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@
</head>
<body>
<nav class="navbar sticky-top navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">Cafe</a>
<a class="navbar-brand" href="{{ path('home') }}">Cafe</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="{{ path('home') }}">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ path('tab_open') }}">Open Tab</a>
</li>
Expand All @@ -43,13 +40,6 @@
{% endfor %}
</ul>
</li>
<li><h6>Open Tabs</h6>
<ul>
{% for tableNumber in activeTables.activeTableNumbers() %}
<li><a href="{{ path('tab_status', {tableNumber : tableNumber}) }}">{{ tableNumber }}</a></li>
{% endfor %}
</ul>
</li>
</ul>
</div>
</nav>
Expand Down
12 changes: 7 additions & 5 deletions src/UserInterface/Web/Templates/chef/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<form action="{{ path('chef_markprepared') }}" method="post">
<input hidden value="{{ group.groupId }}" name="groupId"/>
<input hidden value="{{ group.tabId }}" name="tabId"/>
<table class="table">
<thead>
<table class="table table-bordered">
<thead class="thead-light">
<tr>
<th>Menu #</th>
<th>Description</th>
<th>Prepared</th>
<th scope="col">Menu #</th>
<th scope="col">Description</th>
<th scope="col">Prepared</th>
</tr>
</thead>
<tbody>
Expand All @@ -27,5 +27,7 @@
<button type="submit" class="btn btn-primary" name="mark-prepared">Mark Prepared</button>
<hr />
</form>
{% else %}
<p>No items to prepare</p>
{% endfor %}
{% endblock %}
16 changes: 14 additions & 2 deletions src/UserInterface/Web/Templates/home/home.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
{% extends 'base.html.twig' %}
{% block title %}Cafe application{% endblock %}
{% block title %}Open Tabs{% endblock %}
{% block content %}
dd
<div class="row row-cols-4">
{% for tableNumber in activeTables.activeTableNumbers() %}
<div class="col">
<div class="open-table">
<a href="{{ path('tab_status', {tableNumber : tableNumber}) }}">{{ tableNumber }}</a>
</div>
</div>
{% else %}
<div class="col">
No open tabs. Please <a href="{{ path('tab_open') }}">open a tab</a> and order.
</div>
{% endfor %}
</div>
{% endblock %}
19 changes: 9 additions & 10 deletions src/UserInterface/Web/Templates/tab/close.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
{% block title %}Close tab{% endblock %}
{% block content %}

<table class="table">

<thead>
<table class="table table-bordered">
<thead class="thead-light">
<tr>
<th>Description</th>
<th>Quantity</th>
<th>Price each</th>
<th>Sub total</th>
<th scope="col">Description</th>
<th scope="col">Quantity</th>
<th scope="col">Price each</th>
<th scope="col">Sub total</th>
</tr>
</thead>

Expand All @@ -18,15 +17,15 @@
<tr>
<td>{{ line.description }}</td>
<td>{{ line.quantity }}</td>
<td>{{ line.priceEach }}</td>
<td>{{ line.subTotal }}</td>
<td>{{ line.priceEach|format_currency('EUR') }}</td>
<td>{{ line.subTotal|format_currency('EUR') }}</td>
</tr>
{% endfor %}
</tbody>

<tfoot>
<tr>
<td colspan="4">Total: {{ invoice.total }}</td>
<td colspan="4"><strong>Total: {{ invoice.total|format_currency('EUR') }}</strong></td>
</tr>
</tfoot>
</table>
Expand Down
14 changes: 7 additions & 7 deletions src/UserInterface/Web/Templates/tab/order.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
{% block content %}
{{ form_start(form) }}
<fieldset>
<table class="table">
<thead>
<tr>
<td>Menu #</td>
<td>Description</td>
<td>Number To Order</td>
</tr>
<table class="table table-bordered">
<thead class="thead-light">
<tr>
<th scope="col">Menu #</th>
<th scope="col">Description</th>
<th scope="col">Number To Order</th>
</tr>
</thead>
<tbody>
{% for item in form.items %}
Expand Down
Loading

0 comments on commit fbc598e

Please sign in to comment.