api-erstellen #1
@@ -6,6 +6,7 @@ namespace TorstenHettstedt\TimekeepingApi\Controller;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use PDO;
|
use PDO;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
|
use Slim\Exception\HttpInternalServerErrorException;
|
||||||
use Slim\Psr7\Request;
|
use Slim\Psr7\Request;
|
||||||
use Slim\Psr7\Response;
|
use Slim\Psr7\Response;
|
||||||
use TorstenHettstedt\TimekeepingApi\Models\WorkingHoursView;
|
use TorstenHettstedt\TimekeepingApi\Models\WorkingHoursView;
|
||||||
@@ -15,7 +16,7 @@ use TorstenHettstedt\TimekeepingApi\Repositories\WorkingHoursYearlyViewRepositor
|
|||||||
|
|
||||||
class WorkingHoursViewController
|
class WorkingHoursViewController
|
||||||
{
|
{
|
||||||
protected PDO $databases;
|
protected PDO $databases;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ContainerInterface
|
* @var ContainerInterface
|
||||||
@@ -29,7 +30,8 @@ class WorkingHoursViewController
|
|||||||
*
|
*
|
||||||
* @throws NotDatabasesException
|
* @throws NotDatabasesException
|
||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container) {
|
public function __construct(ContainerInterface $container)
|
||||||
|
{
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
|
TorstenHettstedt marked this conversation as resolved
Outdated
|
|||||||
if ($container->has('databases') === false) {
|
if ($container->has('databases') === false) {
|
||||||
throw new NotDatabasesException('Datenbank ist nicht Vorhanden');
|
throw new NotDatabasesException('Datenbank ist nicht Vorhanden');
|
||||||
@@ -44,13 +46,18 @@ class WorkingHoursViewController
|
|||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*
|
*
|
||||||
|
* @throws HttpInternalServerErrorException
|
||||||
* @noinspection PhpUnusedParameterInspection
|
* @noinspection PhpUnusedParameterInspection
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public function browseWeekly(Request $request, Response $response, array $args): Response
|
public function browseWeekly(Request $request, Response $response, array $args): Response
|
||||||
{
|
{
|
||||||
$repository = new WorkingHoursWeeklyViewRepository($this->container->get('databases'));
|
$repository = new WorkingHoursWeeklyViewRepository($this->container->get('databases'));
|
||||||
|
TorstenHettstedt marked this conversation as resolved
Outdated
TorstenHettstedt
commented
Das Verhalten ist in Das Verhalten ist in `WorkingHoursController` besser gelöst.
|
|||||||
return $this->printResponse($response, $repository->findAll());
|
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
|
* @return Response
|
||||||
*
|
*
|
||||||
|
* @throws HttpInternalServerErrorException
|
||||||
* @noinspection PhpUnusedParameterInspection
|
* @noinspection PhpUnusedParameterInspection
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public function browseMonthly(Request $request, Response $response, array $args): Response
|
public function browseMonthly(Request $request, Response $response, array $args): Response
|
||||||
|
TorstenHettstedt marked this conversation as resolved
Outdated
TorstenHettstedt
commented
Das Verhalten ist in Das Verhalten ist in `WorkingHoursController` besser gelöst.
|
|||||||
{
|
{
|
||||||
$repository = new WorkingHoursMonthlyViewRepository($this->container->get('databases'));
|
$repository = new WorkingHoursMonthlyViewRepository($this->container->get('databases'));
|
||||||
return $this->printResponse($response, $repository->findAll());
|
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,22 +88,27 @@ class WorkingHoursViewController
|
|||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*
|
*
|
||||||
|
TorstenHettstedt marked this conversation as resolved
Outdated
TorstenHettstedt
commented
Da in beiden Controllern die fast gleiche Methode aufgerufen wird, kann diese Methode auch in eine Abstrakte Klasse verschoben werden. Da in beiden Controllern die fast gleiche Methode aufgerufen wird, kann diese Methode auch in eine Abstrakte Klasse verschoben werden.
|
|||||||
|
* @throws HttpInternalServerErrorException
|
||||||
* @noinspection PhpUnusedParameterInspection
|
* @noinspection PhpUnusedParameterInspection
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public function browseYearly(Request $request, Response $response, array $args): Response
|
public function browseYearly(Request $request, Response $response, array $args): Response
|
||||||
{
|
{
|
||||||
$repository = new WorkingHoursYearlyViewRepository($this->container->get('databases'));
|
$repository = new WorkingHoursYearlyViewRepository($this->container->get('databases'));
|
||||||
return $this->printResponse($response, $repository->findAll());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Response $response
|
* @param Response $response
|
||||||
* @param WorkingHoursView[] $data
|
* @param WorkingHoursView[] $data
|
||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
protected function printResponse( Response $response, array $data): Response
|
protected function printResponse(Response $response, array $data): Response
|
||||||
{
|
{
|
||||||
$payload = json_encode($data);
|
$payload = json_encode($data);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user
Das Verhalten ist in
WorkingHoursControllerbesser gelöst.