|
@@ -75,28 +75,12 @@ class ArticleApiController extends ControllerAdapter {
|
|
|
*/
|
|
*/
|
|
|
function getDoArticles(?string $categoryName = null): void {
|
|
function getDoArticles(?string $categoryName = null): void {
|
|
|
if ($categoryName == null) {
|
|
if ($categoryName == null) {
|
|
|
- $articlesToShow = $this->articleDao->getArticles();
|
|
|
|
|
|
|
+ $articles = $this->articleDao->getArticles();
|
|
|
} else {
|
|
} else {
|
|
|
- $articlesToShow = $this->articleDao->getArticlesByCategoryName($categoryName);
|
|
|
|
|
|
|
+ $articles = $this->articleDao->getArticlesByCategoryName($categoryName);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $this->sendJson($articlesToShow);
|
|
|
|
|
-
|
|
|
|
|
- /*
|
|
|
|
|
- $articles = $this->articleDao->getArticles();
|
|
|
|
|
- $articlesToShow = [];
|
|
|
|
|
- if ($categoryName !== null) {
|
|
|
|
|
- foreach ($articles as $article) {
|
|
|
|
|
- if($article->getCategoryName() === $categoryName) {
|
|
|
|
|
- array_push($articlesToShow, $article);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- $articlesToShow = $articles;
|
|
|
|
|
- }
|
|
|
|
|
- $this->sendJson($articlesToShow);
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ $this->sendJson($articles);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -127,20 +111,16 @@ class ArticleApiController extends ControllerAdapter {
|
|
|
$text = $httpData->reqString('text');
|
|
$text = $httpData->reqString('text');
|
|
|
$categoryName = $httpData->reqString('categoryName');
|
|
$categoryName = $httpData->reqString('categoryName');
|
|
|
|
|
|
|
|
- $isValidCategory = $this->isValidArticleCategory($categoryName);
|
|
|
|
|
|
|
+ if (!$this->isValidArticleCategory($categoryName)) {
|
|
|
|
|
+ throw new BadRequestException();
|
|
|
|
|
|
|
|
- if ($isValidCategory) {
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
$articleToAdd = $this->prepareArticle($title, $text, $categoryName);
|
|
$articleToAdd = $this->prepareArticle($title, $text, $categoryName);
|
|
|
|
|
|
|
|
- $this->beginTransaction();
|
|
|
|
|
- $this->articleDao->saveArticle($articleToAdd);
|
|
|
|
|
- $this->commit();
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- throw new BadRequestException();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ $this->beginTransaction();
|
|
|
|
|
+ $this->articleDao->saveArticle($articleToAdd);
|
|
|
|
|
+ $this->commit();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -208,7 +188,7 @@ class ArticleApiController extends ControllerAdapter {
|
|
|
* Überprüft, ob die Article Category einen gültigen Wert enthält.
|
|
* Überprüft, ob die Article Category einen gültigen Wert enthält.
|
|
|
* @return boolean
|
|
* @return boolean
|
|
|
*/
|
|
*/
|
|
|
- function isValidArticleCategory($category){
|
|
|
|
|
|
|
+ function isValidArticleCategory($category): bool {
|
|
|
$categories = array('international', 'national', 'sport');
|
|
$categories = array('international', 'national', 'sport');
|
|
|
return in_array($category, $categories);
|
|
return in_array($category, $categories);
|
|
|
}
|
|
}
|