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
+33
-3
@@ -373,10 +373,40 @@ $app->post("/user/changePassword", function (Request $request, Response $respons
|
||||
return $response->withStatus(500);
|
||||
});
|
||||
|
||||
$app->post("/projectData", function (Request $request, Response $response)
|
||||
$app->patch("/timelineData/{timeline}/{id}", function (Request $request, Response $response, array $args)
|
||||
{
|
||||
$response->getBody()->write(json_encode(array("test" => "test")));
|
||||
return $response;
|
||||
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);
|
||||
});
|
||||
|
||||
|
||||
|
||||
$app->run();
|
||||
|
||||
Vendored
+1
@@ -33,6 +33,7 @@ class middleware
|
||||
*/
|
||||
function baseMiddleware(App $app): void
|
||||
{
|
||||
$app->addBodyParsingMiddleware();
|
||||
$app->addRoutingMiddleware();
|
||||
}
|
||||
|
||||
|
||||
Vendored
+23
-2
@@ -17,7 +17,7 @@ class timelineData
|
||||
function getEduData(): array
|
||||
{
|
||||
$conn = dbConn();
|
||||
$stmt = $conn->prepare("SELECT startPeriod, endPeriod, grade, course FROM edu ORDER BY startPeriod DESC;");
|
||||
$stmt = $conn->prepare("SELECT ID, startPeriod, endPeriod, grade, course FROM edu ORDER BY startPeriod DESC;");
|
||||
$stmt->execute();
|
||||
|
||||
// set the resulting array to associative
|
||||
@@ -49,5 +49,26 @@ class timelineData
|
||||
}
|
||||
return array("errorMessage" => "Error, work data not found");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update education data
|
||||
* @param string $dateFrom - Start date
|
||||
* @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
|
||||
*/
|
||||
function updateEduData(string $dateFrom, string $dateTo, string $grade, string $course, string $id): bool
|
||||
{
|
||||
$conn = dbConn();
|
||||
$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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user