created acd for editing projects data

Signed-off-by: rodude123 <rodude123@gmail.com>
This commit is contained in:
Rohit Pai 2022-11-11 13:56:42 +00:00
parent 1c1acfe938
commit 4f01ebe6ce
4 changed files with 202 additions and 22 deletions

85
dist/api/index.php vendored
View File

@ -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();

View File

@ -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();

View File

@ -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;
}
}

View File

@ -21,6 +21,7 @@
<h1>Editor</h1>
</div>
<section id="curriculumVitae">
<h2>curriculum vitae</h2>
<div class="cvGrid">
@ -107,6 +108,8 @@
</div>
</div>
</section>
section#projects>h2{projects}+div.
</main>
<script src="js/editor.js"></script>