Skip to content

Commit

Permalink
Merge pull request #9 from fphgov/develop
Browse files Browse the repository at this point in the history
v1.0.1
  • Loading branch information
icetee authored May 12, 2023
2 parents 4246e6a + b5a8b2b commit fa2da53
Show file tree
Hide file tree
Showing 30 changed files with 506 additions and 113 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ APP_NOTIFICATION_FORCE=false

APP_EMAIL_TEMPLATE=/var/www/html/public/email

APP_STAT_TOKEN=_stat_token

RECAPTCHA_SECRET=_from_google_
1 change: 1 addition & 0 deletions .github/workflows/release-develop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,4 @@ jobs:
--set env[10].value=${{ secrets.APP_EMAIL }}
--set env[11].value="${{ secrets.APP_PHONE }}"
--set env[13].value=${{ secrets.RECAPTCHA_SECRET }}
--set env[14].value=${{ secrets.APP_STAT_TOKEN }}
1 change: 1 addition & 0 deletions .github/workflows/release-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,4 @@ jobs:
--set env[10].value=${{ secrets.APP_EMAIL }}
--set env[11].value="${{ secrets.APP_PHONE }}"
--set env[13].value=${{ secrets.RECAPTCHA_SECRET }}
--set env[14].value=${{ secrets.APP_STAT_TOKEN }}
5 changes: 4 additions & 1 deletion config/autoload/app.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
'newsletter' => [
'url' => 'https://hirlevel.budapest.hu/subscr_api.php',
'limit' => 20,
]
],
'stat' => [
'token' => getenv('APP_STAT_TOKEN')
],
],
];
5 changes: 3 additions & 2 deletions config/autoload/dependencies.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
Laminas\Db\Adapter\AdapterInterface::class => Laminas\Db\Adapter\AdapterServiceFactory::class,
\Doctrine\ORM\EntityManagerInterface::class => \Roave\PsrContainerDoctrine\EntityManagerFactory::class,

App\Middleware\AuditMiddleware::class => App\Middleware\AuditMiddlewareFactory::class,
App\Middleware\AccountMiddleware::class => App\Middleware\AccountMiddlewareFactory::class,
App\Middleware\AuditMiddleware::class => App\Middleware\AuditMiddlewareFactory::class,
App\Middleware\AccountMiddleware::class => App\Middleware\AccountMiddlewareFactory::class,
App\Middleware\StatisticsAccountMiddleware::class => App\Middleware\StatisticsAccountMiddlewareFactory::class,

\Middlewares\Recaptcha::class => App\Middleware\RecaptchaMiddlewareFactory::class,

Expand Down
10 changes: 10 additions & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,14 @@
App\Middleware\AccountMiddleware::class,
App\Handler\Vote\AddHandler::class
], 'app.api.vote');

$app->get('/app/api/stat/votes', [
App\Middleware\StatisticsAccountMiddleware::class,
App\Handler\Stat\GetVoteHandler::class
], 'app.api.stat.votes');

$app->get('/app/api/stat/history', [
App\Middleware\StatisticsAccountMiddleware::class,
App\Handler\Stat\GetHistoryHandler::class
], 'app.api.stat.history');
};
62 changes: 0 additions & 62 deletions docker-compose.production.yml

This file was deleted.

2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
db:
image: mysql:5.7
container_name: residential_meeting_db
command: --explicit_defaults_for_timestamp --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
command: --explicit_defaults_for_timestamp --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --event_scheduler=ON
env_file: .env
ports:
- 3306:3306
Expand Down
1 change: 1 addition & 0 deletions docker/config/webapp/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ if [ $MODE = "production" ]; then
fi

mkdir -p data/cache/DoctrineEntityProxy
chmod 777 -R data/cache/DoctrineEntityProxy
1 change: 1 addition & 0 deletions k8s/php/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ if [ $MODE = "production" ]; then
fi

mkdir -p data/cache/DoctrineEntityProxy
chmod 777 -R data/cache/DoctrineEntityProxy
4 changes: 4 additions & 0 deletions src/App/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public function getDependencies(): array
Handler\Question\GetHandler::class => Handler\Question\GetHandlerFactory::class,
Handler\Question\GetAllHandler::class => Handler\Question\GetAllHandlerFactory::class,
Handler\Question\GetNavigationHandler::class => Handler\Question\GetNavigationHandlerFactory::class,
Handler\Stat\GetVoteHandler::class => Handler\Stat\GetVoteHandlerFactory::class,
Handler\Stat\GetHistoryHandler::class => Handler\Stat\GetHistoryHandlerFactory::class,
Model\VoteExportModel::class => Model\VoteExportModelFactory::class,
Model\StatExportModel::class => Model\StatExportModelFactory::class,
Service\AccountServiceInterface::class => Service\AccountServiceFactory::class,
Service\MailQueueServiceInterface::class => Service\MailQueueServiceFactory::class,
Service\UserServiceInterface::class => Service\UserServiceFactory::class,
Expand Down
2 changes: 1 addition & 1 deletion src/App/src/Entity/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Question implements QuestionInterface
* @ORM\Column(name="id", type="integer", options={"unsigned"=true})
* @ORM\GeneratedValue(strategy="IDENTITY")
*
* @Groups({"list", "option", "detail", "full_detail", "navigation"})
* @Groups({"list", "option", "detail", "stat", "full_detail", "navigation"})
*/
protected int $id;

Expand Down
72 changes: 72 additions & 0 deletions src/App/src/Entity/Stat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

namespace App\Entity;

use App\Traits\EntityTrait;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
* @ORM\Entity(repositoryClass="App\Repository\StatRepository")
* @ORM\Table(name="stats")
*/
class Stat implements StatInterface
{
use EntityTrait;

/**
* @ORM\Column(name="date", type="date")
*
* @Groups({"stat", "full_detail"})
*/
private DateTime $date;

/**
* @ORM\Id
* @ORM\Column(name="day", type="integer", options={"unsigned"=true})
* @ORM\GeneratedValue(strategy="IDENTITY")
*
* @Groups({"stat", "full_detail"})
*/
private int $day;

/**
* @ORM\Column(name="count", type="integer")
*
* @Groups({"stat", "full_detail"})
*/
private int $count;

public function getDate(): DateTime
{
return $this->date;
}

public function setDate(DateTime $date): void
{
$this->date = $date;
}

public function getDay(): int
{
return $this->day;
}

public function setDay(int $day): void
{
$this->day = $day;
}

public function getCount(): int
{
return $this->count;
}

public function setCount(int $count): void
{
$this->count = $count;
}
}
22 changes: 22 additions & 0 deletions src/App/src/Entity/StatInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Entity;

use DateTime;

interface StatInterface
{
public function getDate(): DateTime;

public function setDate(DateTime $date): void;

public function getDay(): int;

public function setDay(int $day): void;

public function getCount(): int;

public function setCount(int $count): void;
}
8 changes: 5 additions & 3 deletions src/App/src/Entity/Vote.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,29 @@ class Vote implements VoteInterface
* @ORM\Column(name="id", type="integer", options={"unsigned"=true})
* @ORM\GeneratedValue(strategy="IDENTITY")
*
* @Groups({"list", "option", "detail", "full_detail", "vote_list"})
* @Groups({"list", "option", "stat", "detail", "full_detail", "vote_list"})
*/
protected int $id;

/**
* @ORM\ManyToOne(targetEntity="Question", cascade={"persist"})
* @ORM\JoinColumn(name="question_id", referencedColumnName="id", nullable=true)
*
* @Groups({"stat", "full_detail"})
*/
private Question $question;

/**
* @ORM\Column(name="answer", type="boolean", nullable=true)
*
* @Groups({"full_detail"})
* @Groups({"stat", "full_detail"})
*/
private ?bool $answer;

/**
* @ORM\Column(name="zip_code", type="string")
*
* @Groups({"full_detail"})
* @Groups({"stat", "full_detail"})
*/
private string $zipCode;

Expand Down
56 changes: 56 additions & 0 deletions src/App/src/Handler/Stat/GetHistoryHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace App\Handler\Stat;

use App\Model\StatExportModel;
use Laminas\Diactoros\Stream;
use Laminas\Diactoros\Response;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

use function ob_start;
use function ob_get_clean;
use function fopen;
use function fputcsv;
use function rewind;
use function strval;

final class GetHistoryHandler implements RequestHandlerInterface
{
public function __construct(
private StatExportModel $statExportModel,
) {
$this->statExportModel = $statExportModel;
}

public function handle(ServerRequestInterface $request): ResponseInterface
{
$exportData = $this->statExportModel->getCsvData();

ob_start();
ob_get_clean();

$stream = fopen('php://memory', 'wb+');

foreach ($exportData as $fields) {
fputcsv($stream, $fields, ";");
}

rewind($stream);

$body = new Stream($stream);

return new Response($body, 200, [
'Content-Type' => 'text/csv; charset=utf-8',
'Content-Disposition' => "attachment; filename=\"votes.csv\"",
'Content-Description' => 'File Transfer',
'Pragma' => 'public',
'Expires' => '0',
'Cache-Control' => 'must-revalidate',
'Content-Length' => strval($body->getSize()),
]);
}
}
18 changes: 18 additions & 0 deletions src/App/src/Handler/Stat/GetHistoryHandlerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App\Handler\Stat;

use App\Model\StatExportModel;
use Psr\Container\ContainerInterface;

final class GetHistoryHandlerFactory
{
public function __invoke(ContainerInterface $container): GetHistoryHandler
{
return new GetHistoryHandler(
$container->get(StatExportModel::class)
);
}
}
Loading

0 comments on commit fa2da53

Please sign in to comment.