Added the ability to edit and delete posts which includes uploading of images for the posts and managing those images

Signed-off-by: rodude123 <rodude123@gmail.com>
This commit is contained in:
2023-07-12 03:29:56 +01:00
parent be5e047f51
commit 3b71ba4d23
26 changed files with 1549 additions and 315 deletions
+77 -20
View File
@@ -58,19 +58,33 @@ class timelineData
* @param string $dateTo - End date
* @param string $grade - Grade
* @param string $course - Course
* @param string $id - ID of the education data
* @return bool - True if successful, false if not
* @param string $ID - ID of the education data
* @return string - "not found" if the ID is not found, "ok" if successful, "error" if not
*/
public function updateEduData(string $dateFrom, string $dateTo, string $grade, string $course, string $id): bool
public function updateEduData(string $dateFrom, string $dateTo, string $grade, string $course, string $ID): string
{
$conn = dbConn();
$chkStmt = $conn->prepare("SELECT ID FROM edu WHERE ID = :id;");
$chkStmt->bindParam(":id", $ID);
$chkStmt->execute();
$result = $chkStmt->fetch(PDO::FETCH_ASSOC);
if (!$result)
{
return "not found";
}
$stmt = $conn->prepare("UPDATE edu SET startPeriod = :dateFrom, endPeriod = :dateTo, grade = :grade, course = :course WHERE ID = :id;");
$stmt->bindParam(":dateFrom", $dateFrom);
$stmt->bindParam(":dateTo", $dateTo);
$stmt->bindParam(":grade", $grade);
$stmt->bindParam(":course", $course);
$stmt->bindParam(":id", $id);
return $stmt->execute();
$stmt->bindParam(":id", $ID);
if ($stmt->execute())
{
return "ok";
}
return "error";
}
/**
@@ -80,11 +94,21 @@ class timelineData
* @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
* @param string $ID - ID of the work data
* @return string - "not found" if the ID is not found, "ok" if successful, "error" if not
*/
public function updateWorkData(string $dateFrom, string $dateTo, string $companyName, string $area, string $title, string $id): bool
public function updateWorkData(string $dateFrom, string $dateTo, string $companyName, string $area, string $title, string $ID): string
{
$conn = dbConn();
$chkStmt = $conn->prepare("SELECT ID FROM work WHERE ID = :id;");
$chkStmt->bindParam(":id", $ID);
$chkStmt->execute();
$result = $chkStmt->fetch(PDO::FETCH_ASSOC);
if (!$result)
{
return "not found";
}
$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);
@@ -92,34 +116,67 @@ class timelineData
$stmt->bindParam(":companyName", $companyName);
$stmt->bindParam(":area", $area);
$stmt->bindParam(":title", $title);
$stmt->bindParam(":id", $id);
return $stmt->execute();
$stmt->bindParam(":id", $ID);
if ($stmt->execute())
{
return "ok";
}
return "error";
}
/**
* Delete education data by ID
* @param int $id
* @return bool - True if successful, false if not
* @param int $ID
* @return string - "not found" if the ID is not found, "ok" if successful, "error" if not
*/
public function deleteEduData(int $id): bool
public function deleteEduData(int $ID): string
{
$conn = dbConn();
$chkStmt = $conn->prepare("SELECT ID FROM edu WHERE ID = :id;");
$chkStmt->bindParam(":id", $ID);
$chkStmt->execute();
$result = $chkStmt->fetch(PDO::FETCH_ASSOC);
if (!$result)
{
return "not found";
}
$stmt = $conn->prepare("DELETE FROM edu WHERE ID = :id;");
$stmt->bindParam(":id", $id);
return $stmt->execute();
$stmt->bindParam(":id", $ID);
if ($stmt->execute())
{
return "ok";
}
return "error";
}
/**
* Delete work data by ID
* @param int $id
* @return bool - True if successful, false if not
* @param int $ID
* @return string - "not found" if the ID is not found, "ok" if successful, "error" if not
*/
function deleteWorkData(int $id): bool
function deleteWorkData(int $ID): string
{
$conn = dbConn();
$chkStmt = $conn->prepare("SELECT ID FROM work WHERE ID = :id;");
$chkStmt->bindParam(":id", $ID);
$chkStmt->execute();
$result = $chkStmt->fetch(PDO::FETCH_ASSOC);
if (!$result)
{
return "not found";
}
$stmt = $conn->prepare("DELETE FROM work WHERE ID = :id;");
$stmt->bindParam(":id", $id);
return $stmt->execute();
$stmt->bindParam(":id", $ID);
if ($stmt->execute())
{
return "ok";
}
return "error";
}
/**
+40 -5
View File
@@ -53,7 +53,7 @@ class timelineRoutes implements routesInterface
$app->patch("/timelineData/{timeline}/{id}", function (Request $request, Response $response, array $args)
{
$data = $request->getParsedBody();
if ($args["timeline"] == "edu" && $args["id"] != "undefined")
if ($args["timeline"] == "edu" && $args["id"] != null)
{
if (empty($data["dateFrom"]) || empty($data["dateTo"]) || empty($data["grade"]) || empty($data["course"]))
{
@@ -61,8 +61,16 @@ class timelineRoutes implements routesInterface
$response->getBody()->write(json_encode(array("error" => "Only some of the data was sent")));
return $response->withStatus(400);
}
$message = $this->timelineData->updateEduData($data["dateFrom"], $data["dateTo"], $data["grade"], $data["course"], $args["id"]);
if (!$this->timelineData->updateEduData($data["dateFrom"], $data["dateTo"], $data["grade"], $data["course"], $args["id"]))
if ($message == "not found")
{
// uh oh sent some empty data
$response->getBody()->write(json_encode(array("error" => "Edu data with ID " . $args["id"] . " was not found")));
return $response->withStatus(404);
}
if ($message == "error")
{
// uh oh something went wrong
$response->getBody()->write(json_encode(array("error" => "Something went wrong")));
@@ -82,7 +90,16 @@ class timelineRoutes implements routesInterface
return $response->withStatus(400);
}
if (!$this->timelineData->updateWorkData($data["dateFrom"], $data["dateTo"], $data["companyName"], $data["area"], $data["title"], $args["id"]))
$message = $this->timelineData->updateWorkData($data["dateFrom"], $data["dateTo"], $data["companyName"], $data["area"], $data["title"], $args["id"]);
if ($message == "not found")
{
// uh oh sent some empty data
$response->getBody()->write(json_encode(array("error" => "Work data with ID " . $args["id"] . " was not found")));
return $response->withStatus(404);
}
if ($message == "error")
{
// uh oh something went wrong
$response->getBody()->write(json_encode(array("error" => "Something went wrong")));
@@ -101,7 +118,16 @@ class timelineRoutes implements routesInterface
{
if ($args["timeline"] == "edu" && $args["id"] != null)
{
if (!$this->timelineData->deleteEduData($args["id"]))
$message = $this->timelineData->deleteEduData($args["id"]);
if ($message == "not found")
{
// uh oh sent some empty data
$response->getBody()->write(json_encode(array("error" => "Edu data with ID " . $args["id"] . " was not found")));
return $response->withStatus(404);
}
if ($message == "error")
{
// uh oh something went wrong
$response->getBody()->write(json_encode(array("error" => "Something went wrong")));
@@ -113,7 +139,16 @@ class timelineRoutes implements routesInterface
if ($args["timeline"] == "work" && $args["id"] != null)
{
if (!$this->timelineData->deleteWorkData($args["id"]))
$message = $this->timelineData->deleteWorkData($args["id"]);
if ($message == "not found")
{
// uh oh sent some empty data
$response->getBody()->write(json_encode(array("error" => "Work data with ID " . $args["id"] . " was not found")));
return $response->withStatus(404);
}
if ($message == "error")
{
// uh oh something went wrong
$response->getBody()->write(json_encode(array("error" => "Something went wrong")));