Fix storing multiple TaskSerieItems for RootTask
All checks were successful
Java CI with Maven / build-and-push-frontend (push) Successful in 8s
Java CI with Maven / build-and-push-backend (push) Successful in 8s

This commit is contained in:
Sebastian Böckelmann 2024-03-15 15:32:31 +01:00
parent e102b91a1f
commit 717e8d4e45
2 changed files with 8 additions and 5 deletions

View File

@ -14,7 +14,7 @@ public class TaskSerieItem {
@JoinColumn(referencedColumnName = "taskSerieID") @JoinColumn(referencedColumnName = "taskSerieID")
private TaskSerie taskSerie; private TaskSerie taskSerie;
@OneToOne(cascade = CascadeType.ALL) @OneToOne
@JoinColumn(name = "task_id") @JoinColumn(name = "task_id")
private Task task; private Task task;

View File

@ -35,12 +35,11 @@ public class TaskSeriesService {
} }
List<Task> taskList = new ArrayList<>(); List<Task> taskList = new ArrayList<>();
taskList.add(rootTask);
LocalDate currentTaskDate = rootTask.getStartDate().plusDays(taskRepeatInfo.getOffset());
TaskSerie taskSerie = new TaskSerie(); TaskSerie taskSerie = new TaskSerie();
TaskSerieItem rootItem = taskSerie.addTask(rootTask); TaskSerieItem rootItem = taskSerie.addTask(rootTask);
rootTask.setTaskSerieItem(rootItem); rootTask.setTaskSerieItem(rootItem);
LocalDate currentTaskDate = rootTask.getStartDate().plusDays(taskRepeatInfo.getOffset());
int index = 2; int index = 2;
while(currentTaskDate.isBefore(taskRepeatInfo.getEndingDate())) { while(currentTaskDate.isBefore(taskRepeatInfo.getEndingDate())) {
Task task = Task.cloneTask(rootTask); Task task = Task.cloneTask(rootTask);
@ -69,7 +68,11 @@ public class TaskSeriesService {
TaskSerie taskSerie = task.getTaskSerieItem().getTaskSerie(); TaskSerie taskSerie = task.getTaskSerieItem().getTaskSerie();
task.setTaskSerieItem(null); task.setTaskSerieItem(null);
taskSerieItemRepository.delete(item); taskSerieItemRepository.delete(item);
if(taskSerie.getTasks().size() <= 1) { if(taskSerie.getTasks().isEmpty()) {
for(TaskSerieItem taskSerieItem : taskSerie.getTasks()) {
taskSerieItem.setTaskSerie(null);
}
taskSerie.getTasks().clear();
taskSeriesRepository.delete(taskSerie); taskSeriesRepository.delete(taskSerie);
} }
} }