Eine fehlende Datenbank löst schon in der Erstellung des Objektes einen Fehler aus.

Es wurden noch kleinere Fehler beseitigt.
This commit is contained in:
2021-04-07 12:45:27 +02:00
parent 2b31e17e14
commit 9430f3c74c
@@ -6,6 +6,7 @@ namespace TorstenHettstedt\TimekeepingApi\Controller;
use Exception;
use PDO;
use Psr\Container\ContainerInterface;
use Slim\Exception\HttpInternalServerErrorException;
use Slim\Psr7\Request;
use Slim\Psr7\Response;
use TorstenHettstedt\TimekeepingApi\Models\WorkingHoursView;
@@ -29,7 +30,8 @@ class WorkingHoursViewController
*
* @throws NotDatabasesException
*/
public function __construct(ContainerInterface $container) {
public function __construct(ContainerInterface $container)
{
$this->container = $container;
if ($container->has('databases') === false) {
throw new NotDatabasesException('Datenbank ist nicht Vorhanden');
@@ -44,13 +46,18 @@ class WorkingHoursViewController
*
* @return Response
*
* @throws HttpInternalServerErrorException
* @noinspection PhpUnusedParameterInspection
* @throws Exception
*/
public function browseWeekly(Request $request, Response $response, array $args): Response
{
$repository = new WorkingHoursWeeklyViewRepository($this->container->get('databases'));
try {
return $this->printResponse($response, $repository->findAll());
} catch (Exception $exception) {
throw new HttpInternalServerErrorException($request,
'Der Wert für das Datum oder die Zeit ist falsch in der Datenbank', $exception);
}
}
/**
@@ -60,13 +67,18 @@ class WorkingHoursViewController
*
* @return Response
*
* @throws HttpInternalServerErrorException
* @noinspection PhpUnusedParameterInspection
* @throws Exception
*/
public function browseMonthly(Request $request, Response $response, array $args): Response
{
$repository = new WorkingHoursMonthlyViewRepository($this->container->get('databases'));
try {
return $this->printResponse($response, $repository->findAll());
} catch (Exception $exception) {
throw new HttpInternalServerErrorException($request,
'Der Wert für das Datum oder die Zeit ist falsch in der Datenbank', $exception);
}
}
/**
@@ -76,13 +88,18 @@ class WorkingHoursViewController
*
* @return Response
*
* @throws HttpInternalServerErrorException
* @noinspection PhpUnusedParameterInspection
* @throws Exception
*/
public function browseYearly(Request $request, Response $response, array $args): Response
{
$repository = new WorkingHoursYearlyViewRepository($this->container->get('databases'));
try {
return $this->printResponse($response, $repository->findAll());
} catch (Exception $exception) {
throw new HttpInternalServerErrorException($request,
'Der Wert für das Datum oder die Zeit ist falsch in der Datenbank', $exception);
}
}
/**
@@ -91,7 +108,7 @@ class WorkingHoursViewController
*
* @return Response
*/
protected function printResponse( Response $response, array $data): Response
protected function printResponse(Response $response, array $data): Response
{
$payload = json_encode($data);