Added in ability to add a new project with and with an image and update a project with and without image. If a project is the main project then it cannot be deleted and when a new main project is selected it gets moved to the top.
Signed-off-by: rodude123 <rodude123@gmail.com>
This commit is contained in:
Vendored
+15
-7
@@ -218,17 +218,17 @@ $app->patch("/projectData/{id}", function (Request $request, Response $response,
|
||||
$data = $request->getParsedBody();
|
||||
if ($args["id"] != "undefined")
|
||||
{
|
||||
if (empty($data["title"]) || empty($data["isMainProject"]) || empty($data["information"]) || empty($data["projectLink"]) || empty($data["gitLink"]))
|
||||
if (empty($data["title"]) || empty($data["isMainProject"]) || empty($data["information"]) || empty($data["gitLink"]))
|
||||
{
|
||||
// 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["id"], $data["title"], $data["isMainProject"], $data["information"], "", $data["projectLink"], $data["gitLink"]))
|
||||
if (!$projectData->updateProjectData($args["id"], $data["title"], $data["isMainProject"], $data["information"], $data["projectLink"], $data["gitLink"]))
|
||||
{
|
||||
// uh oh something went wrong
|
||||
$response->getBody()->write(json_encode(array("error" => "Something went wrong")));
|
||||
$response->getBody()->write(json_encode(array("error" => "Something went wrong", "data" => $projectData->updateProjectData($args["id"], $data["title"], $data["isMainProject"], $data["information"], $data["projectLink"], $data["gitLink"]))));
|
||||
return $response->withStatus(500);
|
||||
}
|
||||
return $response;
|
||||
@@ -243,13 +243,21 @@ $app->delete("/projectData/{id}", function (Request $request, Response $response
|
||||
global $projectData;
|
||||
if ($args["id"] != null)
|
||||
{
|
||||
if (!$projectData->deleteProjectData($args["id"]))
|
||||
$message = $projectData->deleteProjectData($args["id"]);
|
||||
if ($message === "error")
|
||||
{
|
||||
// uh oh something went wrong
|
||||
$response->getBody()->write(json_encode(array("error" => "Something went wrong")));
|
||||
$response->getBody()->write(json_encode(array("error" => "Something went wrong or the project with ID ".$args["id"]."does not exist")));
|
||||
return $response->withStatus(500);
|
||||
}
|
||||
|
||||
if ($message === "cannot delete")
|
||||
{
|
||||
//uh oh cannot delete the main project
|
||||
$response->getBody()->write(json_encode(array("error" => "Cannot delete the main project")));
|
||||
return $response->withStatus(409);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
@@ -261,7 +269,7 @@ $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["gitLink"]))
|
||||
if (empty($data["title"]) || empty($data["isMainProject"]) || empty($data["information"]) || empty($data["gitLink"]))
|
||||
{
|
||||
// uh oh sent some empty data
|
||||
$response->getBody()->write(json_encode(array("error" => "Only some of the data was sent")));
|
||||
@@ -272,7 +280,7 @@ $app->post("/projectData", function (Request $request, Response $response)
|
||||
if (!is_int($insertedID))
|
||||
{
|
||||
// uh oh something went wrong
|
||||
$response->getBody()->write(json_encode(array("error" => "Something went wrong")));
|
||||
$response->getBody()->write(json_encode(array("error" => "Something went wrong", "message" => $insertedID)));
|
||||
return $response->withStatus(500);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user