Added in ability to add a new project with and without an image
Signed-off-by: rodude123 <rodude123@gmail.com>
This commit is contained in:
Vendored
+36
-7
@@ -1,6 +1,5 @@
|
||||
<?php /** @noinspection PhpIncludeInspection */
|
||||
|
||||
session_start();
|
||||
////////////////// Index file //////////////
|
||||
/// Creates base routes and runs ///
|
||||
/// respective functions ///
|
||||
@@ -216,16 +215,17 @@ $app->get("/projectData", function (Request $request, Response $response)
|
||||
$app->patch("/projectData/{id}", function (Request $request, Response $response, array $args)
|
||||
{
|
||||
global $projectData;
|
||||
if (empty($args["id"] != "undefined"))
|
||||
$data = $request->getParsedBody();
|
||||
if ($args["id"] != "undefined")
|
||||
{
|
||||
if (empty($args["title"]) || empty($args["isMainProject"]) || empty($args["information"]) || empty($args["projectLink"]) || empty($args["githubLink"]))
|
||||
if (empty($data["title"]) || empty($data["isMainProject"]) || empty($data["information"]) || empty($data["projectLink"]) || empty($data["gitLink"]))
|
||||
{
|
||||
// uh oh sent some empty data
|
||||
$response->getBody()->write(json_encode(array("error" => "Only some of the data was sent")));
|
||||
return $response->withStatus(400);
|
||||
}
|
||||
|
||||
if (!$projectData->updateProjectData($args["title"], $args["isMainProject"], $args["information"], $args["projectLink"], $args["githubLink"], $args["id"]))
|
||||
if (!$projectData->updateProjectData($args["id"], $data["title"], $data["isMainProject"], $data["information"], "", $data["projectLink"], $data["gitLink"]))
|
||||
{
|
||||
// uh oh something went wrong
|
||||
$response->getBody()->write(json_encode(array("error" => "Something went wrong")));
|
||||
@@ -261,14 +261,14 @@ $app->post("/projectData", function (Request $request, Response $response)
|
||||
{
|
||||
global $projectData;
|
||||
$data = $request->getParsedBody();
|
||||
if (empty($data["title"]) || empty($data["isMainProject"]) || empty($data["information"]) || empty($data["projectLink"]) || empty($data["githubLink"]))
|
||||
if (empty($data["title"]) || empty($data["isMainProject"]) || empty($data["information"]) || empty($data["projectLink"]) || empty($data["gitLink"]))
|
||||
{
|
||||
// uh oh sent some empty data
|
||||
$response->getBody()->write(json_encode(array("error" => "Only some of the data was sent")));
|
||||
return $response->withStatus(400);
|
||||
}
|
||||
|
||||
$insertedID = $projectData->addProjectData($data["title"], $data["isMainProject"], $data["information"], $data["projectLink"], $data["githubLink"]);
|
||||
$insertedID = $projectData->addProjectData($data["title"], $data["isMainProject"], $data["information"], $data["projectLink"], $data["gitLink"]);
|
||||
if (!is_int($insertedID))
|
||||
{
|
||||
// uh oh something went wrong
|
||||
@@ -280,6 +280,29 @@ $app->post("/projectData", function (Request $request, Response $response)
|
||||
return $response;
|
||||
});
|
||||
|
||||
$app->post("/projectImage/{id}", function (Request $request, Response $response, array $args)
|
||||
{
|
||||
global $projectData;
|
||||
$files = $request->getUploadedFiles();
|
||||
if (empty($args["id"]) || empty($files))
|
||||
{
|
||||
// uh oh only some of the data was sent
|
||||
$response->getBody()->write(json_encode(array("error" => "Only some of the data was sent")));
|
||||
return $response->withStatus(400);
|
||||
}
|
||||
|
||||
$message = $projectData->uploadImage($args["id"], $files["img"]);
|
||||
if (!is_array($message))
|
||||
{
|
||||
// uh oh something went wrong
|
||||
$response->getBody()->write(json_encode(array("error" => $message)));
|
||||
return $response->withStatus(500);
|
||||
}
|
||||
|
||||
$response->getBody()->write(json_encode($message));
|
||||
return $response;
|
||||
});
|
||||
|
||||
$app->post("/contact", function (Request $request, Response $response)
|
||||
{
|
||||
$data = $request->getParsedBody();
|
||||
@@ -479,6 +502,12 @@ $app->post("/user/login", function (Request $request, Response $response)
|
||||
return $response->withStatus(401);
|
||||
});
|
||||
|
||||
$app->get("/user/logout", function (Request $request, Response $response)
|
||||
{
|
||||
session_unset();
|
||||
return $response;
|
||||
});
|
||||
|
||||
$app->get("/user/isLoggedIn", function (Request $request, Response $response)
|
||||
{
|
||||
global $user;
|
||||
@@ -498,7 +527,7 @@ $app->get("/user/isLoggedIn", function (Request $request, Response $response)
|
||||
|
||||
$response->getBody()->write(json_encode(array("token" => $_SESSION["token"])));
|
||||
return $response;
|
||||
|
||||
|
||||
});
|
||||
|
||||
$app->get("/user/checkResetEmail/{email}", function (Request $request, Response $response, array $args)
|
||||
|
||||
Reference in New Issue
Block a user