#27 gardenplanmodel bugfixed cropid

This commit is contained in:
Gian-Andrea Hutter 2022-11-04 15:32:15 +01:00
parent d45b8e116e
commit 2361afd537
3 changed files with 9 additions and 6 deletions

View File

@ -12,9 +12,9 @@ import ch.zhaw.gartenverwaltung.types.Task;
import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
/**
@ -24,6 +24,7 @@ public class Gardenplanmodel {
private GardenPlan gardenPlan;
private List<Crop> cropList;
private TaskListModel taskListModel;
private Object IllegalArgumentException;
/**
* Constructor of Gardenplan model
@ -48,7 +49,7 @@ public class Gardenplanmodel {
* @throws PlantNotFoundException If the plant is not found in the database.
*/
public void plantAsCrop(Plant plant, LocalDate plantingDate) throws IOException, HardinessZoneNotSetException, PlantNotFoundException {
Crop crop = new Crop(plant.id(),plantingDate);
Crop crop = new Crop(plant.id(), plantingDate);
//TODO Add Area to Plant
//crop.withArea(0);
gardenPlan.saveCrop(crop);
@ -63,9 +64,8 @@ public class Gardenplanmodel {
* @throws IOException If the database cannot be accessed
*/
public void removeCrop(Crop crop) throws IOException {
gardenPlan.removeCrop(crop);
taskListModel.removeTasksForCrop(crop);
taskListModel.removeTasksForCrop(crop.getCropId().orElseThrow(IllegalArgumentException::new));
cropList = gardenPlan.getCrops();
}
/**

View File

@ -159,5 +159,8 @@ public class JsonTaskDatabase implements TaskDatabase{
(res, task) -> res.put(task.getId(), task),
(existing, replacement) -> {});
}
Long maxId = taskMap.isEmpty() ? 0L : Collections.max(taskMap.keySet());
idProvider = new IdProvider(maxId);
}
}

View File

@ -21,11 +21,11 @@ public class Task {
* default constructor
* (used by Json deserializer)
*/
public Task(long cropId){
public Task(){
name= "";
description= "";
startDate = LocalDate.now();
this.cropId = cropId;
// this.cropId = cropId;
}
public Task(String name, String description, LocalDate startDate, long cropId) {