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 397416cd31 - Show all commits
@@ -44,13 +44,13 @@ class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWri
public function findAll(): array public function findAll(): array
{ {
$models = []; $models = [];
$stmt = $this->database->prepare('SELECT "Datum" as workingDay, "Arbeitszeit" as workingTime FROM public."Arbeitszeiten"'); $stmt = $this->database->prepare('select "Datum" as workingDay, "Arbeitszeit" as workingTime from public."Arbeitszeiten"');
$stmt->execute(); $stmt->execute();
while ($row = $stmt->fetch()) { while ($row = $stmt->fetch()) {
$model = new WorkingHours(); $model = new WorkingHours();
$model $model
->setWorkingDay(new DateTime($row['workingday'])) ->setWorkingDay(new DateTime($row['workingday']))
->setWorkingTime(new DateInterval('P0000-00-00T'.$row['workingtime'])); ->setWorkingTime(new DateInterval('P0000-00-00T' . $row['workingtime']));
$models[] = $model; $models[] = $model;
} }
return $models; return $models;
@@ -68,7 +68,7 @@ class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWri
*/ */
public function findByKey(mixed $primary_key): WorkingHours public function findByKey(mixed $primary_key): WorkingHours
{ {
$stmt = $this->database->prepare('SELECT "Datum" as workingDay, "Arbeitszeit" as workingTime FROM public."Arbeitszeiten" WHERE "Datum" = ?'); $stmt = $this->database->prepare('select "Datum" as workingDay, "Arbeitszeit" as workingTime from public."Arbeitszeiten" where "Datum" = ?');
$stmt->bindParam(1, $primary_key); $stmt->bindParam(1, $primary_key);
$stmt->execute(); $stmt->execute();
$row = $stmt->fetch(); $row = $stmt->fetch();
@@ -78,7 +78,7 @@ class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWri
$model = new WorkingHours(); $model = new WorkingHours();
$model $model
->setWorkingDay(new DateTime($row['workingday'])) ->setWorkingDay(new DateTime($row['workingday']))
->setWorkingTime(new DateInterval('P0000-00-00T'.$row['workingtime'])); ->setWorkingTime(new DateInterval('P0000-00-00T' . $row['workingtime']));
return $model; return $model;
} }
@@ -101,7 +101,7 @@ class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWri
throw new RepositoryModelAlreadyExists(); throw new RepositoryModelAlreadyExists();
} /** @noinspection PhpUnusedLocalVariableInspection */ } /** @noinspection PhpUnusedLocalVariableInspection */
catch (RepositoryRecordNotFoundException $exception) { catch (RepositoryRecordNotFoundException $exception) {
$stmt = $this->database->prepare('INSERT INTO public."Arbeitszeiten" ("Datum", "Arbeitszeit") values (?, ?) ON CONFLICT DO NOTHING'); $stmt = $this->database->prepare('insert into public."Arbeitszeiten" ("Datum", "Arbeitszeit") values (?, ?) on conflict do nothing');
$stmt->bindParam(1, $workingDay); $stmt->bindParam(1, $workingDay);
$stmt->bindParam(2, $workingTime); $stmt->bindParam(2, $workingTime);
$stmt->execute(); $stmt->execute();
@@ -121,7 +121,7 @@ class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWri
} else { } else {
throw new InvalidArgumentException('Es wird ein Modell der Klasse "' . WorkingHours::class . '" verlangt.'); throw new InvalidArgumentException('Es wird ein Modell der Klasse "' . WorkingHours::class . '" verlangt.');
} }
$stmt = $this->database->prepare('UPDATE public."Arbeitszeiten" SET "Arbeitszeit" = ? WHERE "Datum" = ?'); $stmt = $this->database->prepare('update public."Arbeitszeiten" set "Arbeitszeit" = ? where "Datum" = ?');
$stmt->bindParam(1, $workingTime); $stmt->bindParam(1, $workingTime);
$stmt->bindParam(2, $workingDay); $stmt->bindParam(2, $workingDay);
$stmt->execute(); $stmt->execute();
@@ -142,7 +142,7 @@ class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWri
} else { } else {
throw new InvalidArgumentException('Es wird ein Modell der Klasse "' . WorkingHours::class . '" verlangt.'); throw new InvalidArgumentException('Es wird ein Modell der Klasse "' . WorkingHours::class . '" verlangt.');
} }
$stmt = $this->database->prepare('DELETE FROM public."Arbeitszeiten" WHERE "Datum" = ?'); $stmt = $this->database->prepare('delete from public."Arbeitszeiten" where "Datum" = ?');
$stmt->bindParam(1, $workingDay); $stmt->bindParam(1, $workingDay);
$stmt->execute(); $stmt->execute();
if ($stmt->rowCount() < 1) { if ($stmt->rowCount() < 1) {