Compare commits

15 Commits

Author SHA1 Message Date
70c3a61103 add: createunits 2023-01-19 14:36:32 +01:00
7c4ab54f45 add: createIngredients 2023-01-19 14:27:30 +01:00
e666991b60 better select 2023-01-18 10:51:28 +01:00
b93e0c8e5a change: signup 2023-01-18 09:51:43 +01:00
66a9311cae fix 2023-01-18 09:13:01 +01:00
c754569143 Merge remote-tracking branch 'origin/don' into don 2023-01-18 09:09:54 +01:00
71ab5b8dae partial fix 2023-01-18 09:09:39 +01:00
0d811dd059 add: wordbook for easier use of the DB 2023-01-18 09:08:23 +01:00
d28b3fac90 Merge pull request 'Login' (#1) from feat/login into don
Reviewed-on: #1
2023-01-18 08:40:25 +01:00
af0d895227 fixed: foreignkeys 2023-01-12 14:56:50 +01:00
da0445ccf6 add: DB removing ALTER TABLE ADD Primary Key 2023-01-12 14:51:44 +01:00
c23b77ff0d add: DB primary key update 2023-01-12 14:49:58 +01:00
03a42f3ba7 add: DB primary key update 2023-01-12 14:46:46 +01:00
1d80d93b1d add: DB auto_increment 2023-01-12 14:43:28 +01:00
151b1ab549 phpdoc 2023-01-12 14:05:19 +01:00
4 changed files with 81 additions and 43 deletions

View File

@@ -6,7 +6,7 @@ time_zone = "+00:00";
CREATE TABLE `ingredienti` CREATE TABLE `ingredienti`
( /*Zutaten*/ ( /*Zutaten*/
`id` varchar(36) NOT NULL, `id` int auto_increment NOT NULL PRIMARY KEY,
`cognome` varchar(200) NOT NULL, /*Name*/ `cognome` varchar(200) NOT NULL, /*Name*/
`caloriePerCento` integer(5) NOT NULL, /*Kalorien pro Gramm*/ `caloriePerCento` integer(5) NOT NULL, /*Kalorien pro Gramm*/
`ilPeso` integer(5) NULL, /*Gewicht*/ `ilPeso` integer(5) NULL, /*Gewicht*/
@@ -16,14 +16,14 @@ CREATE TABLE `ingredienti`
CREATE TABLE `folla` CREATE TABLE `folla`
( /*Menge*/ ( /*Menge*/
`id` varchar(36) NOT NULL, `id` int auto_increment NOT NULL PRIMARY KEY,
`unita` varchar(200) NOT NULL, /*Einheit*/ `unita` varchar(200) NOT NULL, /*Einheit*/
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `elenco` CREATE TABLE `elenco`
( /*Liste*/ ( /*Liste*/
`id` varchar(36) NOT NULL, `id` int auto_increment NOT NULL PRIMARY KEY,
`creatore` varchar(200) NOT NULL, /*Ersteller*/ `creatore` varchar(200) NOT NULL, /*Ersteller*/
`coloreDiSfondo` integer(10) NOT NULL, /*Hintergrundfarbe*/ `coloreDiSfondo` integer(10) NOT NULL, /*Hintergrundfarbe*/
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
@@ -31,50 +31,36 @@ CREATE TABLE `elenco`
CREATE TABLE `utente` CREATE TABLE `utente`
( /*Benutzer*/ ( /*Benutzer*/
`id` varchar(36) NOT NULL, `id` int auto_increment NOT NULL PRIMARY KEY,
`email` varchar(200) NOT NULL, /*Email*/ `email` varchar(200) NOT NULL, /*Email*/
`parolaDordine` varchar(255) NOT NULL, /*Passwort*/ `parolaDordine` varchar(255) NOT NULL, /*Passwort*/
`nomeUtente` varchar(50) UNIQUE NOT NULL, /*Benutzernamen*/ `nomeUtente` varchar(50) UNIQUE NOT NULL, /*Benutzernamen*/
`gettone` varchar(255), /*Token für Session*/ `gettone` varchar(255), /*Token für Session*/
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `elencoIngredienti` CREATE TABLE `elencoIngredienti`
( /*Liste_Zutaten*/ ( /*Liste_Zutaten*/
`id` varchar(36) NOT NULL, `id` int auto_increment NOT NULL PRIMARY KEY,
`ingredientiID` varchar(36) NOT NULL, /*ZutatenID*/ `ingredientiID` int NOT NULL, /*ZutatenID*/
`elencoID` varchar(36) NOT NULL, /*ListeID*/ `elencoID` int NOT NULL, /*ListeID*/
`follaID` varchar(36) NOT NULL, /*MengeID*/ `follaID` int NOT NULL, /*MengeID*/
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `utenteElenco` CREATE TABLE `utenteElenco`
( /*Benutzer_Liste*/ ( /*Benutzer_Liste*/
`id` varchar(36) NOT NULL, `id` int auto_increment NOT NULL PRIMARY KEY,
`elencoID` varchar(36) NOT NULL, /*ListeID*/ `elencoID` int NOT NULL, /*ListeID*/
`utenteID` varchar(36) NOT NULL, /*BenutzerID*/ `utenteID` int NOT NULL, /*BenutzerID*/
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `ingredienti` /*Zutaten*/
ADD PRIMARY KEY (`id`);
ALTER TABLE `folla` /*Menge*/
ADD PRIMARY KEY (`id`);
ALTER TABLE `elenco` /*Liste*/
ADD PRIMARY KEY (`id`);
ALTER TABLE `utente` /*Benutzer*/
ADD PRIMARY KEY (`id`);
ALTER TABLE `elencoIngredienti` /*Liste_Zutaten*/ ALTER TABLE `elencoIngredienti` /*Liste_Zutaten*/
ADD PRIMARY KEY (`id`),
ADD CONSTRAINT `FK_ElencoIngredienti_Ingredienti` FOREIGN KEY (`ingredientiID`) REFERENCES `ingredienti`(`id`), /*Liste_Zutaten hat Foreignkey von Zutaten(id)*/ ADD CONSTRAINT `FK_ElencoIngredienti_Ingredienti` FOREIGN KEY (`ingredientiID`) REFERENCES `ingredienti`(`id`), /*Liste_Zutaten hat Foreignkey von Zutaten(id)*/
ADD CONSTRAINT `FK_ElencoIngredienti_Elenco` FOREIGN KEY (`elencoID`) REFERENCES `elenco`(`id`), /*Liste_Zutaten hat Foreignkey von Liste(id)*/ ADD CONSTRAINT `FK_ElencoIngredienti_Elenco` FOREIGN KEY (`elencoID`) REFERENCES `elenco`(`id`), /*Liste_Zutaten hat Foreignkey von Liste(id)*/
ADD CONSTRAINT `FK_ElencoIngredienti_Folla` FOREIGN KEY (`follaID`) REFERENCES `folla`(`id`); /*Liste_Zutaten hat Foreignkey von Menge(id)*/ ADD CONSTRAINT `FK_ElencoIngredienti_Folla` FOREIGN KEY (`follaID`) REFERENCES `folla`(`id`); /*Liste_Zutaten hat Foreignkey von Menge(id)*/
ALTER TABLE `utenteElenco` /*Benutzer_Liste*/ ALTER TABLE `utenteElenco` /*Benutzer_Liste*/
ADD PRIMARY KEY (`id`),
ADD CONSTRAINT `FK_UtenteElenco_Utente` FOREIGN KEY (`utenteId`) REFERENCES `utente`(`id`), /*Benutzer_Liste hat Foreignkey von Benutzer(id)*/ ADD CONSTRAINT `FK_UtenteElenco_Utente` FOREIGN KEY (`utenteId`) REFERENCES `utente`(`id`), /*Benutzer_Liste hat Foreignkey von Benutzer(id)*/
ADD CONSTRAINT `FK_UtenteElenco_Elenco` FOREIGN KEY (`elencoId`) REFERENCES `elenco`(`id`); /*Benutzer_Liste hat Foreignkey von Liste(id)*/ ADD CONSTRAINT `FK_UtenteElenco_Elenco` FOREIGN KEY (`elencoId`) REFERENCES `elenco`(`id`); /*Benutzer_Liste hat Foreignkey von Liste(id)*/

View File

@@ -44,7 +44,7 @@ class BancaDati {
$value = ""; $value = "";
$column = ""; $column = "";
foreach ($values as $col => $v){ foreach ($values as $col => $v){
$value .= $v . ","; $value .= "'" . $v . "',";
$column .= $col . ","; $column .= $col . ",";
} }
$value = trim($value, ","); $value = trim($value, ",");
@@ -70,7 +70,7 @@ class BancaDati {
public function update(string $table, string $id, array $values){ public function update(string $table, string $id, array $values){
$value = ""; $value = "";
foreach ($values as $col => $v){ foreach ($values as $col => $v){
$value .= $col . "=" . $v . ","; $value .= $col . "='" . $v . "',";
} }
$value = trim($value, ","); $value = trim($value, ",");
@@ -91,7 +91,7 @@ class BancaDati {
* @author Malte Schulze Hobeling * @author Malte Schulze Hobeling
*/ */
public function delete(string $table, string $id){ public function delete(string $table, string $id){
$sql = "DELETE FROM " . $table . " WHERE `id` = " . $id . ";"; $sql = "DELETE FROM " . $table . " WHERE `id` = '" . $id . "';";
try { try {
$sth = $this->pdo->prepare($sql); $sth = $this->pdo->prepare($sql);
$sth->execute(); $sth->execute();
@@ -102,29 +102,32 @@ class BancaDati {
/** /**
* einheitliche Select Funktion * einheitliche Select Funktion
* kann sortiert werden durch ["by"]=>"col" und ["order"]=>"ASC|DESC"
* @param string $table * @param string $table
* @param array $where ["column"]=>"value" es wird mit LIKE verglichen und mit AND verbunden * @param array $where ["column"]=>"value" es wird mit LIKE verglichen und mit AND verbunden
* @param array|null $order ["by"]=>"column"; ["order"]=>"ASC|DESC"
* @return void * @return void
* @author Malte Schulze Hobeling * @author Malte Schulze Hobeling
*/ */
public function select(string $table, array $where, array $order = null){ public function select(string $table, array $where){
$whereString = ""; $whereString = "";
$orderString = "";
if(isset($where["by"])){
$orderString = " ORDER BY " . $where["by"];
unset($where["by"]);
if(isset($where["order"])){
$orderString .= " " . $where["order"];
unset($where["order"]);
}
}
foreach ($where as $col => $v) { foreach ($where as $col => $v) {
if($whereString != ""){ if($whereString != ""){
$whereString .= " AND "; $whereString .= " AND ";
} }
$whereString .= $col . " LIKE " . $v; $whereString .= "`" . $col . "` LIKE '" . $v . "'";
}
$sql = "SELECT * FROM ".$table." WHERE ".$whereString;
if(isset($order["by"])){
$sql .= " ORDER BY ".$order["by"];
}
if(isset($order["order"])){
$sql .= $order["order"];
} }
$sql = "SELECT * FROM ".$table." WHERE ".$whereString.$orderString.";";
try { try {
return $this->pdo->query($sql); return $this->pdo->query($sql)->fetch();
}catch (PDOException $e){ }catch (PDOException $e){
die; die;
} }

View File

@@ -34,7 +34,12 @@ $app->get("/user/:id", function (array $req, Response $res) use ($db) {
$res->send("user " . $req["params"]["id"]); $res->send("user " . $req["params"]["id"]);
}); });
$app->post("/createuser", function (array $req, Response $res) use ($db) { $app->post("/createuser", function (array $req, Response $res) use ($db) {
$db->insert("utente", ["email" => "test@email.com", "parolaDordine" => "password", "nomeUtente" => "testuser"]); $newUsername = $req["body"]["username"];
$newPassword = $req["body"]["password"];
$newEmail = $req["body"]["email"];
// $db->insert("utente", ["email" => "test@email.com", "parolaDordine" => "password", "nomeUtente" => "testuser"]);
$db->insert("utente", ["email" => "$newEmail", "parolaDordine" => "$newPassword", "nomeUtente" => "$newUsername"]);
$res->send("user "); $res->send("user ");
}); });
@@ -53,4 +58,21 @@ $app->post("/login", function( array $req, Response $res) use ($db) {
} }
}); });
$app->post("/createingredients", function (array $req, Response $res) use ($db) {
$newIngredient = $req["body"]["ingredient"];
$newCalorie = $req["body"]["calories"];
$newWeight = $req["body"]["weight"];
$newPrice = $req["body"]["price"];
$db->insert("ingredienti", ["cognome" => "$newIngredient", "caloriePerCento" => "$newCalorie", "ilPeso" => "$newWeight", "prezzo" => "$newPrice"]);
$res->send("New ingredient has been listed ");
});
$app->post("/createunits", function (array $req, Response $res) use ($db) {
$newUnit = $req["body"]["unit"];
$db->insert("folla", ["unita" => "$newUnit"]);
$res->send("New unit has been listed ");
});
$app->start(); $app->start();

27
italienIntoGerman.txt Normal file
View File

@@ -0,0 +1,27 @@
ingredienti = Zutaten
cognome = Name
caloriePerCento = Kalorien pro Gramm
ilPeso = Gewicht
prezzo = Preis
folla = Menge
unita = Einheit
elenco = Liste
creatore = Ersteller
coloreDiSfondo = Hintergrundfarbe
utente = Benutzer
email = Email
parolaDordine = Passwort
nomeUtente = Benutzernamen
gettone = Token (für die Session)
elencoIngredienti = Liste_Zutaten
ingredientiID = ZutatenID
elencoID = ListeID
follaID = MengeID
utenteElenco = Benutzer_Liste
elencoID = ListeID
utenteID = BenutzerID