updateArticle - Exeptions

This commit is contained in:
2026-06-02 15:22:18 +02:00
parent af04557f58
commit c6b55030cf
2 changed files with 13 additions and 9 deletions
+7 -1
View File
@@ -1,5 +1,9 @@
<?php <?php
require_once "Article.php"; require_once "Article.php";
class NotFoundException extends Exception {}
class UnauthorizedAccessException extends Exception {}
/** /**
* Die Klasse beinhaltet alle Methoden für die Operation mit den Artikel-Daten. * Die Klasse beinhaltet alle Methoden für die Operation mit den Artikel-Daten.
* *
@@ -29,7 +33,9 @@ interface ArticleManagerDAO
* @param $author * @param $author
* @return void * @return void
* *
* TODO: Fehlerbeschreibung hinzufügen * @throws NotFoundException
* @throws UnauthorizedAccessException
* /
*/ */
public function updateArticle($id, $article, $author); public function updateArticle($id, $article, $author);
+6 -8
View File
@@ -61,18 +61,16 @@ class LocalArticleManager implements ArticleManagerDAO {
$this->saveArticle($articles); $this->saveArticle($articles);
} }
public function updateArticle($id, $article, $author) public function updateArticle($id, $article, $author)
{ {
if (empty($article)) { if (empty($article)) {
// TODO: Implement Exception. throw new InvalidArgumentException("Der Beitrag darf nicht leer sein.");
return;
} }
// Berechtigungsprüfung: // Berechtigungsprüfung:
if ($article->getAuthor() !== $author) { if ($article->getAuthor() !== $author) {
// TODO: Implement Exception. throw new UnauthorizedAccessException("Sie sind nicht berechtigt, diesen Artikel zu bearbeiten.");
return;
} }
// Beitrag aktualisieren: // Beitrag aktualisieren:
@@ -92,15 +90,15 @@ class LocalArticleManager implements ArticleManagerDAO {
]; ];
$updated = true; $updated = true;
break; break;
}else{
// TODO: Implement Exception.
return;
} }
} }
// Nur speichern, wenn Beitrag geändert wurde: // Nur speichern, wenn Beitrag geändert wurde:
if ($updated) { if ($updated) {
$this->saveArticle($articles); $this->saveArticle($articles);
} else {
throw new NotFoundException("Ein Artikel mit der ID". $id . " wurde nicht gefunden.");
} }
} }