Linked backend with frontend and styled curriculum vitae for mobile
This commit is contained in:
Vendored
+40
-4
@@ -7,17 +7,53 @@ use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Slim\Factory\AppFactory;
|
||||
|
||||
require "routes.php";
|
||||
require "./vendor/autoload.php";
|
||||
//require “routes.php”;
|
||||
require "../vendor/autoload.php";
|
||||
include "timelineData.php";
|
||||
|
||||
// Start slim
|
||||
$app = AppFactory::create();
|
||||
// create middleware
|
||||
$app->addRoutingMiddleware();
|
||||
|
||||
$errorMiddleware = $app->addErrorMiddleware(false, true, true);
|
||||
// for error checking
|
||||
$errorMiddleware = $app->addErrorMiddleware(true, true, true);
|
||||
|
||||
$app->get("/getTimelineData", function (Request $request, Response $response)
|
||||
$app->setBasePath("/api");
|
||||
|
||||
$timelineData = new TimelineData();
|
||||
|
||||
$app->get("/timelineData/{timeline}", function (Request $request, Response $response, array $args)
|
||||
{
|
||||
global $timelineData;
|
||||
$json = $result = "";
|
||||
|
||||
//check if route is available if it is get the data
|
||||
//otherwise return an error
|
||||
if($args["timeline"] == "edu")
|
||||
{
|
||||
$result = $timelineData->getEduData();
|
||||
}
|
||||
else if($args["timeline"] == "work")
|
||||
{
|
||||
$result = $timelineData->getWorkData();
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = array(array("errorMessage" => "Error, timeline data not found"));
|
||||
}
|
||||
|
||||
$json = json_encode($result);
|
||||
|
||||
$response->getBody()->write($json);
|
||||
|
||||
//if it is an error give a 404 code since it can't find the data
|
||||
if(array_key_exists("errorMessage", $result[0]))
|
||||
{
|
||||
$response = $response->withStatus(404);
|
||||
}
|
||||
//use content type json to indicate json data on frontend.
|
||||
return $response->withHeader("Content-Type", "application/json");
|
||||
});
|
||||
|
||||
$app->run();
|
||||
|
||||
Reference in New Issue
Block a user