late fix #6

Merged
PBS2H21AKA merged 1 commits from done into don 2023-01-25 08:04:52 +01:00
3 changed files with 39 additions and 16 deletions

View File

@ -16,7 +16,7 @@ CREATE TABLE `ingredienti`
`cognome` varchar(200) NOT NULL, /*Name*/
`calorie` integer(5) NOT NULL, /*Kalorien*/
`quantita` integer(5) NOT NULL, /*Anzahl*/
`prezzo` decimal(4, 2) NOT NULL, /*Preis*/
`prezzo` decimal(8, 2) NOT NULL, /*Preis*/
`follaID` int NOT NULL, /*MengeID*/
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@ -77,7 +77,7 @@ ALTER TABLE `elenco`
/*Test Data*/
INSERT INTO `utente` (email, parolaDordine, nomeUtente) VALUES ('test@test.com', 'password', "testuser");
INSERT INTO `utente` (email, parolaDordine, nomeUtente) VALUES ('test1@test.com', 'password1', "testuser1");
INSERT INTO `utente` (email, parolaDordine, nomeUtente) VALUES ('test1@test.com', 'hunter2', "testuser1");
INSERT INTO `folla` (unita) VALUES ('st');
@ -91,8 +91,11 @@ INSERT INTO `folla` (unita) VALUES ('EL');
INSERT INTO `ingredienti` (cognome, calorie, quantita, prezzo, follaID) VALUES ('Raffinierter Zucker', 3870, 1000, 5, 2);
INSERT INTO `ingredienti` (cognome, calorie, quantita, prezzo, follaID) VALUES ('Die Chips von der Tanke', 843, 375, 4.30, 2);
INSERT INTO `ingredienti` (cognome, calorie, quantita, prezzo, follaID) VALUES ('Reines Copium', 420, 1337, 6.9, 4);
INSERT INTO `ingredienti` (cognome, calorie, quantita, prezzo, follaID) VALUES ('Maggi', 420, 1337, 6.9, 4);
INSERT INTO `ingredienti` (cognome, calorie, quantita, prezzo, follaID) VALUES ('Eine große Pommes Frites mit Pommes Frites', 4200, 1, 6.9, 3);
INSERT INTO `elenco` (utenteID, cognome) VALUES (1, 'Liste den Einkauf bei Netto');
INSERT INTO `elenco` (utenteID, cognome) VALUES (1, 'Liste für den Einkauf bei Netto');
INSERT INTO `elencoIngredienti` (ingredientiID, elencoID) VALUES (1, 1);
INSERT INTO `elencoIngredienti` (ingredientiID, elencoID) VALUES (2, 1);

View File

@ -13,13 +13,13 @@ Eine auflistung von allen Funktionen und API-Endpunkten mit Erklärung.
### User erstellen
```shell
POST 127.0.0.1/DirektiveDesDons/user
POST 127.0.0.1/DirektiveDesDons/signup
BODY
{
"username": "Benutzername",
"email": "email"
"password": "Passwort",
"email": "email",
"password": "Passwort"
}
```
@ -49,8 +49,8 @@ POST 127.0.0.1/DirektiveDesDons/list
BODY
{
"name": "Einkaufsliste 1"
"backgoundColor": "#123",
"name": "Einkaufsliste 1",
"backgoundColor": "#123"
}
```
@ -117,6 +117,20 @@ GET 127.0.0.1/DirektiveDesDons/ingredient/1
DELETE 127.0.0.1/DirektiveDesDons/ingredient/1
```
### Zutat ändern
```shell
POST 127.0.0.1/DirektiveDesDons/ingredient/3
BODY
{
"name": "Nüsse",
"calories": "123",
"quantity": "5",
"unit": "st",
"price": "13.5"
}
```
---
## MengenEinheiten

View File

@ -40,7 +40,7 @@ $app->use("/", function (array &$req, Response $res) {
* Home
*/
$app->get("/", function (array $req, Response $res) use ($db) {
$res->json(["message" => "",
$res->json(["message" => "Die Einkaufsliste des Don",
"name" => "Shopping List",
"authors" => "Simon Bock, Johannes Kantz & Malte Schulze Hobeling"]);
});
@ -55,10 +55,6 @@ $app->get("/user", function (array $req, Response $res) {
$res->json(["status" => HTTP_STATUS_CODE::FORBIDDEN, "message" => "You are not logged in. Goto '/login' to login"]);
}
});
$app->get("/user/:id", function (array $req, Response $res) use ($db) {
$db->select("utente", ["username" => $req["id"]]);
$res->send("user " . $req["params"]["id"]);
});
$app->post("/signup", function (array $req, Response $res) use ($db) {
$newUsername = $req["body"]["username"];
$newPassword = $req["body"]["password"];
@ -116,7 +112,12 @@ $app->route("/ingredient")
$app->route("/ingredient/:id")
->get(function (array $req, Response $res) use ($db) {
$id = $req["params"]["id"];
$ingredient = $db->select("ingredienti", ["id" => $id])[0];
$query = $db->select("ingredienti", ["id" => $id]);
if(count($query) < 1){
$res->json(["message" => "Item does not exists"]);
return;
}
$ingredient = $query[0];
$res->json(["data" => $ingredient]);
})
->put(function (array $req, Response $res) use ($db) {
@ -172,8 +173,13 @@ $app->route("/unit")
$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]);
$query = $db->select("folla", ["id" => $id]);
if(count($query) < 1){
$res->json(["message" => "Unit does not exists"]);
return;
}
$unit = $query[0];
$res->json(["data" => $unit]);
})
->put(function (array $req, Response $res) use ($db) {
$id = $req["params"]["id"];