|
|
@@ -75,30 +75,12 @@ class ArticleApiController extends ControllerAdapter {
|
|
|
*/
|
|
|
function getDoArticles(?string $categoryName = null): void {
|
|
|
if ($categoryName == null) {
|
|
|
- $articlesToShow = $this->articleDao->getArticles();
|
|
|
+ $articles = $this->articleDao->getArticles();
|
|
|
} else {
|
|
|
- $articlesToShow = $this->articleDao->getArticlesByCategoryName($categoryName);
|
|
|
+ $articles = $this->articleDao->getArticlesByCategoryName($categoryName);
|
|
|
}
|
|
|
|
|
|
- echo $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);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -123,34 +105,23 @@ class ArticleApiController extends ControllerAdapter {
|
|
|
* @throws StatusException
|
|
|
*/
|
|
|
function postDoArticle(ParamBody $body): void {
|
|
|
-
|
|
|
$httpData = $body->parseJsonToHttpData();
|
|
|
$title = $httpData->reqString('title');
|
|
|
$categoryName = $httpData->reqString('categoryName');
|
|
|
$text = $httpData->reqString('text');
|
|
|
/*die();*/
|
|
|
|
|
|
- $isValidCategory = $this->isValidArticleCategory($categoryName);
|
|
|
-
|
|
|
- if ($isValidCategory) {
|
|
|
-
|
|
|
- $articleToAdd = $this->prepareArticle($categoryName, $title, $text);
|
|
|
-
|
|
|
- //$this->beginTransaction();
|
|
|
- $this->articleDao->saveArticle($articleToAdd);
|
|
|
- //$this->commit();
|
|
|
-
|
|
|
- } else {
|
|
|
+ if (!$this->isValidArticleCategory($categoryName)) {
|
|
|
throw new BadRequestException();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- //var_dump($body->parseJson());
|
|
|
|
|
|
- /*
|
|
|
- $httpData = $body->parseJsonToHttpData();
|
|
|
- var_dump($httpData->reqString('title'));
|
|
|
- die();
|
|
|
- */
|
|
|
+ $articleToAdd = $this->prepareArticle($categoryName, $title, $text);
|
|
|
+
|
|
|
+ $this->beginTransaction();
|
|
|
+ $this->articleDao->saveArticle($articleToAdd);
|
|
|
+ $this->commit();
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -182,20 +153,15 @@ class ArticleApiController extends ControllerAdapter {
|
|
|
$text = $httpData->reqString('text');
|
|
|
/*die();*/
|
|
|
|
|
|
- $isValidCategory = $this->isValidArticleCategory($categoryName);
|
|
|
-
|
|
|
- if ($isValidCategory) {
|
|
|
-
|
|
|
- $articleToAdd = $this->prepareArticle($categoryName, $title, $text);
|
|
|
-
|
|
|
- //$this->beginTransaction();
|
|
|
- $this->articleDao->saveArticle($articleToAdd);
|
|
|
- //$this->commit();
|
|
|
-
|
|
|
- } else {
|
|
|
+ if (!$this->isValidArticleCategory($categoryName)) {
|
|
|
throw new BadRequestException();
|
|
|
}
|
|
|
|
|
|
+ $articleToAdd = $this->prepareArticle($categoryName, $title, $text);
|
|
|
+
|
|
|
+ $this->beginTransaction();
|
|
|
+ $this->articleDao->saveArticle($articleToAdd);
|
|
|
+ $this->commit();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -217,7 +183,7 @@ class ArticleApiController extends ControllerAdapter {
|
|
|
* Überprüft, ob die Article Category einen gültigen Wert enthält.
|
|
|
* @return boolean
|
|
|
*/
|
|
|
- function isValidArticleCategory($category){
|
|
|
+ function isValidArticleCategory($category): bool {
|
|
|
$categories = array('international', 'national', 'sport');
|
|
|
return in_array($category, $categories);
|
|
|
}
|