Food, User
This commit is contained in:
parent
b97fe83f40
commit
a0eed3ce51
@ -84,6 +84,19 @@ public class AccountMgr {
|
||||
return id;
|
||||
}
|
||||
|
||||
protected static User getUserById(long id){
|
||||
List<String> entry = Database.getEntryById("user",id);
|
||||
String[] parts = entry.get(0).split(":");
|
||||
Address address = getAddressById(id);
|
||||
return new User(id,parts[1],parts[2],parts[4],parts[5],address,isWorker(String.valueOf(id)),isParent(String.valueOf(id)));
|
||||
}
|
||||
|
||||
protected static Address getAddressById(long id){
|
||||
List<String> entry = Database.getEntryById("address",id);
|
||||
String[] parts = entry.get(0).split(":");
|
||||
return new Address(Long.parseLong(parts[0]),parts[1],parts[2],parts[3],parts[4]);
|
||||
}
|
||||
|
||||
/**
|
||||
* creates entries in the database to match parent to child
|
||||
* @param parentId id of parent
|
||||
|
@ -0,0 +1,37 @@
|
||||
package com.bib.essensbestellungsverwaltung;
|
||||
|
||||
public class Address {
|
||||
private long id;
|
||||
private String street;
|
||||
private String number;
|
||||
private String plz;
|
||||
private String city;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public String getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public String getPlz() {
|
||||
return plz;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public Address(long id, String street, String number, String plz, String city) {
|
||||
this.id = id;
|
||||
this.street = street;
|
||||
this.number = number;
|
||||
this.plz = plz;
|
||||
this.city = city;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.bib.essensbestellungsverwaltung;
|
||||
|
||||
public class Allergy {
|
||||
private final long id;
|
||||
private final String name;
|
||||
private final String handle;
|
||||
|
||||
public Allergy(long id, String name, String handle) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getHandle() {
|
||||
return handle;
|
||||
}
|
||||
}
|
@ -119,7 +119,13 @@ public class ConsoleLib {
|
||||
System.out.print("Allergienummer: ");
|
||||
String allergies = sc.nextLine();
|
||||
String[] allergyData = allergies.split(",");
|
||||
if(FoodMgr.createFood(foodData,allergyData) < 1){
|
||||
FoodType foodType = FoodMgr.getFoodTypeById(Long.parseLong(foodData[3]));
|
||||
List<Allergy> allergyList = new ArrayList<>();
|
||||
for (String data : allergyData) {
|
||||
allergyList.add(FoodMgr.getAllergyById(Long.parseLong(data)));
|
||||
}
|
||||
Food food = new Food(foodData[0],foodData[1],true,foodType,allergyList);
|
||||
if(FoodMgr.createFood(food) < 1){
|
||||
System.out.println("Fehler");
|
||||
}
|
||||
}
|
||||
@ -131,6 +137,9 @@ public class ConsoleLib {
|
||||
while (id == -1){
|
||||
System.out.print("Email: ");
|
||||
String email = sc.nextLine();
|
||||
if(email.isEmpty()){
|
||||
return -1;
|
||||
}
|
||||
System.out.print("Passwort: ");
|
||||
String pw = sc.nextLine();
|
||||
id = AccountMgr.login(email,pw);
|
||||
@ -183,16 +192,25 @@ public class ConsoleLib {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.print("Bitte geben Sie das Datum im Format YYYY-MM-DD an: ");
|
||||
food_planData[0] = sc.nextLine();
|
||||
printConsole(FoodMgr.getVeganFood(false));
|
||||
List<Food> veganMain = FoodMgr.getVeganFood(false);
|
||||
for (Food food : veganMain) {
|
||||
System.out.println(food.getId() + " : " + food.getName());
|
||||
}
|
||||
System.out.print("Veganes Hauptgericht Nr: ");
|
||||
food_planData[1] = sc.nextLine();
|
||||
printConsole(FoodMgr.getFood(false));
|
||||
List<Food> foodMain = FoodMgr.getFood(false);
|
||||
System.out.print("Zweites Hauptgericht Nr: ");
|
||||
food_planData[2] = sc.nextLine();
|
||||
printConsole(FoodMgr.getVeganFood(true));
|
||||
List<Food> veganDessert = FoodMgr.getVeganFood(true);
|
||||
for (Food food : veganDessert) {
|
||||
System.out.println(food.getId() + " : " + food.getName());
|
||||
}
|
||||
System.out.print("Veganes Dessert Nr: ");
|
||||
food_planData[3] = sc.nextLine();
|
||||
printConsole(FoodMgr.getFood(true));
|
||||
List<Food> foodDessert = FoodMgr.getFood(true);
|
||||
for (Food food : foodDessert) {
|
||||
System.out.println(food.getId() + " : " + food.getName());
|
||||
}
|
||||
System.out.print("Zweites Dessert Nr: ");
|
||||
food_planData[4] = sc.nextLine();
|
||||
long id = FoodMgr.createFood_plan(food_planData);
|
||||
@ -207,7 +225,8 @@ public class ConsoleLib {
|
||||
System.out.print("Bitte geben Sie das Datum im Format YYYY-MM-DD an: ");
|
||||
String date = sc.nextLine();
|
||||
List<String> plan = FoodMgr.getFood_plan(date);
|
||||
List<String> food = new ArrayList<>();
|
||||
List<String> foodList = new ArrayList<>();
|
||||
Food food;
|
||||
StringBuilder sb;
|
||||
for (String day : plan) {
|
||||
sb = new StringBuilder();
|
||||
@ -216,23 +235,19 @@ public class ConsoleLib {
|
||||
sb.append(parts[1]);
|
||||
sb.append(" Veganesgericht: ");
|
||||
food = FoodMgr.getFoodById(Long.parseLong(parts[2]));
|
||||
String[] foodParts = food.get(0).split(":");
|
||||
sb.append(foodParts[1]);
|
||||
sb.append(food.getName());
|
||||
sb.append(" Zweites Hauptgericht: ");
|
||||
food = FoodMgr.getFoodById(Long.parseLong(parts[3]));
|
||||
foodParts = food.get(0).split(":");
|
||||
sb.append(foodParts[1]);
|
||||
sb.append(food.getName());
|
||||
sb.append(" Veganesdessert: ");
|
||||
food = FoodMgr.getFoodById(Long.parseLong(parts[4]));
|
||||
foodParts = food.get(0).split(":");
|
||||
sb.append(foodParts[1]);
|
||||
sb.append(food.getName());
|
||||
sb.append(" Zweites Dessert: ");
|
||||
food = FoodMgr.getFoodById(Long.parseLong(parts[5]));
|
||||
foodParts = food.get(0).split(":");
|
||||
sb.append(foodParts[1]);
|
||||
food.add(sb.toString());
|
||||
sb.append(food.getName());
|
||||
foodList.add(sb.toString());
|
||||
}
|
||||
printConsole(food);
|
||||
printConsole(foodList);
|
||||
}
|
||||
|
||||
public static void createFood_selectionPrompt(){
|
||||
|
@ -32,21 +32,23 @@ public class ConsoleMain {
|
||||
}
|
||||
|
||||
public static void defaultMenu(){
|
||||
System.out.println("0: Programm beenden");
|
||||
System.out.println("1: Login");
|
||||
System.out.println("2: Essensplan anzeigen");
|
||||
System.out.println("3: Programm beenden");
|
||||
System.out.println("3: Registrieren");
|
||||
|
||||
System.out.print("Auswahl: ");
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String selection = sc.nextLine();
|
||||
switch (selection) {
|
||||
case "0" -> currentUserId = -2;
|
||||
case "1" -> {
|
||||
currentUserId = ConsoleLib.loginPrompt();
|
||||
isWorker = AccountMgr.isWorker(String.valueOf(currentUserId));
|
||||
isParent = AccountMgr.isParent(String.valueOf(currentUserId));
|
||||
}
|
||||
case "2" -> ConsoleLib.showFood_planPrompt();
|
||||
case "3" -> currentUserId = -2;
|
||||
case "3" -> ConsoleLib.createParentPrompt();
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,14 +59,14 @@ public class ConsoleMain {
|
||||
System.out.println("3: Ein neues Kind anlegen");
|
||||
System.out.println("4: Kind einem Elternteil zuordnen");
|
||||
System.out.println("5: Ein neues Essen anlegen");
|
||||
System.out.println("6: Table");
|
||||
System.out.println("7: Einen Essensplan erstellen");
|
||||
System.out.println("8: Essensplan anzeigen");
|
||||
System.out.println("9: Löschen");
|
||||
System.out.println("10: Essen auswählen");
|
||||
System.out.println("11: Bestellungen des Tages sammeln");
|
||||
System.out.println("12: Monatsabrechnung");
|
||||
System.out.println("13: Preis ändern");
|
||||
System.out.println("6: Einen Essensplan erstellen");
|
||||
System.out.println("7: Essensplan anzeigen");
|
||||
System.out.println("8: Essen auswählen");
|
||||
System.out.println("9: Bestellungen des Tages sammeln");
|
||||
System.out.println("10: Monatsabrechnung");
|
||||
System.out.println("11: Preis ändern");
|
||||
System.out.println("x1: Table");
|
||||
System.out.println("x2: Löschen");
|
||||
|
||||
|
||||
System.out.print("Auswahl: ");
|
||||
@ -81,14 +83,14 @@ public class ConsoleMain {
|
||||
case "3" -> ConsoleLib.createChildPrompt(String.valueOf(currentUserId));
|
||||
case "4" -> ConsoleLib.matchParentChildPrompt(String.valueOf(currentUserId));
|
||||
case "5" -> ConsoleLib.createFoodPrompt();
|
||||
case "6" -> ConsoleLib.tablePrompt();
|
||||
case "7" -> ConsoleLib.createFood_planPrompt();
|
||||
case "8" -> ConsoleLib.showFood_planPrompt();
|
||||
case "9" -> ConsoleLib.deletePrompt();
|
||||
case "10" -> ConsoleLib.createFood_selectionPrompt();
|
||||
case "11" -> ConsoleLib.dayOrderPrompt();
|
||||
case "12" -> ConsoleLib.invoicePrompt();
|
||||
case "13" -> ConsoleLib.changePricePrompt();
|
||||
case "6" -> ConsoleLib.createFood_planPrompt();
|
||||
case "7" -> ConsoleLib.showFood_planPrompt();
|
||||
case "8" -> ConsoleLib.createFood_selectionPrompt();
|
||||
case "9" -> ConsoleLib.dayOrderPrompt();
|
||||
case "10" -> ConsoleLib.invoicePrompt();
|
||||
case "11" -> ConsoleLib.changePricePrompt();
|
||||
case "x1" -> ConsoleLib.tablePrompt();
|
||||
case "x2" -> ConsoleLib.deletePrompt();
|
||||
}
|
||||
|
||||
}
|
||||
@ -96,7 +98,8 @@ public class ConsoleMain {
|
||||
public static void parentMenu(){
|
||||
System.out.println("0: Ausloggen");
|
||||
System.out.println("3: Ein neues Kind anlegen");
|
||||
System.out.println("4: Kind einem Elternteil zuordnen");
|
||||
System.out.println("7: Essensplan anzeigen");
|
||||
System.out.println("8: Essen auswählen");
|
||||
|
||||
|
||||
System.out.print("Auswahl: ");
|
||||
@ -109,10 +112,9 @@ public class ConsoleMain {
|
||||
isParent = false;
|
||||
}
|
||||
case "3" -> ConsoleLib.createChildPrompt(String.valueOf(currentUserId));
|
||||
case "4" -> ConsoleLib.matchParentChildPrompt(String.valueOf(currentUserId));
|
||||
case "6" -> ConsoleLib.tablePrompt();
|
||||
default -> {
|
||||
}
|
||||
case "7" -> ConsoleLib.showFood_planPrompt();
|
||||
case "8" -> ConsoleLib.createFood_selectionPrompt();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -62,7 +62,8 @@ public class Database {
|
||||
sql[2] = """
|
||||
CREATE TABLE IF NOT EXISTS allergy (
|
||||
id integer PRIMARY KEY,
|
||||
name text UNIQUE
|
||||
name text UNIQUE,
|
||||
handle text UNIQUE
|
||||
);""";
|
||||
sql[3] = """
|
||||
CREATE TABLE IF NOT EXISTS severity (
|
||||
@ -180,71 +181,71 @@ public class Database {
|
||||
INSERT OR IGNORE INTO food_type (id,name)
|
||||
VALUES ('3','Fleischhaltig');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('1','Eier');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('1','Eier','a');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('2','Soja');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('2','Soja','b');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('3','Milch');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('3','Milch','c');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('4','Erdnüsse');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('4','Erdnüsse','d');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('5','Weichtiere');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('5','Weichtiere','e');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('6','Krebstiere');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('6','Krebstiere','f');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('7','Getreide');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('7','Getreide','g');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('8','Senf');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('8','Senf','h');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('9','Sesam');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('9','Sesam','i');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('10','Schwefeldioxid und Sulfit');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('10','Schwefeldioxid und Sulfit','j');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('11','Nüsse');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('11','Nüsse','k');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('12','Sellerie');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('12','Sellerie','l');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('13','Fische');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('13','Fische','m');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('14','Lupinen');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('14','Lupinen','n');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('15','Nitrit-Pökelsalz');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('15','Nitrit-Pökelsalz','1');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('16','Phosphat');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('16','Phosphat','2');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('17','Nitrat');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('17','Nitrat','3');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('18','Antioxidationsmittel');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('18','Antioxidationsmittel','4');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('19','Farbstoff');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('19','Farbstoff','5');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('20','Geschmacksverstärker');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('20','Geschmacksverstärker','6');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('21','Süßungsmittel');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('21','Süßungsmittel','7');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO allergy (id,name)
|
||||
VALUES('22','Konservierungsstoff');""");
|
||||
INSERT OR IGNORE INTO allergy (id,name,handle)
|
||||
VALUES('22','Konservierungsstoff','8');""");
|
||||
sqls.add("""
|
||||
INSERT OR IGNORE INTO severity (id,name)
|
||||
VALUES('1','Harmlos');""");
|
||||
|
54
src/main/java/com/bib/essensbestellungsverwaltung/Food.java
Normal file
54
src/main/java/com/bib/essensbestellungsverwaltung/Food.java
Normal file
@ -0,0 +1,54 @@
|
||||
package com.bib.essensbestellungsverwaltung;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Food {
|
||||
private long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private boolean isDessert;
|
||||
private FoodType foodType;
|
||||
private List<Allergy> allergies;
|
||||
|
||||
public Food(long id, String name, String description, boolean isDessert, FoodType foodType, List<Allergy> allergies) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.isDessert = isDessert;
|
||||
this.foodType = foodType;
|
||||
this.allergies = allergies;
|
||||
}
|
||||
|
||||
public Food(String name, String description, boolean isDessert, FoodType foodType, List<Allergy> allergies) {
|
||||
this.id = -1;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.isDessert = isDessert;
|
||||
this.foodType = foodType;
|
||||
this.allergies = allergies;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public boolean isDessert() {
|
||||
return isDessert;
|
||||
}
|
||||
|
||||
public FoodType getFoodType() {
|
||||
return foodType;
|
||||
}
|
||||
|
||||
public List<Allergy> getAllergies() {
|
||||
return allergies;
|
||||
}
|
||||
}
|
@ -6,21 +6,21 @@ package com.bib.essensbestellungsverwaltung;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class FoodMgr {
|
||||
/**
|
||||
* inserts a food int to the database and creates the food_restriction entries
|
||||
* @param foodData name, description, isdessert, food_typeid
|
||||
* @param allergyData allergyids
|
||||
* @return id of food or -1
|
||||
*/
|
||||
public static long createFood(String[] foodData, String[] allergyData){
|
||||
public static long createFood(Food food){
|
||||
String[] foodH = {"name","description","isDessert","food_typeid"};
|
||||
String[] food_restrictionH = {"foodid","allergyid"};
|
||||
long id = Database.insert("food",foodH,foodData);
|
||||
if(allergyData.length > 0){
|
||||
String[] foodD = {food.getName(),food.getDescription(),(food.isDessert() ? "1" : "0"), String.valueOf(food.getFoodType().getId())};
|
||||
long id = Database.insert("food",foodH,foodD);
|
||||
if(food.getAllergies().size() > 0){
|
||||
String sId = String.valueOf(id);
|
||||
for (String allergyId : allergyData) {
|
||||
String[] food_restrictionD = {sId,allergyId};
|
||||
for (Allergy allergy : food.getAllergies()) {
|
||||
String[] food_restrictionD = {sId, String.valueOf(allergy.getId())};
|
||||
Database.insert("food_restriction",food_restrictionH, food_restrictionD);
|
||||
}
|
||||
}
|
||||
@ -42,10 +42,16 @@ public class FoodMgr {
|
||||
* @param isDessert true for only desserts false for non desserts
|
||||
* @return a list of all non desserts or all desserts
|
||||
*/
|
||||
public static List<String> getFood(boolean isDessert){
|
||||
public static List<Food> getFood(boolean isDessert){
|
||||
String[] foodH = {"isDessert"};
|
||||
String[] foodD = {(isDessert ? "1" : "0")};
|
||||
return Database.select("food",foodH,foodD);
|
||||
List<String> entries = Database.select("food",foodH,foodD);
|
||||
List<Food> foods = new ArrayList<>();
|
||||
for (String entry : entries) {
|
||||
String[] parts = entry.split(":");
|
||||
foods.add(getFoodById(Long.parseLong(parts[0])));
|
||||
}
|
||||
return foods;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,10 +59,16 @@ public class FoodMgr {
|
||||
* @param isDessert true for only desserts false for non desserts
|
||||
* @return a list of all vegan non desserts or all vegan desserts
|
||||
*/
|
||||
public static List<String> getVeganFood(boolean isDessert){
|
||||
public static List<Food> getVeganFood(boolean isDessert){
|
||||
String[] foodH = {"isDessert","food_typeid"};
|
||||
String[] foodD = {(isDessert ? "1" : "0"),"1"};
|
||||
return Database.select("food",foodH,foodD);
|
||||
List<String> entries = Database.select("food",foodH,foodD);
|
||||
List<Food> foods = new ArrayList<>();
|
||||
for (String entry : entries) {
|
||||
String[] parts = entry.split(":");
|
||||
foods.add(getFoodById(Long.parseLong(parts[0])));
|
||||
}
|
||||
return foods;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,8 +82,42 @@ public class FoodMgr {
|
||||
return Database.select("food_plan",food_planH,food_planD);
|
||||
}
|
||||
|
||||
public static List<String> getFoodById(long id){
|
||||
return Database.getEntryById("food",id);
|
||||
public static Food getFoodById(long id){
|
||||
List<String> entry = Database.getEntryById("food",id);
|
||||
String[] parts = entry.get(0).split(":");
|
||||
String name = parts[1];
|
||||
String description = parts[2];
|
||||
boolean isDessert;
|
||||
isDessert = parts[3].equals("0");
|
||||
FoodType foodType = getFoodTypeById(Long.parseLong(parts[4]));
|
||||
List<Allergy> allergies = getAllergies(id);
|
||||
return new Food(id,name,description,isDessert,foodType,allergies);
|
||||
}
|
||||
|
||||
public static FoodType getFoodTypeById(long id){
|
||||
List<String> entry = Database.getEntryById("foodtype",id);
|
||||
String[] typeParts = entry.get(0).split(":");
|
||||
return new FoodType(Long.parseLong(typeParts[0]),typeParts[1]);
|
||||
}
|
||||
|
||||
public static Allergy getAllergyById(long id){
|
||||
String[] allergyH = {"id"};
|
||||
String[] allergyD = {String.valueOf(id)};
|
||||
List<String> allergies = Database.select("allergy",allergyH,allergyD);
|
||||
String[] allergyParts = allergies.get(0).split(":");
|
||||
return new Allergy(id,allergyParts[1],allergyParts[2]);
|
||||
}
|
||||
|
||||
public static List<Allergy> getAllergies(long foodId){
|
||||
List<Allergy> allergies = new ArrayList<>();
|
||||
String[] restrictionsH = {"foodid"};
|
||||
String[] restrictionsD = {String.valueOf(foodId)};
|
||||
List<String> restrictions = Database.select("food_restrictions",restrictionsH,restrictionsD);
|
||||
for (String restriction : restrictions) {
|
||||
String[] partsRestrictions = restriction.split(":");
|
||||
allergies.add(getAllergyById(Long.parseLong(partsRestrictions[2])));
|
||||
}
|
||||
return allergies;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,11 +146,10 @@ public class FoodMgr {
|
||||
List<String> food_plan = getFood_plan(date);
|
||||
String[] food_planParts = food_plan.get(0).split(":");
|
||||
for(int i = 2; i < 2+4; i++){
|
||||
List<String> food = getFoodById(Long.parseLong(food_planParts[i]));
|
||||
String[] foodParts = food.get(0).split(":");
|
||||
String foodName = foodParts[1];
|
||||
Food food = getFoodById(Long.parseLong(food_planParts[i]));
|
||||
String foodName = food.getName();
|
||||
String[] food_selectionH = {"food_planid","foodid"};
|
||||
String[] food_selectionD = {food_planParts[0],foodParts[0]};
|
||||
String[] food_selectionD = {food_planParts[0], String.valueOf(food.getId())};
|
||||
int count = Database.count("food_selection",food_selectionH,food_selectionD);
|
||||
orders.add(foodName+":"+count);
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.bib.essensbestellungsverwaltung;
|
||||
|
||||
public class FoodType {
|
||||
private long id;
|
||||
private String name;
|
||||
|
||||
public FoodType(long id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
55
src/main/java/com/bib/essensbestellungsverwaltung/User.java
Normal file
55
src/main/java/com/bib/essensbestellungsverwaltung/User.java
Normal file
@ -0,0 +1,55 @@
|
||||
package com.bib.essensbestellungsverwaltung;
|
||||
|
||||
public class User {
|
||||
private long id;
|
||||
private String name;
|
||||
private String firstname;
|
||||
private String password;
|
||||
private String email;
|
||||
private Address address;
|
||||
private boolean isWorker;
|
||||
private boolean isParent;
|
||||
|
||||
public User(long id, String name, String firstname, String password, String email, Address address, boolean isWorker, boolean isParent) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.firstname = firstname;
|
||||
this.password = password;
|
||||
this.email = email;
|
||||
this.address = address;
|
||||
this.isWorker = isWorker;
|
||||
this.isParent = isParent;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public Address getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public boolean isWorker() {
|
||||
return isWorker;
|
||||
}
|
||||
|
||||
public boolean isParent() {
|
||||
return isParent;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user