von der Wiege bis zur Bahre, Kommentare, Kommentare

This commit is contained in:
2023-01-16 16:35:45 +01:00
parent 573e17161b
commit 0dcec76379
3 changed files with 151 additions and 10 deletions

View File

@@ -7,6 +7,12 @@ 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){
String[] foodH = {"name","description","isDessert","food_typeid"};
String[] food_restrictionH = {"foodid","allergyid"};
@@ -21,23 +27,43 @@ public class FoodMgr {
return id;
}
/**
* inserts a food_plan into the database
* @param food_planData date[YYYY-MM-DD], foodid[vegan], foodid, foodid[dessert,vegan], foodid[dessert]
* @return id of food_plan or -1
*/
public static long createFood_plan(String[] food_planData){
String[] food_planH = {"date","food1","food2","dessert1","dessert2"};
return Database.insert("food_plan",food_planH,food_planData);
}
/**
* returns all non desserts or all desserts
* @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){
String[] foodH = {"isDessert"};
String[] foodD = {(isDessert ? "1" : "0")};
return Database.select("food",foodH,foodD);
}
/**
* getFood but returns only vegan food
* @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){
String[] foodH = {"isDessert","food_typeid"};
String[] foodD = {(isDessert ? "1" : "0"),"1"};
return Database.select("food",foodH,foodD);
}
/**
* returns a food_plan for a day
* @param date YYYY-MM-DD one day
* @return food_plan for date
*/
public static List<String> getFood_plan(String date){
String[] food_planH = {"date"};
String[] food_planD = {date};
@@ -48,6 +74,11 @@ public class FoodMgr {
return Database.getEntryById("food",id);
}
/**
* inserts the selected food into food_Selection if the food_plan has not been sent
* @param food_selectionData childid, food_planid, foodid
* @return id or -1
*/
public static long createFood_selection(String[] food_selectionData){
String[] food_selectionH = {"childid","food_planid","foodid"};
List<String> food_plan = Database.getEntryById("food_plan",Long.parseLong(food_selectionData[1]));
@@ -59,6 +90,11 @@ public class FoodMgr {
}
}
/**
* accumulates the selected food for a given day and locks the corresponding food_plan
* @param date YYYY-MM-DD day
* @return the accumulated orders
*/
public static List<String> getDayOrder(String date){
List<String> orders = new ArrayList<>();
List<String> food_plan = getFood_plan(date);