Selaa lähdekoodia

Aufgaben getDoArticle und getDoArticles

Gabriyel Goede 1 kuukausi sitten
vanhempi
sitoutus
70f4f5223e

+ 17 - 16
composer.json

@@ -11,7 +11,6 @@
 		"n2n/n2n-impl-persistence-meta" : "^7.5",
 		"n2n/n2n-impl-persistence-meta" : "^7.5",
 		"n2n/n2n-impl-persistence-orm" : "^7.5",
 		"n2n/n2n-impl-persistence-orm" : "^7.5",
 		"n2n/rocket" : "^3.0",
 		"n2n/rocket" : "^3.0",
-		"n2n/page" : "^1.6",
 		"lcobucci/jwt" : "4.0.4",
 		"lcobucci/jwt" : "4.0.4",
 		"n2n/n2n-bind": "^7.5"
 		"n2n/n2n-bind": "^7.5"
     },
     },
@@ -20,19 +19,21 @@
 		"n2n/n2n-test" : "^7.5",
 		"n2n/n2n-test" : "^7.5",
 		"phpunit/phpunit" : "^9.5.25@stable"
 		"phpunit/phpunit" : "^9.5.25@stable"
 	},
 	},
-	"autoload" : {
-		"psr-4" : {
-			"em\\" : "app/em"
-		}
-	},
-	"autoload-dev" : {
-		"psr-4" : {
-			"em\\" : "app/em"
-		}
-	},
-	"config": {
-		"allow-plugins": {
-			"n2n/n2n-composer-module-installer": true
-		}
-	}
+    "autoload" : {
+        "psr-4" : {
+            "internship\\" : "src-php/app/internship"
+        }
+    },
+    "autoload-dev" : {
+        "psr-4" : {
+            "internship\\" : "src-php/test/internship",
+            "util\\" : "src-php/test/util"
+        }
+    },
+    "config": {
+        "vendor-dir" : "src-php/vendor",
+        "allow-plugins": {
+            "n2n/n2n-composer-module-installer": true
+        }
+    }
 }
 }

+ 1 - 63
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
         "This file is @generated automatically"
     ],
     ],
-    "content-hash": "efbdfd0da539712322ef2d711fa83018",
+    "content-hash": "daf0a259f2427c028366d53e401ff745",
     "packages": [
     "packages": [
         {
         {
             "name": "lcobucci/clock",
             "name": "lcobucci/clock",
@@ -1629,68 +1629,6 @@
             },
             },
             "time": "2026-08-20T16:25:33+00:00"
             "time": "2026-08-20T16:25:33+00:00"
         },
         },
-        {
-            "name": "n2n/page",
-            "version": "1.6.x-dev",
-            "source": {
-                "type": "git",
-                "url": "https://github.com/n2n/page.git",
-                "reference": "aec2f4bd229c9a2bd419b80b008bd38d12f3b32e"
-            },
-            "dist": {
-                "type": "zip",
-                "url": "https://api.github.com/repos/n2n/page/zipball/aec2f4bd229c9a2bd419b80b008bd38d12f3b32e",
-                "reference": "aec2f4bd229c9a2bd419b80b008bd38d12f3b32e",
-                "shasum": ""
-            },
-            "require": {
-                "n2n/n2n-composer-module-installer": "^7.1",
-                "n2n/n2n-web": "^7.3",
-                "n2n/rocket": "^3"
-            },
-            "require-dev": {
-                "n2n/hangar": "^8",
-                "n2n/n2nutil-bootstrap": "^4.3.3",
-                "phpunit/phpunit": "^9.5"
-            },
-            "type": "n2n-module",
-            "autoload": {
-                "psr-4": {
-                    "page\\": "src/app/page"
-                }
-            },
-            "notification-url": "https://packagist.org/downloads/",
-            "license": [
-                "GPL-3.0-or-later"
-            ],
-            "authors": [
-                {
-                    "name": "Andreas von Burg",
-                    "email": "a@von-burg.net",
-                    "homepage": "https://www.von-burg.net/"
-                },
-                {
-                    "name": "Bert Hofmänner",
-                    "email": "hofmaenner@hnm.ch"
-                },
-                {
-                    "name": "Thomas Günther",
-                    "email": "guenther@hnm.ch"
-                }
-            ],
-            "description": "rocket cmf",
-            "homepage": "https://n2n.rocks/",
-            "keywords": [
-                "cmf",
-                "cms",
-                "n2n"
-            ],
-            "support": {
-                "issues": "https://github.com/n2n/page/issues",
-                "source": "https://github.com/n2n/page/tree/1.6.x"
-            },
-            "time": "2025-09-05T11:48:39+00:00"
-        },
         {
         {
             "name": "n2n/rocket",
             "name": "n2n/rocket",
             "version": "3.0.x-dev",
             "version": "3.0.x-dev",

+ 13 - 1
src-php/app/internship/controller/ArticleApiController.php

@@ -6,6 +6,7 @@ use internship\model\ArticleDao;
 use n2n\context\attribute\Inject;
 use n2n\context\attribute\Inject;
 use n2n\web\http\controller\ParamBody;
 use n2n\web\http\controller\ParamBody;
 use internship\bo\Article;
 use internship\bo\Article;
+use n2n\validation\plan\ErrorMap;
 use n2n\web\http\PageNotFoundException;
 use n2n\web\http\PageNotFoundException;
 
 
 /**
 /**
@@ -16,6 +17,10 @@ class ArticleApiController extends ControllerAdapter {
 	#[Inject]
 	#[Inject]
 	private ArticleDao $articleDao;
 	private ArticleDao $articleDao;
 
 
+	function index() {
+		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.
 	 *
 	 *
@@ -44,7 +49,8 @@ class ArticleApiController extends ControllerAdapter {
 	 * @throws PageNotFoundException if Article could not be found.
 	 * @throws PageNotFoundException if Article could not be found.
 	 */
 	 */
 	function getDoArticle(int $articleId): void {
 	function getDoArticle(int $articleId): void {
-
+		$article = $this->articleDao->getArticleById($articleId);
+		$this->sendJson($article);
 	}
 	}
 
 
 	/**
 	/**
@@ -67,6 +73,12 @@ class ArticleApiController extends ControllerAdapter {
 	 * @return void
 	 * @return void
 	 */
 	 */
 	function getDoArticles(?string $categoryName = null): void {
 	function getDoArticles(?string $categoryName = null): void {
+		if($categoryName === null) {
+			$articles = $this->articleDao->getArticles();
+		} else { 
+			$articles = $this->articleDao->getArticlesByCategoryName($categoryName);
+		} 
+		$this->sendJson($articles);
 	}
 	}
 
 
 	/**
 	/**

+ 40 - 0
src-php/app/internship/controller/ExampleController.php

@@ -0,0 +1,40 @@
+<?php
+namespace internship\controller;
+
+use n2n\web\http\controller\ControllerAdapter;
+use n2n\web\http\controller\ParamQuery;
+use n2n\reflection\annotation\AnnoInit;
+use n2n\web\http\annotation\AnnoPath;
+use n2n\web\http\annotation\AnnoExt;
+class ExampleController extends ControllerAdapter { 
+	private static function _annos(AnnoInit $ai) {
+        $ai->m('detail4', new AnnoPath('param1:#^\W+$#/fufgg/param2:*'));
+		$ai->m('number', new AnnoPath('param:#^[0-9]$#'), new AnnoExt('txt', 'html'));
+    }  
+
+    public function index() {
+        echo 'hallo atusch';
+    }
+
+	public function doDetail() {
+		echo "Hallo atusch hallo";
+	}
+	
+	public function doDetail1(ParamQuery $param1, ParamQuery $param2) {
+        echo 'param1: ' . $param1 . ' param2: ' . $param2;
+    }
+
+	public function doDetail2($param1, $extension) {
+		echo 'param1: ' . $param1 . ' extension: ' . $extension;
+	}
+
+	public function doDetail3($param1, array $params = array()) {
+    	echo 'param1: ' . $param1 . ' params: ' . implode(', ', $params);
+	}
+
+
+	public function detail4($param1, $param2) {
+        echo 'param100: ' . $param1 . ' params2: ' . $param2;
+    }
+
+}

+ 15 - 1
src-php/app/internship/model/ArticleDao.php

@@ -4,6 +4,7 @@ namespace internship\model;
 use n2n\persistence\orm\EntityManager;
 use n2n\persistence\orm\EntityManager;
 use internship\bo\Article;
 use internship\bo\Article;
 use n2n\context\attribute\RequestScoped;
 use n2n\context\attribute\RequestScoped;
+use n2n\persistence\Pdo;
 
 
 /**
 /**
  * Benutze diese Klasse um Datenbankabfragen auszuführen.
  * Benutze diese Klasse um Datenbankabfragen auszuführen.
@@ -13,9 +14,11 @@ use n2n\context\attribute\RequestScoped;
 #[RequestScoped]
 #[RequestScoped]
 class ArticleDao {
 class ArticleDao {
 	private EntityManager $em;
 	private EntityManager $em;
+	private Pdo $pdo;
 
 
 	private function _init(EntityManager $em): void {
 	private function _init(EntityManager $em): void {
 		$this->em = $em;
 		$this->em = $em;
+		$this->pdo = $em->getPdo();
 	}
 	}
 
 
 	/**
 	/**
@@ -24,6 +27,8 @@ class ArticleDao {
 	 * @return Article[]
 	 * @return Article[]
 	 */
 	 */
 	function getArticles(): array {
 	function getArticles(): array {
+		$criteria = $this->em->createSimpleCriteria(Article::getClass());
+		return $criteria->toQuery()->fetchArray();
 
 
 	}
 	}
 
 
@@ -33,7 +38,8 @@ class ArticleDao {
 	 * @return array
 	 * @return array
 	 */
 	 */
 	function getArticlesByCategoryName(string $categoryName): array {
 	function getArticlesByCategoryName(string $categoryName): array {
-
+		$criteria = $this->em->createSimpleCriteria(Article::getClass(), ['categoryName' => $categoryName ]);
+		return $criteria->toQuery()->fetchArray();
 	}
 	}
 
 
 	/**
 	/**
@@ -43,6 +49,14 @@ class ArticleDao {
 	 * @return Article|null
 	 * @return Article|null
 	 */
 	 */
 	function getArticleById(int $id): ?Article {
 	function getArticleById(int $id): ?Article {
+		return $this->em->find(Article::getClass(), $id);
+
+		$criteria = $this->em->createSimpleCriteria(Article::getClass(),['id'=> $id]);
+		return $criteria->toQuery()->fetchSingle();
 
 
 	}
 	}
+
+	//function getArticleRowById(int $id): array {
+	//	$this->pdo->prepare('SELECT...'),
+	//}
 }
 }

+ 2 - 1
src-php/public/assets/.gitignore

@@ -1,4 +1,5 @@
 /n2n-impl-web-ui
 /n2n-impl-web-ui
 /n2n-impl-web-dispatch
 /n2n-impl-web-dispatch
 /n2n
 /n2n
-/n2n-web
+/n2n-web
+/rocket

+ 3 - 1
src-php/var/etc/.gitignore

@@ -3,4 +3,6 @@
 /n2n
 /n2n
 /n2n-web
 /n2n-web
 /n2n-impl-persistence-orm
 /n2n-impl-persistence-orm
-/n2n-persistence
+/n2n-persistence
+/n2n-batch
+/rocket

+ 1 - 0
src-php/var/etc/internship/app.ini

@@ -1,5 +1,6 @@
 [routing]
 [routing]
 controllers[/] = "internship\controller\IsRootController"
 controllers[/] = "internship\controller\IsRootController"
+controllers[] = "/example > internship\\controller\\ExampleController"
 
 
 [orm]
 [orm]
 entities[] = "internship\bo\Article"
 entities[] = "internship\bo\Article"