Being able to edit a timeline item fully working as currently tested.
Signed-off-by: rodude123 <rodude123@gmail.com>
This commit is contained in:
Vendored
+134
-33
@@ -59,6 +59,139 @@ $app->get("/timelineData/{timeline}", function (Request $request, Response $resp
|
||||
return $response->withStatus(404);
|
||||
});
|
||||
|
||||
$app->patch("/timelineData/{timeline}/{id}", function (Request $request, Response $response, array $args)
|
||||
{
|
||||
global $timelineData;
|
||||
$data = $request->getParsedBody();
|
||||
if ($args["timeline"] == "edu" && $args["id"] != "undefined")
|
||||
{
|
||||
if (empty($data["dateFrom"]) || empty($data["dateTo"]) || empty($data["grade"]) || empty($data["course"]))
|
||||
{
|
||||
// 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 (!$timelineData->updateEduData($data["dateFrom"], $data["dateTo"], $data["grade"], $data["course"], $args["id"]))
|
||||
{
|
||||
// uh oh something went wrong
|
||||
$response->getBody()->write(json_encode(array("error" => "Something went wrong")));
|
||||
return $response->withStatus(500);
|
||||
}
|
||||
|
||||
return $response->withStatus(200);
|
||||
}
|
||||
|
||||
if ($args["timeline"] == "work" && $args["id"] != null)
|
||||
{
|
||||
if (empty($data["dateFrom"]) || empty($data["dateTo"]) || empty($data["companyName"]) || empty($data["area"]) || empty($data["title"]))
|
||||
{
|
||||
// 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 (!$timelineData->updateWorkData($data["dateFrom"], $data["dateTo"], $data["companyName"], $data["area"], $data["title"], $args["id"]))
|
||||
{
|
||||
// uh oh something went wrong
|
||||
$response->getBody()->write(json_encode(array("error" => "Something went wrong")));
|
||||
return $response->withStatus(500);
|
||||
}
|
||||
|
||||
return $response->withStatus(200);
|
||||
}
|
||||
|
||||
$response->getBody()->write(json_encode(array("error" => "The correct data was not sent")));
|
||||
return $response->withStatus(400);
|
||||
});
|
||||
|
||||
$app->delete("/timelineData/{timeline}/{id}", function (Request $request, Response $response, array $args)
|
||||
{
|
||||
global $timelineData;
|
||||
if ($args["timeline"] == "edu" && $args["id"] != null)
|
||||
{
|
||||
if (!$timelineData->deleteEduData($args["id"]))
|
||||
{
|
||||
// uh oh something went wrong
|
||||
$response->getBody()->write(json_encode(array("error" => "Something went wrong")));
|
||||
return $response->withStatus(500);
|
||||
}
|
||||
|
||||
return $response->withStatus(200);
|
||||
}
|
||||
|
||||
if ($args["timeline"] == "work" && $args["id"] != null)
|
||||
{
|
||||
if (!$timelineData->deleteWorkData($args["id"]))
|
||||
{
|
||||
// uh oh something went wrong
|
||||
$response->getBody()->write(json_encode(array("error" => "Something went wrong")));
|
||||
return $response->withStatus(500);
|
||||
}
|
||||
|
||||
return $response->withStatus(200);
|
||||
}
|
||||
|
||||
$response->getBody()->write(json_encode(array("error" => "The correct data was not sent")));
|
||||
return $response->withStatus(400);
|
||||
});
|
||||
|
||||
$app->post("/timelineData/{timeline}", function (Request $request, Response $response, array $args)
|
||||
{
|
||||
global $timelineData;
|
||||
$data = $request->getParsedBody();
|
||||
if ($args["timeline"] == "edu")
|
||||
{
|
||||
if (empty($data["dateFrom"]) || empty($data["dateTo"]) || empty($data["grade"]) || empty($data["course"]))
|
||||
{
|
||||
// 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 = $timelineData->addEduData($data["dateFrom"], $data["dateTo"], $data["grade"], $data["course"]);
|
||||
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->withStatus(200);
|
||||
}
|
||||
|
||||
if ($args["timeline"] == "work")
|
||||
{
|
||||
if (empty($data["dateFrom"]) || empty($data["companyName"]) || empty($data["area"]) || empty($data["title"]))
|
||||
{
|
||||
// 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 (empty($data["dateTo"]))
|
||||
{
|
||||
$data["dateTo"] = "";
|
||||
}
|
||||
|
||||
$insertedID = $timelineData->addWorkData($data["dateFrom"], $data["dateTo"], $data["companyName"], $data["area"], $data["title"]);
|
||||
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->withStatus(200);
|
||||
}
|
||||
|
||||
$response->getBody()->write(json_encode(array("error" => "The correct data was not sent")));
|
||||
return $response->withStatus(400);
|
||||
});
|
||||
|
||||
$app->get("/projectData", function (Request $request, Response $response)
|
||||
{
|
||||
global $projectData;
|
||||
@@ -373,39 +506,7 @@ $app->post("/user/changePassword", function (Request $request, Response $respons
|
||||
return $response->withStatus(500);
|
||||
});
|
||||
|
||||
$app->patch("/timelineData/{timeline}/{id}", function (Request $request, Response $response, array $args)
|
||||
{
|
||||
global $timelineData;
|
||||
if ($args["timeline"] == "edu" && $args["id"] != "undefined")
|
||||
{
|
||||
$data = $request->getParsedBody();
|
||||
if (empty($data["dateFrom"]) || empty($data["dateTo"]) || empty($data["grade"]) || empty($data["course"]))
|
||||
{
|
||||
// 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 (!$timelineData->updateEduData($data["dateFrom"], $data["dateTo"], $data["grade"], $data["course"], $args["id"]))
|
||||
{
|
||||
// uh oh something went wrong
|
||||
$response->getBody()->write(json_encode(array("error" => "Something went wrong")));
|
||||
return $response->withStatus(500);
|
||||
}
|
||||
|
||||
return $response->withStatus(200);
|
||||
}
|
||||
|
||||
if ($args["timeline"] == "work" && $args["id"] != null)
|
||||
{
|
||||
|
||||
return $response->withStatus(200);
|
||||
}
|
||||
|
||||
$response->getBody()->write(json_encode(array("error" => "The correct data was not sent")));
|
||||
return $response->withStatus(400);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Vendored
+103
-2
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace api;
|
||||
|
||||
use PDO;
|
||||
|
||||
require_once "./config.php";
|
||||
@@ -37,12 +39,12 @@ class timelineData
|
||||
function getWorkData(): array
|
||||
{
|
||||
$conn = dbConn();
|
||||
$stmt = $conn->prepare("SELECT startPeriod, endPeriod, companyName, area, title FROM work ORDER BY work.startPeriod DESC;");
|
||||
$stmt = $conn->prepare("SELECT ID, startPeriod, endPeriod, companyName, area, title FROM work ORDER BY work.startPeriod DESC;");
|
||||
$stmt->execute();
|
||||
|
||||
// set the resulting array to associative
|
||||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
|
||||
if ($result)
|
||||
{
|
||||
return $result;
|
||||
@@ -71,4 +73,103 @@ class timelineData
|
||||
return $stmt->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update work data
|
||||
* @param string $dateFrom - Start date
|
||||
* @param string $dateTo - End date
|
||||
* @param string $companyName - Company name
|
||||
* @param string $area - Area
|
||||
* @param string $title - Title
|
||||
* @param string $id - ID of the work data
|
||||
* @return bool - True if successful, false if not
|
||||
*/
|
||||
public function updateWorkData(string $dateFrom, string $dateTo, string $companyName, string $area, string $title, string $id): bool
|
||||
{
|
||||
$conn = dbConn();
|
||||
$stmt = $conn->prepare("UPDATE work SET startPeriod = :dateFrom, endPeriod = :dateTo, companyName = :companyName, area = :area, title = :title WHERE ID = :id;");
|
||||
$stmt->bindParam(":dateFrom", $dateFrom);
|
||||
$stmt->bindParam(":dateTo", $dateTo);
|
||||
$stmt->bindParam(":companyName", $companyName);
|
||||
$stmt->bindParam(":area", $area);
|
||||
$stmt->bindParam(":title", $title);
|
||||
$stmt->bindParam(":id", $id);
|
||||
return $stmt->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete education data by ID
|
||||
* @param int $id
|
||||
* @return bool - True if successful, false if not
|
||||
*/
|
||||
function deleteEduData(int $id): bool
|
||||
{
|
||||
$conn = dbConn();
|
||||
$stmt = $conn->prepare("DELETE FROM edu WHERE ID = :id;");
|
||||
$stmt->bindParam(":id", $id);
|
||||
return $stmt->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete work data by ID
|
||||
* @param int $id
|
||||
* @return bool - True if successful, false if not
|
||||
*/
|
||||
function deleteWorkData(int $id): bool
|
||||
{
|
||||
$conn = dbConn();
|
||||
$stmt = $conn->prepare("DELETE FROM work WHERE ID = :id;");
|
||||
$stmt->bindParam(":id", $id);
|
||||
return $stmt->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new education data
|
||||
* @param string $dateFrom - Start date
|
||||
* @param string $dateTo - End date
|
||||
* @param string $grade - Grade
|
||||
* @param string $course - Course
|
||||
* @return bool|int - ID of the new education data or false if not successful
|
||||
*/
|
||||
function addEduData(string $dateFrom, string $dateTo, string $grade, string $course): bool|int
|
||||
{
|
||||
$conn = dbConn();
|
||||
$stmt = $conn->prepare("INSERT INTO edu (startPeriod, endPeriod, grade, course) VALUES (:dateFrom, :dateTo, :grade, :course);");
|
||||
$stmt->bindParam(":dateFrom", $dateFrom);
|
||||
$stmt->bindParam(":dateTo", $dateTo);
|
||||
$stmt->bindParam(":grade", $grade);
|
||||
$stmt->bindParam(":course", $course);
|
||||
|
||||
if($stmt->execute())
|
||||
{
|
||||
return $conn->lastInsertId();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new work data
|
||||
* @param string $dateFrom - Start date
|
||||
* @param string $dateTo - End date
|
||||
* @param string $companyName - Company name
|
||||
* @param string $area - Area
|
||||
* @param string $title - Title
|
||||
* @return bool|int - ID of the new work data if successful, false if not
|
||||
*/
|
||||
function addWorkData(string $dateFrom, string $dateTo, string $companyName, string $area, string $title): bool|int
|
||||
{
|
||||
$conn = dbConn();
|
||||
$stmt = $conn->prepare("INSERT INTO work (startPeriod, endPeriod, companyName, area, title) VALUES (:dateFrom, :dateTo, :companyName, :area, :title);");
|
||||
$stmt->bindParam(":dateFrom", $dateFrom);
|
||||
$stmt->bindParam(":dateTo", $dateTo);
|
||||
$stmt->bindParam(":companyName", $companyName);
|
||||
$stmt->bindParam(":area", $area);
|
||||
$stmt->bindParam(":title", $title);
|
||||
|
||||
if($stmt->execute())
|
||||
{
|
||||
return $conn->lastInsertId();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
@@ -1 +1 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Editor</title><link rel="stylesheet" href="css/main.css"><script src="https://kit.fontawesome.com/ed3c25598e.js" crossorigin="anonymous"></script></head><body><nav class="sideNav"><a href="#" class="closeBtn" id="navClose">×</a><ul><li><a href="#" class="active"><span><</span>CV<span>></span></a></li><li><a href="#"><span><</span>Projects<span>></span></a></li><li><a href="#"><span><</span>Settings<span>></span></a></li></ul></nav><main class="editor" style="margin-left: 250px;"><div class="title"><span id="navOpen">☰</span><h1>Editor</h1></div><section id="curriculumVitae"><h2>curriculum vitae</h2><div class="cvGrid"><!-- https://codepen.io/keithwyland/pen/wqNqvy --><div><h3>Education</h3><div class="editorContainer"><form action="" method="POST"><div class="formControl"><label for="dateFrom">Date From</label> <input type="date" id="dateFrom" name="dateFrom"></div><div class="formControl"><label for="dateTo">Date To</label> <input type="date" id="dateTo" name="dateTo"></div><div class="formControl"><label for="grade">Grade</label> <input type="text" id="grade" name="grade"></div><div class="formControl"><label for="courseTitle">Course Title</label> <input type="text" id="courseTitle" name="courseTitle"></div><div class="error hidden" id="eduError"><button class="close" type="button">×</button><div></div></div><input type="submit" class="btn btnPrimary boxShadowIn boxShadowOut" value="Add new course"></form><div class="timeline" id="edu"></div></div></div><div><h3>Work</h3><div class="timeline" id="work"></div></div></div></section></main><script src="js/editor.js"></script></body></html>
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Editor</title><link rel="stylesheet" href="css/main.css"><script src="https://kit.fontawesome.com/ed3c25598e.js" crossorigin="anonymous"></script></head><body><nav class="sideNav"><a href="#" class="closeBtn" id="navClose">×</a><ul><li><a href="#" class="active"><span><</span>CV<span>></span></a></li><li><a href="#"><span><</span>Projects<span>></span></a></li><li><a href="#"><span><</span>Settings<span>></span></a></li></ul></nav><main class="editor" style="margin-left: 250px;"><div class="title"><span id="navOpen">☰</span><h1>Editor</h1></div><section id="curriculumVitae"><h2>curriculum vitae</h2><div class="cvGrid"><div><h3>Education</h3><div class="editorContainer"><form action="" method="POST" id="addEdu"><div class="formControl"><label for="dateFromE">Date From</label> <input type="date" id="dateFromE" name="dateFromE"></div><div class="formControl"><label for="dateToE">Date To</label> <input type="date" id="dateToE" name="dateToE"></div><div class="formControl"><label for="grade">Grade</label> <input type="text" id="grade" name="grade"></div><div class="formControl"><label for="courseTitle">Course Title</label> <input type="text" id="courseTitle" name="courseTitle"></div><div class="error hidden" id="eduError"><button class="close" type="button">×</button><div></div></div><input type="submit" class="btn btnPrimary boxShadowIn boxShadowOut" value="Add new course"></form><div class="timeline" id="edu"></div></div></div><div><h3>Work</h3><div class="editorContainer"><form action="" method="POST" id="addWork"><div class="formControl"><label for="dateFromW">Date From</label> <input type="date" id="dateFromW" name="dateFromW"></div><div class="formControl"><label for="dateToW">Date To</label> <input type="date" id="dateToW" name="dateToW"></div><div class="formControl"><label for="company">Company</label> <input type="text" id="company" name="company"></div><div class="formControl"><label for="area">Area</label> <input type="text" id="area" name="area"></div><div class="formControl"><label for="jobTitle">Job Title</label> <input type="text" id="jobTitle" name="jobTitle"></div><div class="error hidden" id="workError"><button class="close" type="button">×</button><div></div></div><input type="submit" class="btn btnPrimary boxShadowIn boxShadowOut" value="Add new job"></form><div class="timeline" id="work"></div></div></div></div></section></main><script src="js/editor.js"></script></body></html>
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user