done #3

Merged
PBS2H21ASH merged 19 commits from done into don 2023-01-24 20:11:21 +01:00
2 changed files with 16 additions and 5 deletions
Showing only changes of commit c8582c8813 - Show all commits

View File

@ -9,7 +9,7 @@ class BancaDati {
private $dbName = "BancaDati";
private $linkName = "localhost";
private $user = "root";
private $pw = "root";
private $pw = "";
public $pdo;
public function __construct() {
@ -55,8 +55,10 @@ class BancaDati {
try {
$sth = $this->pdo->prepare($sql);
$sth->execute();
return $this->pdo->lastInsertId();
}catch (PDOException $e){
die;
return false;
//die;
}
}
@ -128,7 +130,7 @@ class BancaDati {
}
$sql = "SELECT * FROM " . $table . ((count($where) > 0) ? " WHERE ".$whereString.$orderString : "") .";";
try {
return $this->pdo->query($sql)->fetchAll();
return $this->pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
}catch (PDOException $e){
die;
}

View File

@ -251,7 +251,6 @@ $app->route("/list/:id")
$res->json(["data" => $list]);
})
->post(function (array $req, Response $res) use ($db) {
// TODO: add Item to List with id
$id = $req["params"]["id"];
$ingredientId = $req["body"]["ingredientId"];
@ -284,7 +283,17 @@ $app->route("/list/:id")
$res->json(["message" => "List has been deleted"]);
});
$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();