From 4f01ebe6ce2e15799589156e1df61d3422acfa49 Mon Sep 17 00:00:00 2001 From: rodude123 Date: Fri, 11 Nov 2022 13:56:42 +0000 Subject: [PATCH] created acd for editing projects data Signed-off-by: rodude123 --- dist/api/index.php | 85 +++++++++++++++++++++++++++++++++++------ src/api/index.php | 85 +++++++++++++++++++++++++++++++++++------ src/api/projectData.php | 51 +++++++++++++++++++++++++ src/editor/editor.html | 3 ++ 4 files changed, 202 insertions(+), 22 deletions(-) diff --git a/dist/api/index.php b/dist/api/index.php index 63b33d9..4515f78 100644 --- a/dist/api/index.php +++ b/dist/api/index.php @@ -80,10 +80,10 @@ $app->patch("/timelineData/{timeline}/{id}", function (Request $request, Respons return $response->withStatus(500); } - return $response->withStatus(200); + return $response; } - if ($args["timeline"] == "work" && $args["id"] != null) + if ($args["timeline"] == "work" && $args["id"] != "undefined") { if (empty($data["dateFrom"]) || empty($data["dateTo"]) || empty($data["companyName"]) || empty($data["area"]) || empty($data["title"])) { @@ -99,7 +99,7 @@ $app->patch("/timelineData/{timeline}/{id}", function (Request $request, Respons return $response->withStatus(500); } - return $response->withStatus(200); + return $response; } $response->getBody()->write(json_encode(array("error" => "The correct data was not sent"))); @@ -118,7 +118,7 @@ $app->delete("/timelineData/{timeline}/{id}", function (Request $request, Respon return $response->withStatus(500); } - return $response->withStatus(200); + return $response; } if ($args["timeline"] == "work" && $args["id"] != null) @@ -130,7 +130,7 @@ $app->delete("/timelineData/{timeline}/{id}", function (Request $request, Respon return $response->withStatus(500); } - return $response->withStatus(200); + return $response; } $response->getBody()->write(json_encode(array("error" => "The correct data was not sent"))); @@ -159,7 +159,7 @@ $app->post("/timelineData/{timeline}", function (Request $request, Response $res } $response->getBody()->write(json_encode(array("ID" => $insertedID))); - return $response->withStatus(200); + return $response; } if ($args["timeline"] == "work") @@ -185,7 +185,7 @@ $app->post("/timelineData/{timeline}", function (Request $request, Response $res } $response->getBody()->write(json_encode(array("ID" => $insertedID))); - return $response->withStatus(200); + return $response; } $response->getBody()->write(json_encode(array("error" => "The correct data was not sent"))); @@ -211,6 +211,73 @@ $app->get("/projectData", function (Request $request, Response $response) return $response; }); +$app->patch("/projectData/{id}", function (Request $request, Response $response, array $args) +{ + global $projectData; + if (empty($args["id"] != "undefined")) + { + if (empty($args["title"]) || empty($args["isMainProject"]) || empty($args["information"]) || empty($args["projectLink"]) || empty($args["githubLink"])) + { + // 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"])) + { + // uh oh something went wrong + $response->getBody()->write(json_encode(array("error" => "Something went wrong"))); + return $response->withStatus(500); + } + return $response; + } + + $response->getBody()->write(json_encode(array("error" => "Please provide an ID"))); + return $response->withStatus(400); +}); + +$app->delete("/projectData/{id}", function (Request $request, Response $response, array $args) +{ + global $projectData; + if ($args["id"] != null) + { + if (!$projectData->deleteProjectData($args["id"])) + { + // uh oh something went wrong + $response->getBody()->write(json_encode(array("error" => "Something went wrong"))); + return $response->withStatus(500); + } + + return $response; + } + + $response->getBody()->write(json_encode(array("error" => "Please provide an ID"))); + return $response->withStatus(400); +}); + +$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"])) + { + // 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"]); + if (!is_int($insertedID)) + { + // uh oh something went wrong + $response->getBody()->write(json_encode(array("error" => "Something went wrong"))); + return $response->withStatus(500); + } + + $response->getBody()->write(json_encode(array("ID" => $insertedID))); + return $response; +}); + $app->post("/contact", function (Request $request, Response $response) { $data = $request->getParsedBody(); @@ -507,8 +574,4 @@ $app->post("/user/changePassword", function (Request $request, Response $respons return $response->withStatus(500); }); - - - - $app->run(); diff --git a/src/api/index.php b/src/api/index.php index 63b33d9..4515f78 100644 --- a/src/api/index.php +++ b/src/api/index.php @@ -80,10 +80,10 @@ $app->patch("/timelineData/{timeline}/{id}", function (Request $request, Respons return $response->withStatus(500); } - return $response->withStatus(200); + return $response; } - if ($args["timeline"] == "work" && $args["id"] != null) + if ($args["timeline"] == "work" && $args["id"] != "undefined") { if (empty($data["dateFrom"]) || empty($data["dateTo"]) || empty($data["companyName"]) || empty($data["area"]) || empty($data["title"])) { @@ -99,7 +99,7 @@ $app->patch("/timelineData/{timeline}/{id}", function (Request $request, Respons return $response->withStatus(500); } - return $response->withStatus(200); + return $response; } $response->getBody()->write(json_encode(array("error" => "The correct data was not sent"))); @@ -118,7 +118,7 @@ $app->delete("/timelineData/{timeline}/{id}", function (Request $request, Respon return $response->withStatus(500); } - return $response->withStatus(200); + return $response; } if ($args["timeline"] == "work" && $args["id"] != null) @@ -130,7 +130,7 @@ $app->delete("/timelineData/{timeline}/{id}", function (Request $request, Respon return $response->withStatus(500); } - return $response->withStatus(200); + return $response; } $response->getBody()->write(json_encode(array("error" => "The correct data was not sent"))); @@ -159,7 +159,7 @@ $app->post("/timelineData/{timeline}", function (Request $request, Response $res } $response->getBody()->write(json_encode(array("ID" => $insertedID))); - return $response->withStatus(200); + return $response; } if ($args["timeline"] == "work") @@ -185,7 +185,7 @@ $app->post("/timelineData/{timeline}", function (Request $request, Response $res } $response->getBody()->write(json_encode(array("ID" => $insertedID))); - return $response->withStatus(200); + return $response; } $response->getBody()->write(json_encode(array("error" => "The correct data was not sent"))); @@ -211,6 +211,73 @@ $app->get("/projectData", function (Request $request, Response $response) return $response; }); +$app->patch("/projectData/{id}", function (Request $request, Response $response, array $args) +{ + global $projectData; + if (empty($args["id"] != "undefined")) + { + if (empty($args["title"]) || empty($args["isMainProject"]) || empty($args["information"]) || empty($args["projectLink"]) || empty($args["githubLink"])) + { + // 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"])) + { + // uh oh something went wrong + $response->getBody()->write(json_encode(array("error" => "Something went wrong"))); + return $response->withStatus(500); + } + return $response; + } + + $response->getBody()->write(json_encode(array("error" => "Please provide an ID"))); + return $response->withStatus(400); +}); + +$app->delete("/projectData/{id}", function (Request $request, Response $response, array $args) +{ + global $projectData; + if ($args["id"] != null) + { + if (!$projectData->deleteProjectData($args["id"])) + { + // uh oh something went wrong + $response->getBody()->write(json_encode(array("error" => "Something went wrong"))); + return $response->withStatus(500); + } + + return $response; + } + + $response->getBody()->write(json_encode(array("error" => "Please provide an ID"))); + return $response->withStatus(400); +}); + +$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"])) + { + // 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"]); + if (!is_int($insertedID)) + { + // uh oh something went wrong + $response->getBody()->write(json_encode(array("error" => "Something went wrong"))); + return $response->withStatus(500); + } + + $response->getBody()->write(json_encode(array("ID" => $insertedID))); + return $response; +}); + $app->post("/contact", function (Request $request, Response $response) { $data = $request->getParsedBody(); @@ -507,8 +574,4 @@ $app->post("/user/changePassword", function (Request $request, Response $respons return $response->withStatus(500); }); - - - - $app->run(); diff --git a/src/api/projectData.php b/src/api/projectData.php index 74be93c..f4fef3c 100644 --- a/src/api/projectData.php +++ b/src/api/projectData.php @@ -29,4 +29,55 @@ class projectData } return array("errorMessage" => "Error, project data not found"); } + + function updateProjectData(string $title, string $isMainProject, string $information, string $projectLink, string $githubLink, string $id): bool + { + $conn = dbConn(); + $stmt = $conn->prepare("UPDATE projects SET title = :title, isMainProject = :isMainProject, information = :information, projectLink = :projectLink, githubLink = :githubLink WHERE ID = :id"); + $stmt->bindParam(":title", $title); + $stmt->bindParam(":isMainProject", $isMainProject); + $stmt->bindParam(":information", $information); + $stmt->bindParam(":projectLink", $projectLink); + $stmt->bindParam(":githubLink", $githubLink); + $stmt->bindParam(":id", $id); + $stmt->execute(); + + if ($stmt->rowCount() > 0) + { + return true; + } + return false; + } + + function deleteProjectData(int $id): bool + { + $conn = dbConn(); + $stmt = $conn->prepare("DELETE FROM projects WHERE ID = :id"); + $stmt->bindParam(":id", $id); + $stmt->execute(); + + if ($stmt->rowCount() > 0) + { + return true; + } + return false; + } + + function addProjectData(string $title, string $isMainProject, string $information, string $projectLink, string $githubLink): bool + { + $conn = dbConn(); + $stmt = $conn->prepare("INSERT INTO projects (title, isMainProject, information, projectLink, githubLink) VALUES (:title, :isMainProject, :information, :projectLink, :githubLink)"); + $stmt->bindParam(":title", $title); + $stmt->bindParam(":isMainProject", $isMainProject); + $stmt->bindParam(":information", $information); + $stmt->bindParam(":projectLink", $projectLink); + $stmt->bindParam(":githubLink", $githubLink); + $stmt->execute(); + + if ($stmt->rowCount() > 0) + { + return true; + } + return false; + } } diff --git a/src/editor/editor.html b/src/editor/editor.html index 37d1c5c..221fa05 100644 --- a/src/editor/editor.html +++ b/src/editor/editor.html @@ -21,6 +21,7 @@

Editor

+

curriculum vitae

@@ -107,6 +108,8 @@
+ + section#projects>h2{projects}+div.