Reset method added
This commit is contained in:
parent
c5030f4cf0
commit
8ee06acb3d
1 changed files with 71 additions and 1 deletions
|
@ -79,8 +79,78 @@ public class Database {
|
|||
}
|
||||
|
||||
public String reset(Request req, Response res) {
|
||||
return "{}";
|
||||
try {
|
||||
// Reset Customers
|
||||
String resetCustomersQuery = "TRUNCATE TABLE Customer; INSERT INTO Customer(name, address) " +
|
||||
"SELECT name, address FROM (VALUES " +
|
||||
"('Finkakor AB', 'Helsingborg'), " +
|
||||
"('Småbröd AB', 'Malmö'), " +
|
||||
"('Kaffebröd AB', 'Landskrona'), " +
|
||||
"('Bjudkakor AB', 'Ystad'), " +
|
||||
"('Kalaskakor AB', 'Trelleborg'), " +
|
||||
"('Partykakor AB', 'Kristianstad'), " +
|
||||
"('Gästkakor AB', 'Hässleholm'), " +
|
||||
"('Skånekakor AB', 'Perstorp')) AS temp(name, address)";
|
||||
conn.createStatement().executeUpdate(resetCustomersQuery);
|
||||
|
||||
// Reset Cookies
|
||||
String resetCookiesQuery = "TRUNCATE TABLE Cookie; INSERT INTO Cookie(name) " +
|
||||
"SELECT name FROM (VALUES " +
|
||||
"('Nut ring'), " +
|
||||
"('Nut cookie'), " +
|
||||
"('Amneris'), " +
|
||||
"('Tango'), " +
|
||||
"('Almond delight'), " +
|
||||
"('Berliner')) AS temp(name)";
|
||||
conn.createStatement().executeUpdate(resetCookiesQuery);
|
||||
|
||||
// Reset Ingredients
|
||||
String resetIngredientsQuery = "TRUNCATE TABLE Ingredient; INSERT INTO Ingredient(ingredient_name, stock, unit) " +
|
||||
"SELECT ingredient_name, stock, unit FROM (VALUES " +
|
||||
"('Bread crumbs', 500000, 'g'), " +
|
||||
"('Butter', 500000, 'g'), " +
|
||||
"('Chocolate', 500000, 'g'), " +
|
||||
"('Chopped almonds', 500000, 'g'), " +
|
||||
"('Cinnamon', 500000, 'g'), " +
|
||||
"('Egg whites', 500000, 'ml'), " +
|
||||
"('Eggs', 500000, 'g'), " +
|
||||
"('Fine-ground nuts', 500000, 'g'), " +
|
||||
"('Flour', 500000, 'g'), " +
|
||||
"('Ground, roasted nuts', 500000, 'g'), " +
|
||||
"('Icing sugar', 500000, 'g'), " +
|
||||
"('Marzipan', 500000, 'g'), " +
|
||||
"('Potato starch', 500000, 'g'), " +
|
||||
"('Roasted, chopped nuts', 500000, 'g'), " +
|
||||
"('Sodium bicarbonate', 500000, 'g'), " +
|
||||
"('Sugar', 500000, 'g'), " +
|
||||
"('Vanilla sugar', 500000, 'g'), " +
|
||||
"('Vanilla', 500000, 'g'), " +
|
||||
"('Wheat flour', 500000, 'g')) AS temp(ingredient_name, stock, unit)";
|
||||
conn.createStatement().executeUpdate(resetIngredientsQuery);
|
||||
|
||||
// Reset Recipes
|
||||
String resetRecipesQuery = "TRUNCATE TABLE Recipe; INSERT INTO Recipe(ingredient_name, cookie_name, amount) " +
|
||||
"SELECT ingredient_name, cookie_name, amount FROM (VALUES " +
|
||||
"('Butter', 'Nut ring', 450),('Flour', 'Nut ring', 450),('Icing sugar', 'Nut ring', 190),('Roasted, chopped nuts', 'Nut ring', 225), " +
|
||||
"('Bread crumbs', 'Nut cookie', 125),('Chocolate', 'Nut cookie', 50),('Egg whites', 'Nut cookie', 350),('Fine-ground nuts', 'Nut cookie', 750),('Ground, roasted nuts', 'Nut cookie', 625),('Sugar', 'Nut cookie', 375), " +
|
||||
"('Butter', 'Amneris', 250),('Eggs', 'Amneris', 250),('Marzipan', 'Amneris', 750),('Potato starch', 'Amneris', 25),('Wheat flour', 'Amneris', 25), " +
|
||||
"('Butter', 'Tango', 200),('Flour', 'Tango', 300),('Sodium bicarbonate', 'Tango', 4),('Sugar', 'Tango', 250),('Vanilla', 'Tango', 2), " +
|
||||
"('Butter', 'Almond delight', 400),('Chopped almonds', 'Almond delight', 279),('Cinnamon', 'Almond delight', 10),('Flour', 'Almond delight', 400),('Sugar', 'Almond delight', 270), " +
|
||||
"('Butter', 'Berliner', 250),('Chocolate', 'Berliner', 50),('Eggs', 'Berliner', 50),('Flour', 'Berliner', 350),('Icing sugar', 'Berliner', 100),('Vanilla sugar', 'Berliner', 5)) AS temp(ingredient_name, cookie_name, amount)";
|
||||
conn.createStatement().executeUpdate(resetRecipesQuery);
|
||||
|
||||
// Clear Pallets
|
||||
String clearPalletsQuery = "TRUNCATE TABLE Pallet";
|
||||
conn.createStatement().executeUpdate(clearPalletsQuery);
|
||||
|
||||
// Return JSON response
|
||||
return "{\"status\": \"ok\"}";
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return "{\"status\": \"error\"}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String createPallet(Request req, Response res) {
|
||||
if (req.queryParams("cookie") != null) {
|
||||
|
|
Loading…
Reference in a new issue