add: delete items from list
This commit is contained in:
parent
b2ce4f829d
commit
c8582c8813
@ -9,7 +9,7 @@ class BancaDati {
|
|||||||
private $dbName = "BancaDati";
|
private $dbName = "BancaDati";
|
||||||
private $linkName = "localhost";
|
private $linkName = "localhost";
|
||||||
private $user = "root";
|
private $user = "root";
|
||||||
private $pw = "root";
|
private $pw = "";
|
||||||
|
|
||||||
public $pdo;
|
public $pdo;
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
@ -55,8 +55,10 @@ class BancaDati {
|
|||||||
try {
|
try {
|
||||||
$sth = $this->pdo->prepare($sql);
|
$sth = $this->pdo->prepare($sql);
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
|
return $this->pdo->lastInsertId();
|
||||||
}catch (PDOException $e){
|
}catch (PDOException $e){
|
||||||
die;
|
return false;
|
||||||
|
//die;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +130,7 @@ class BancaDati {
|
|||||||
}
|
}
|
||||||
$sql = "SELECT * FROM " . $table . ((count($where) > 0) ? " WHERE ".$whereString.$orderString : "") .";";
|
$sql = "SELECT * FROM " . $table . ((count($where) > 0) ? " WHERE ".$whereString.$orderString : "") .";";
|
||||||
try {
|
try {
|
||||||
return $this->pdo->query($sql)->fetchAll();
|
return $this->pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
|
||||||
}catch (PDOException $e){
|
}catch (PDOException $e){
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
13
index.php
13
index.php
@ -251,7 +251,6 @@ $app->route("/list/:id")
|
|||||||
$res->json(["data" => $list]);
|
$res->json(["data" => $list]);
|
||||||
})
|
})
|
||||||
->post(function (array $req, Response $res) use ($db) {
|
->post(function (array $req, Response $res) use ($db) {
|
||||||
// TODO: add Item to List with id
|
|
||||||
$id = $req["params"]["id"];
|
$id = $req["params"]["id"];
|
||||||
$ingredientId = $req["body"]["ingredientId"];
|
$ingredientId = $req["body"]["ingredientId"];
|
||||||
|
|
||||||
@ -284,7 +283,17 @@ $app->route("/list/:id")
|
|||||||
$res->json(["message" => "List has been deleted"]);
|
$res->json(["message" => "List has been deleted"]);
|
||||||
});
|
});
|
||||||
$app->delete("/list/:id/:item", function (array $req, Response $res) use ($db) {
|
$app->delete("/list/:id/:item", function (array $req, Response $res) use ($db) {
|
||||||
// TODO: delete item from list
|
$listId = $req["params"]["id"];
|
||||||
|
$itemId = $req["params"]["item"];
|
||||||
|
|
||||||
|
$list = $db->select("elenco", ["id" => $listId, "utenteID" => $req["user"]->id]);
|
||||||
|
if(count($list) < 1){
|
||||||
|
$res->json(["message" => "List does not exist or you dont have the permissions to edit the list"]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db->delete("elencoIngredienti", $itemId);
|
||||||
|
$res->json(["message" => "Item has been deleted"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
$app->start();
|
$app->start();
|
Loading…
Reference in New Issue
Block a user