From e82ec15504e9ef0873eb1eeba11ad0f3718d3e5d Mon Sep 17 00:00:00 2001 From: rodude123 Date: Fri, 9 Jun 2023 14:50:20 +0100 Subject: [PATCH] Fixed bugs in blog routes and added doc comments to all route files Signed-off-by: rodude123 --- dist/api/blog/blogRoutes.php | 17 ++++++++++++++++- dist/api/index.php | 3 +++ dist/api/project/projectRoutes.php | 11 +++++++++++ dist/api/timeline/timelineRoutes.php | 12 +++++++++++- dist/api/user/userRoutes.php | 10 ++++++++++ src/api/blog/blogRoutes.php | 23 ++++++++++++++++++++++- src/api/index.php | 3 +++ src/api/project/projectRoutes.php | 11 +++++++++++ src/api/timeline/timelineRoutes.php | 12 +++++++++++- src/api/user/userRoutes.php | 10 ++++++++++ 10 files changed, 108 insertions(+), 4 deletions(-) diff --git a/dist/api/blog/blogRoutes.php b/dist/api/blog/blogRoutes.php index c5cb5c4..06cef3f 100644 --- a/dist/api/blog/blogRoutes.php +++ b/dist/api/blog/blogRoutes.php @@ -1,18 +1,33 @@ blogData = new blogData(); $this->createRoutes($app); } + /** + * creates the routes for the blog + * @param App $app - the slim app used to create the routes + * @return void - returns nothing + */ public function createRoutes(App $app): void { // TODO: Implement createRoutes() method. diff --git a/dist/api/index.php b/dist/api/index.php index bab7012..f1f8f4e 100644 --- a/dist/api/index.php +++ b/dist/api/index.php @@ -10,7 +10,9 @@ require "utils/middleware.php"; require "timeline/timelineRoutes.php"; require "project/projectRoutes.php"; require "user/userRoutes.php"; +require "blog/blogRoutes.php"; +use api\blog\blogRoutes; use api\project\projectRoutes; use api\timeline\timelineRoutes; use api\user\userRoutes; @@ -30,6 +32,7 @@ new middleware($app); new timelineRoutes($app); new projectRoutes($app); +new blogRoutes($app); new userRoutes($app); // misc routes diff --git a/dist/api/project/projectRoutes.php b/dist/api/project/projectRoutes.php index e0409e1..5ed6210 100644 --- a/dist/api/project/projectRoutes.php +++ b/dist/api/project/projectRoutes.php @@ -11,11 +11,22 @@ use Slim\App; class projectRoutes implements routesInterface { private projectData $projectData; + + /** + * constructor used to instantiate a base project routes, to be used in the index.php file. + * @param App $app - the slim app used to create the routes + */ public function __construct(App $app) { $this->projectData = new projectData(); $this->createRoutes($app); } + + /** + * creates the routes for the project + * @param App $app - the slim app used to create the routes + * @return void - returns nothing + */ public function createRoutes(App $app): void { $app->get("/projectData", function (Request $request, Response $response) diff --git a/dist/api/timeline/timelineRoutes.php b/dist/api/timeline/timelineRoutes.php index 03cf389..d6ab9d6 100644 --- a/dist/api/timeline/timelineRoutes.php +++ b/dist/api/timeline/timelineRoutes.php @@ -11,19 +11,29 @@ use Slim\App; class timelineRoutes implements routesInterface { private timelineData $timelineData; + + /** + * constructor used to instantiate a base timeline routes, to be used in the index.php file. + * @param App $app - the slim app used to create the routes + */ public function __construct(App $app) { $this->timelineData = new timelineData(); $this->createRoutes($app); } + /** + * creates the routes for the timeline + * @param App $app - the slim app used to create the routes + * @return void - returns nothing + */ public function createRoutes(App $app): void { $app->get("/timelineData/{timeline}", function (Request $request, Response $response, array $args) { //check if route is available if it is get the data //otherwise return an error - if($args["timeline"] == "edu") + if ($args["timeline"] == "edu") { $response->getBody()->write(json_encode($this->timelineData->getEduData())); return $response; diff --git a/dist/api/user/userRoutes.php b/dist/api/user/userRoutes.php index 1bc3114..0511e4d 100644 --- a/dist/api/user/userRoutes.php +++ b/dist/api/user/userRoutes.php @@ -11,12 +11,22 @@ use Slim\App; class userRoutes implements routesInterface { private userData $user; + + /** + * constructor used to instantiate a base user routes, to be used in the index.php file. + * @param App $app - the slim app used to create the routes + */ public function __construct(App $app) { $this->user = new userData(); $this->createRoutes($app); } + /** + * creates the routes for the user + * @param App $app - the slim app used to create the routes + * @return void - returns nothing + */ public function createRoutes(App $app): void { $app->post("/user/login", function (Request $request, Response $response) diff --git a/src/api/blog/blogRoutes.php b/src/api/blog/blogRoutes.php index 1b6494a..06cef3f 100644 --- a/src/api/blog/blogRoutes.php +++ b/src/api/blog/blogRoutes.php @@ -1,12 +1,33 @@ blogData = new blogData(); + $this->createRoutes($app); + } + + /** + * creates the routes for the blog + * @param App $app - the slim app used to create the routes + * @return void - returns nothing + */ public function createRoutes(App $app): void { // TODO: Implement createRoutes() method. diff --git a/src/api/index.php b/src/api/index.php index bab7012..f1f8f4e 100644 --- a/src/api/index.php +++ b/src/api/index.php @@ -10,7 +10,9 @@ require "utils/middleware.php"; require "timeline/timelineRoutes.php"; require "project/projectRoutes.php"; require "user/userRoutes.php"; +require "blog/blogRoutes.php"; +use api\blog\blogRoutes; use api\project\projectRoutes; use api\timeline\timelineRoutes; use api\user\userRoutes; @@ -30,6 +32,7 @@ new middleware($app); new timelineRoutes($app); new projectRoutes($app); +new blogRoutes($app); new userRoutes($app); // misc routes diff --git a/src/api/project/projectRoutes.php b/src/api/project/projectRoutes.php index e0409e1..5ed6210 100644 --- a/src/api/project/projectRoutes.php +++ b/src/api/project/projectRoutes.php @@ -11,11 +11,22 @@ use Slim\App; class projectRoutes implements routesInterface { private projectData $projectData; + + /** + * constructor used to instantiate a base project routes, to be used in the index.php file. + * @param App $app - the slim app used to create the routes + */ public function __construct(App $app) { $this->projectData = new projectData(); $this->createRoutes($app); } + + /** + * creates the routes for the project + * @param App $app - the slim app used to create the routes + * @return void - returns nothing + */ public function createRoutes(App $app): void { $app->get("/projectData", function (Request $request, Response $response) diff --git a/src/api/timeline/timelineRoutes.php b/src/api/timeline/timelineRoutes.php index 03cf389..d6ab9d6 100644 --- a/src/api/timeline/timelineRoutes.php +++ b/src/api/timeline/timelineRoutes.php @@ -11,19 +11,29 @@ use Slim\App; class timelineRoutes implements routesInterface { private timelineData $timelineData; + + /** + * constructor used to instantiate a base timeline routes, to be used in the index.php file. + * @param App $app - the slim app used to create the routes + */ public function __construct(App $app) { $this->timelineData = new timelineData(); $this->createRoutes($app); } + /** + * creates the routes for the timeline + * @param App $app - the slim app used to create the routes + * @return void - returns nothing + */ public function createRoutes(App $app): void { $app->get("/timelineData/{timeline}", function (Request $request, Response $response, array $args) { //check if route is available if it is get the data //otherwise return an error - if($args["timeline"] == "edu") + if ($args["timeline"] == "edu") { $response->getBody()->write(json_encode($this->timelineData->getEduData())); return $response; diff --git a/src/api/user/userRoutes.php b/src/api/user/userRoutes.php index 1bc3114..0511e4d 100644 --- a/src/api/user/userRoutes.php +++ b/src/api/user/userRoutes.php @@ -11,12 +11,22 @@ use Slim\App; class userRoutes implements routesInterface { private userData $user; + + /** + * constructor used to instantiate a base user routes, to be used in the index.php file. + * @param App $app - the slim app used to create the routes + */ public function __construct(App $app) { $this->user = new userData(); $this->createRoutes($app); } + /** + * creates the routes for the user + * @param App $app - the slim app used to create the routes + * @return void - returns nothing + */ public function createRoutes(App $app): void { $app->post("/user/login", function (Request $request, Response $response)