add: update and delete units
This commit is contained in:
parent
9a00e7eb16
commit
9ca46b9b3e
27
index.php
27
index.php
@ -169,11 +169,28 @@ $app->route("/unit")
|
||||
$newUnitId = $db->insert("folla", ["unita" => $name]);
|
||||
$res->json(["message" => "Unit: '" . $name . "' created", "data" => $db->select("folla", ["id" => $newUnitId])[0]], HTTP_STATUS_CODE::CREATED);
|
||||
});
|
||||
$app->get("/unit/:id", function (array $req, Response $res) use ($db) {
|
||||
$id = $req["params"]["id"];
|
||||
$ingredient = $db->select("folla", ["id" => $id])[0];
|
||||
$res->json(["data" => $ingredient]);
|
||||
});
|
||||
$app->route("/unit/:id")
|
||||
->get(function (array $req, Response $res) use ($db) {
|
||||
$id = $req["params"]["id"];
|
||||
$ingredient = $db->select("folla", ["id" => $id])[0];
|
||||
$res->json(["data" => $ingredient]);
|
||||
})
|
||||
->put(function (array $req, Response $res) use ($db) {
|
||||
$id = $req["params"]["id"];
|
||||
$name = $req["body"]["name"];
|
||||
|
||||
if (!isset($name) || strlen($name) < 1 || strlen($name) > 200) {
|
||||
$res->json(["message" => "Invalid Request. Please follow the Documentation", HTTP_STATUS_CODE::BAD_REQUEST]);
|
||||
return;
|
||||
}
|
||||
$db->update("folla", $id, ["unita" => $name]);
|
||||
$res->json(["message" => "Unit has been updated", "data" => $db->select("folla", ["id" => $id])]);
|
||||
})
|
||||
->delete(function (array $req, Response $res) use ($db) {
|
||||
$id = $req["params"]["id"];
|
||||
$db->delete("folla", $id);
|
||||
$res->json(["message" => "Unit has been deleted"]);
|
||||
});
|
||||
|
||||
/*
|
||||
* List
|
||||
|
Loading…
Reference in New Issue
Block a user