Merge remote-tracking branch 'origin/feature_taskList_m2' into feature_gardenplan-model_M2

This commit is contained in:
Gian-Andrea Hutter 2022-10-31 14:28:06 +01:00
commit 521f3ae025
1 changed files with 15 additions and 3 deletions

View File

@ -1,7 +1,12 @@
package ch.zhaw.gartenverwaltung.taskList; package ch.zhaw.gartenverwaltung.taskList;
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
import ch.zhaw.gartenverwaltung.io.JsonTaskDatabase; import ch.zhaw.gartenverwaltung.io.JsonTaskDatabase;
import ch.zhaw.gartenverwaltung.io.PlantDatabase;
import ch.zhaw.gartenverwaltung.io.TaskDatabase; import ch.zhaw.gartenverwaltung.io.TaskDatabase;
import ch.zhaw.gartenverwaltung.types.Crop;
import ch.zhaw.gartenverwaltung.types.HardinessZone;
import ch.zhaw.gartenverwaltung.types.Plant;
import ch.zhaw.gartenverwaltung.types.Task; import ch.zhaw.gartenverwaltung.types.Task;
import java.io.IOException; import java.io.IOException;
@ -12,23 +17,30 @@ import java.util.stream.Collectors;
public class TaskListModel { public class TaskListModel {
private TaskDatabase taskDatabase; private TaskDatabase taskDatabase;
private PlantDatabase plantDatabase;
static final Comparator<Task> sortByStartDate = Comparator.comparing(Task::getStartDate); static final Comparator<Task> sortByStartDate = Comparator.comparing(Task::getStartDate);
public TaskListModel(){ public TaskListModel(){
taskDatabase = new JsonTaskDatabase(); taskDatabase = new JsonTaskDatabase();
} }
public TaskListModel(TaskDatabase taskDatabase) { public TaskListModel(TaskDatabase taskDatabase, PlantDatabase plantDatabase) {
this.taskDatabase = taskDatabase; this.taskDatabase = taskDatabase;
this.plantDatabase = plantDatabase;
} }
public void addTask(Task task) throws IOException { public void addTask(Task task) throws IOException {
taskDatabase.saveTask(task); taskDatabase.saveTask(task);
} }
public void planTasksForCrop(Crop crop) throws HardinessZoneNotSetException, IOException {
Plant plant = plantDatabase.getPlantById(HardinessZone.ZONE_8A, crop.getPlantId()).orElseThrow();
// TODO new exception
// TODO HArdiness Zone
return;
}
public void removeTask(Task task) throws IOException { public void removeTask(Task task) throws IOException {
taskDatabase.removeTask(task); taskDatabase.removeTask(task);
} }