categoryDao->getCategoryById($categoryId); if ($category === null) { throw new PageNotFoundException(); } else { $this->sendJson($category); } }*/ /** * Gibt den {@see Article} mit der entsprechenden id im JSON Format zurück. * * * * @param int $articleId * @return void * @throws PageNotFoundException if Article could not be found. */ function getDoArticle(int $articleId): void { $article = $this->articleDao->getArticleById($articleId); if ($article === null) { throw new PageNotFoundException(); } else { $this->sendJson($article); } } /** * Diese Methode kannst du im Browser testen. Pfad: localhost/[ordner name vom projekt]/src-php/public/api/articles * * * * @param string|null $categoryName * @return void */ function getDoArticles(?string $categoryName = null): void { if ($categoryName == null) { $articles = $this->articleDao->getArticles(); } else { $articles = $this->articleDao->getArticlesByCategoryName($categoryName); } $this->sendJson($articles); } /** * Speichere einen Artikel. * * * * Nenne die Methode {@see saveArticle(Article $article)} * * @return void * @throws StatusException */ function postDoArticle(ParamBody $body): void { $httpData = $body->parseJsonToHttpData(); $title = $httpData->reqString('title'); $text = $httpData->reqString('text'); $categoryName = $httpData->reqString('categoryName'); if (!$this->isValidArticleCategory($categoryName)) { throw new BadRequestException(); } $articleToAdd = $this->createArticle($title, $text, $categoryName); $this->beginTransaction(); $this->articleDao->saveArticle($articleToAdd); $this->commit(); $this->sendJson($articleToAdd); } /** * Editiere einen Artikel. * * * * @return void * @throws StatusException */ function putDoArticle(int $articleId, ParamBody $body): void { $httpData = $body->parseJsonToHttpData(); $title = $httpData->reqString('title'); $text = $httpData->reqString('text'); $categoryName = $httpData->reqString('categoryName'); if (!$this->isValidArticleCategory($categoryName)) { throw new BadRequestException(); } $article = $this->articleDao->getArticleById($articleId); if ($article === null) { throw new PageNotFoundException(); } $article->categoryName = $categoryName; $article->title = $title; $article->text = $text; $this->beginTransaction(); $this->articleDao->saveArticle($article); $this->commit(); $this->sendJson($article); } /** * Löscht den {@see Article} mit der dazugehörigen Id. * *