Kommentare 2: electric boogaloo
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
package com.bib.essensbestellungsverwaltung;
|
||||
/*
|
||||
@author Malte Schulze Hobeling
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* A collection of functions loosely related to food management
|
||||
* Acts as an abstraction layer to the database
|
||||
* @author Malte Schulze Hobeling
|
||||
*/
|
||||
public class FoodMgr {
|
||||
/**
|
||||
* inserts a food int to the database and creates the food_restriction entries
|
||||
* @param food the food to be created
|
||||
* @return id of food or -1
|
||||
* @author Malte Schulze Hobeling
|
||||
*/
|
||||
public static long createFood(Food food){
|
||||
String[] foodH = {"name","description","isDessert","food_typeid"};
|
||||
@@ -29,7 +32,9 @@ public class FoodMgr {
|
||||
|
||||
/**
|
||||
* inserts a food_plan into the database
|
||||
* @param foodPlan the foodPlan to be created
|
||||
* @return id of food_plan or -1
|
||||
* @author Malte Schulze Hobeling
|
||||
*/
|
||||
public static long createFood_plan(FoodPlan foodPlan){
|
||||
String[] food_planH = {"date","food1","food2","dessert1","dessert2"};
|
||||
@@ -45,6 +50,7 @@ public class FoodMgr {
|
||||
* 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
|
||||
* @author Malte Schulze Hobeling
|
||||
*/
|
||||
public static List<Food> getFood(boolean isDessert){
|
||||
String[] foodH = {"isDessert"};
|
||||
@@ -62,6 +68,7 @@ public class FoodMgr {
|
||||
* 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
|
||||
* @author Malte Schulze Hobeling
|
||||
*/
|
||||
public static List<Food> getVeganFood(boolean isDessert){
|
||||
String[] foodH = {"isDessert","food_typeid"};
|
||||
@@ -79,6 +86,7 @@ public class FoodMgr {
|
||||
* returns a food_plan for a day
|
||||
* @param date YYYY-MM-DD one day
|
||||
* @return food_plan for date
|
||||
* @author Malte Schulze Hobeling
|
||||
*/
|
||||
public static FoodPlan getFoodPlan(String date){
|
||||
String[] food_planH = {"date"};
|
||||
@@ -93,8 +101,17 @@ public class FoodMgr {
|
||||
return new FoodPlan(Long.parseLong(parts[0]),date,foodVegan,foodSecond,dessertVegan,dessertSecond,isSent);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a FoodPlan for a given id or null if no unique id was found
|
||||
* @param id id of the FoodPlan
|
||||
* @return FoodPlan or null
|
||||
* @author Malte Schulze Hobeling
|
||||
*/
|
||||
public static FoodPlan getFoodPlanById(long id){
|
||||
List<String> entry = Database.getEntryById("food_plan",id);
|
||||
if(entry.size() != 1){
|
||||
return null;
|
||||
}
|
||||
String[] parts = entry.get(0).split(":");
|
||||
Food foodVegan = getFoodById(Long.parseLong(parts[2]));
|
||||
Food foodSecond = getFoodById(Long.parseLong(parts[3]));
|
||||
@@ -104,8 +121,17 @@ public class FoodMgr {
|
||||
return new FoodPlan(id,parts[1], foodVegan,foodSecond,dessertVegan,dessertSecond,isSent);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a Food for a given id or null if no unique id was found
|
||||
* @param id id of the Food
|
||||
* @return Food or null
|
||||
* @author Malte Schulze Hobeling
|
||||
*/
|
||||
public static Food getFoodById(long id){
|
||||
List<String> entry = Database.getEntryById("food",id);
|
||||
if(entry.size() != 1){
|
||||
return null;
|
||||
}
|
||||
String[] parts = entry.get(0).split(":");
|
||||
String name = parts[1];
|
||||
String description = parts[2];
|
||||
@@ -116,20 +142,44 @@ public class FoodMgr {
|
||||
return new Food(id,name,description,isDessert,foodType,allergies);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a FoodType for a given id or null if no unique id was found
|
||||
* @param id id of the FoodType
|
||||
* @return FoodType or null
|
||||
* @author Malte Schulze Hobeling
|
||||
*/
|
||||
public static FoodType getFoodTypeById(long id){
|
||||
List<String> entry = Database.getEntryById("food_type",id);
|
||||
if(entry.size() != 1){
|
||||
return null;
|
||||
}
|
||||
String[] typeParts = entry.get(0).split(":");
|
||||
return new FoodType(Long.parseLong(typeParts[0]),typeParts[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an Allergy for a given id or null if no unique id was found
|
||||
* @param id id of the Allergy
|
||||
* @return Allergy or null
|
||||
* @author Malte Schulze Hobeling
|
||||
*/
|
||||
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(":");
|
||||
List<String> entry = Database.select("allergy",allergyH,allergyD);
|
||||
if(entry.size() != 1){
|
||||
return null;
|
||||
}
|
||||
String[] allergyParts = entry.get(0).split(":");
|
||||
return new Allergy(id,allergyParts[1],allergyParts[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns all Allergies for a given foodId
|
||||
* @param foodId the foodId you want the allergies from
|
||||
* @return a List of Allergy, can be empty
|
||||
* @author Malte Schulze Hobeling
|
||||
*/
|
||||
public static List<Allergy> getAllergies(long foodId){
|
||||
List<Allergy> allergies = new ArrayList<>();
|
||||
String[] restrictionsH = {"foodid"};
|
||||
@@ -146,11 +196,12 @@ public class FoodMgr {
|
||||
* 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
|
||||
* @author Malte Schulze Hobeling
|
||||
*/
|
||||
public static long createFood_selection(String[] food_selectionData){
|
||||
String[] food_selectionH = {"childid","food_planid","foodid"};
|
||||
FoodPlan food_plan = getFoodPlanById(Long.parseLong(food_selectionData[1]));
|
||||
if(!food_plan.isSent()){
|
||||
if(food_plan != null && !food_plan.isSent()){
|
||||
return Database.insert("food_selection",food_selectionH,food_selectionData);
|
||||
}else {
|
||||
return -1;
|
||||
@@ -161,6 +212,7 @@ 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
|
||||
* @author Malte Schulze Hobeling
|
||||
*/
|
||||
public static List<String> getDayOrder(String date){
|
||||
List<String> orders = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user