api-erstellen #1

Merged
TorstenHettstedt merged 52 commits from api-erstellen into master 2021-04-07 13:00:46 +02:00
Showing only changes of commit 2b31e17e14 - Show all commits
@@ -4,6 +4,7 @@ namespace TorstenHettstedt\TimekeepingApi\Controller;
use Exception; use Exception;
use PDO;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use Slim\Psr7\Request; use Slim\Psr7\Request;
use Slim\Psr7\Response; use Slim\Psr7\Response;
@@ -14,13 +15,26 @@ use TorstenHettstedt\TimekeepingApi\Repositories\WorkingHoursYearlyViewRepositor
class WorkingHoursViewController class WorkingHoursViewController
{ {
protected PDO $databases;
/** /**
* @var ContainerInterface * @var ContainerInterface
*/ */
protected ContainerInterface $container; protected ContainerInterface $container;
/**
* WorkingHoursViewController constructor.
*
* @param ContainerInterface $container
*
* @throws NotDatabasesException
*/
public function __construct(ContainerInterface $container) { public function __construct(ContainerInterface $container) {
$this->container = $container; $this->container = $container;
if ($container->has('databases') === false) {
throw new NotDatabasesException('Datenbank ist nicht Vorhanden');
}
$this->databases = $container->get('databases');
} }
/** /**
@@ -31,14 +45,10 @@ class WorkingHoursViewController
* @return Response * @return Response
* *
* @noinspection PhpUnusedParameterInspection * @noinspection PhpUnusedParameterInspection
* @throws NotDatabasesException
* @throws Exception * @throws Exception
*/ */
public function browseWeekly(Request $request, Response $response, array $args): Response public function browseWeekly(Request $request, Response $response, array $args): Response
{ {
if ($this->container->has('databases') === false) {
throw new NotDatabasesException('Datenbank ist nicht Vorhanden');
}
$repository = new WorkingHoursWeeklyViewRepository($this->container->get('databases')); $repository = new WorkingHoursWeeklyViewRepository($this->container->get('databases'));
return $this->printResponse($response, $repository->findAll()); return $this->printResponse($response, $repository->findAll());
} }
@@ -55,9 +65,6 @@ class WorkingHoursViewController
*/ */
public function browseMonthly(Request $request, Response $response, array $args): Response public function browseMonthly(Request $request, Response $response, array $args): Response
{ {
if ($this->container->has('databases') === false) {
throw new NotDatabasesException('Datenbank ist nicht Vorhanden');
}
$repository = new WorkingHoursMonthlyViewRepository($this->container->get('databases')); $repository = new WorkingHoursMonthlyViewRepository($this->container->get('databases'));
return $this->printResponse($response, $repository->findAll()); return $this->printResponse($response, $repository->findAll());
} }
@@ -74,9 +81,6 @@ class WorkingHoursViewController
*/ */
public function browseYearly(Request $request, Response $response, array $args): Response public function browseYearly(Request $request, Response $response, array $args): Response
{ {
if ($this->container->has('databases') === false) {
throw new NotDatabasesException('Datenbank ist nicht Vorhanden');
}
$repository = new WorkingHoursYearlyViewRepository($this->container->get('databases')); $repository = new WorkingHoursYearlyViewRepository($this->container->get('databases'));
return $this->printResponse($response, $repository->findAll()); return $this->printResponse($response, $repository->findAll());
} }