Fixed bugs in blog routes and added doc comments to all route files

Signed-off-by: rodude123 <rodude123@gmail.com>
This commit is contained in:
Rohit Pai 2023-06-09 14:50:20 +01:00
parent e339204bd7
commit e82ec15504
10 changed files with 108 additions and 4 deletions

View File

@ -1,18 +1,33 @@
<?php <?php
namespace api\blog; namespace api\blog;
require_once __DIR__ . "/../utils/routesInterface.php";
require_once "blogData.php";
use api\utils\routesInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\App; use Slim\App;
class blogRoutes implements \api\utils\routesInterface class blogRoutes implements routesInterface
{ {
private blogData $blogData; private blogData $blogData;
/**
* constructor used to instantiate a base blog 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) public function __construct(App $app)
{ {
$this->blogData = new blogData(); $this->blogData = new blogData();
$this->createRoutes($app); $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 public function createRoutes(App $app): void
{ {
// TODO: Implement createRoutes() method. // TODO: Implement createRoutes() method.

3
dist/api/index.php vendored
View File

@ -10,7 +10,9 @@ require "utils/middleware.php";
require "timeline/timelineRoutes.php"; require "timeline/timelineRoutes.php";
require "project/projectRoutes.php"; require "project/projectRoutes.php";
require "user/userRoutes.php"; require "user/userRoutes.php";
require "blog/blogRoutes.php";
use api\blog\blogRoutes;
use api\project\projectRoutes; use api\project\projectRoutes;
use api\timeline\timelineRoutes; use api\timeline\timelineRoutes;
use api\user\userRoutes; use api\user\userRoutes;
@ -30,6 +32,7 @@ new middleware($app);
new timelineRoutes($app); new timelineRoutes($app);
new projectRoutes($app); new projectRoutes($app);
new blogRoutes($app);
new userRoutes($app); new userRoutes($app);
// misc routes // misc routes

View File

@ -11,11 +11,22 @@ use Slim\App;
class projectRoutes implements routesInterface class projectRoutes implements routesInterface
{ {
private projectData $projectData; 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) public function __construct(App $app)
{ {
$this->projectData = new projectData(); $this->projectData = new projectData();
$this->createRoutes($app); $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 public function createRoutes(App $app): void
{ {
$app->get("/projectData", function (Request $request, Response $response) $app->get("/projectData", function (Request $request, Response $response)

View File

@ -11,19 +11,29 @@ use Slim\App;
class timelineRoutes implements routesInterface class timelineRoutes implements routesInterface
{ {
private timelineData $timelineData; 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) public function __construct(App $app)
{ {
$this->timelineData = new timelineData(); $this->timelineData = new timelineData();
$this->createRoutes($app); $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 public function createRoutes(App $app): void
{ {
$app->get("/timelineData/{timeline}", function (Request $request, Response $response, array $args) $app->get("/timelineData/{timeline}", function (Request $request, Response $response, array $args)
{ {
//check if route is available if it is get the data //check if route is available if it is get the data
//otherwise return an error //otherwise return an error
if($args["timeline"] == "edu") if ($args["timeline"] == "edu")
{ {
$response->getBody()->write(json_encode($this->timelineData->getEduData())); $response->getBody()->write(json_encode($this->timelineData->getEduData()));
return $response; return $response;

View File

@ -11,12 +11,22 @@ use Slim\App;
class userRoutes implements routesInterface class userRoutes implements routesInterface
{ {
private userData $user; 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) public function __construct(App $app)
{ {
$this->user = new userData(); $this->user = new userData();
$this->createRoutes($app); $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 public function createRoutes(App $app): void
{ {
$app->post("/user/login", function (Request $request, Response $response) $app->post("/user/login", function (Request $request, Response $response)

View File

@ -1,12 +1,33 @@
<?php <?php
namespace api\blog; namespace api\blog;
require_once __DIR__ . "/../utils/routesInterface.php";
require_once "blogData.php";
use api\utils\routesInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\App; use Slim\App;
class blogRoutes implements \api\utils\routesInterface class blogRoutes implements routesInterface
{ {
private blogData $blogData;
/**
* constructor used to instantiate a base blog 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->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 public function createRoutes(App $app): void
{ {
// TODO: Implement createRoutes() method. // TODO: Implement createRoutes() method.

View File

@ -10,7 +10,9 @@ require "utils/middleware.php";
require "timeline/timelineRoutes.php"; require "timeline/timelineRoutes.php";
require "project/projectRoutes.php"; require "project/projectRoutes.php";
require "user/userRoutes.php"; require "user/userRoutes.php";
require "blog/blogRoutes.php";
use api\blog\blogRoutes;
use api\project\projectRoutes; use api\project\projectRoutes;
use api\timeline\timelineRoutes; use api\timeline\timelineRoutes;
use api\user\userRoutes; use api\user\userRoutes;
@ -30,6 +32,7 @@ new middleware($app);
new timelineRoutes($app); new timelineRoutes($app);
new projectRoutes($app); new projectRoutes($app);
new blogRoutes($app);
new userRoutes($app); new userRoutes($app);
// misc routes // misc routes

View File

@ -11,11 +11,22 @@ use Slim\App;
class projectRoutes implements routesInterface class projectRoutes implements routesInterface
{ {
private projectData $projectData; 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) public function __construct(App $app)
{ {
$this->projectData = new projectData(); $this->projectData = new projectData();
$this->createRoutes($app); $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 public function createRoutes(App $app): void
{ {
$app->get("/projectData", function (Request $request, Response $response) $app->get("/projectData", function (Request $request, Response $response)

View File

@ -11,19 +11,29 @@ use Slim\App;
class timelineRoutes implements routesInterface class timelineRoutes implements routesInterface
{ {
private timelineData $timelineData; 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) public function __construct(App $app)
{ {
$this->timelineData = new timelineData(); $this->timelineData = new timelineData();
$this->createRoutes($app); $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 public function createRoutes(App $app): void
{ {
$app->get("/timelineData/{timeline}", function (Request $request, Response $response, array $args) $app->get("/timelineData/{timeline}", function (Request $request, Response $response, array $args)
{ {
//check if route is available if it is get the data //check if route is available if it is get the data
//otherwise return an error //otherwise return an error
if($args["timeline"] == "edu") if ($args["timeline"] == "edu")
{ {
$response->getBody()->write(json_encode($this->timelineData->getEduData())); $response->getBody()->write(json_encode($this->timelineData->getEduData()));
return $response; return $response;

View File

@ -11,12 +11,22 @@ use Slim\App;
class userRoutes implements routesInterface class userRoutes implements routesInterface
{ {
private userData $user; 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) public function __construct(App $app)
{ {
$this->user = new userData(); $this->user = new userData();
$this->createRoutes($app); $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 public function createRoutes(App $app): void
{ {
$app->post("/user/login", function (Request $request, Response $response) $app->post("/user/login", function (Request $request, Response $response)