|
@@ -10,17 +10,19 @@ use n2n\validation\plan\ErrorMap;
|
|
|
use n2n\web\http\BadRequestException;
|
|
use n2n\web\http\BadRequestException;
|
|
|
use n2n\web\http\PageNotFoundException;
|
|
use n2n\web\http\PageNotFoundException;
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* REST Controller
|
|
* REST Controller
|
|
|
* https://dev.n2n.rocks/de/n2n/docs/rest
|
|
* https://dev.n2n.rocks/de/n2n/docs/rest
|
|
|
*/
|
|
*/
|
|
|
class ArticleApiController extends ControllerAdapter {
|
|
class ArticleApiController extends ControllerAdapter {
|
|
|
#[Inject]
|
|
#[Inject]
|
|
|
- private ArticleDao $articleDao;
|
|
|
|
|
|
|
+ public ArticleDao $articleDao;
|
|
|
|
|
|
|
|
function index() {
|
|
function index() {
|
|
|
echo 'hallo';
|
|
echo 'hallo';
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Gibt den {@see Article} mit der entsprechenden id im JSON Format zurück.
|
|
* Gibt den {@see Article} mit der entsprechenden id im JSON Format zurück.
|
|
@@ -117,26 +119,17 @@ class ArticleApiController extends ControllerAdapter {
|
|
|
* @return void
|
|
* @return void
|
|
|
*/
|
|
*/
|
|
|
function postDoArticle(ParamBody $body): void {
|
|
function postDoArticle(ParamBody $body): void {
|
|
|
- if(!$body === null) {
|
|
|
|
|
- $zwivar1 = $body->parseJson();
|
|
|
|
|
- } else {
|
|
|
|
|
- throw new BadRequestException('Body cant be empty');
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ $bodyData = $body->parseJson();
|
|
|
$this->beginTransaction();
|
|
$this->beginTransaction();
|
|
|
- if(!in_array($zwivar1['categoryName'],['sport','international','national'])) {
|
|
|
|
|
- throw new BadRequestException('The Category must be international, national or sport');
|
|
|
|
|
- }
|
|
|
|
|
- if(!isset($zwivar1['title'])) {
|
|
|
|
|
- throw new BadRequestException('Title must be set');
|
|
|
|
|
- }
|
|
|
|
|
- if(!isset($zwivar1['text'])) {
|
|
|
|
|
- throw new BadRequestException('Article must contain a text');
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ $this->articleDao->BadRequestExceptionIfs($body, 0);
|
|
|
$article = new Article();
|
|
$article = new Article();
|
|
|
- $article->setTitle($zwivar1['title']);
|
|
|
|
|
- $article->setText($zwivar1['text']);
|
|
|
|
|
- $article->setCategoryName($zwivar1['categoryName']);
|
|
|
|
|
|
|
+ $article->setTitle($bodyData['title']);
|
|
|
|
|
+ $article->setText($bodyData['text']);
|
|
|
|
|
+ $article->setCategoryName($bodyData['categoryName']);
|
|
|
$this->articleDao->saveArticle($article);
|
|
$this->articleDao->saveArticle($article);
|
|
|
|
|
|
|
|
$this->commit();
|
|
$this->commit();
|
|
@@ -164,24 +157,7 @@ class ArticleApiController extends ControllerAdapter {
|
|
|
function putDoArticle(int $articleId, ParamBody $body): void {
|
|
function putDoArticle(int $articleId, ParamBody $body): void {
|
|
|
$this->beginTransaction();
|
|
$this->beginTransaction();
|
|
|
$article = $this->articleDao->getArticleById($articleId);
|
|
$article = $this->articleDao->getArticleById($articleId);
|
|
|
- if($article === null) {
|
|
|
|
|
- throw new PageNotFoundException('Article not found');
|
|
|
|
|
- }
|
|
|
|
|
- $zwivar1 = $body->parseJson();
|
|
|
|
|
- if(isset($zwivar1['categoryName'])) {
|
|
|
|
|
- if(!in_array($zwivar1['categoryName'],['sport','international','national'])) {
|
|
|
|
|
- throw new BadRequestException('The Category must be international, national or sport');
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- $article->setCategoryName($zwivar1['categoryName']);
|
|
|
|
|
- }
|
|
|
|
|
- if(isset($zwivar1['text'])) {
|
|
|
|
|
- $article->setText($zwivar1['text']);
|
|
|
|
|
- }
|
|
|
|
|
- if(isset($zwivar1['title'])) {
|
|
|
|
|
- $article->setTitle($zwivar1['title']);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $this->articleDao->BadRequestExceptionIfs($body, $articleId);
|
|
|
$this->articleDao->saveArticle($article);
|
|
$this->articleDao->saveArticle($article);
|
|
|
$this->commit();
|
|
$this->commit();
|
|
|
$this->sendJson($article);
|
|
$this->sendJson($article);
|