issue-77 #105

Merged
sebastian merged 17 commits from issue-77 into master 2024-03-16 10:12:35 +01:00
6 changed files with 33 additions and 3 deletions
Showing only changes of commit ec4a1cfbc7 - Show all commits

View File

@ -12,7 +12,7 @@ public class TaskSerie {
@GeneratedValue(strategy = GenerationType.AUTO)
private long taskSerieID;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "taskSerie")
@OneToMany(fetch = FetchType.EAGER, mappedBy = "taskSerie", orphanRemoval = true)
List<TaskSerieItem> tasks = new ArrayList<>();

View File

@ -20,6 +20,7 @@ public interface TaskRepository extends CrudRepository<Task, Long> {
@Modifying
@Transactional
@Query(value = "DELETE FROM Task t WHERE t.taskgroup = ?1")
void deleteAllByTaskgroup(Taskgroup taskgroup);
@Transactional

View File

@ -1,9 +1,19 @@
package core.repositories.timemanager;
import core.entities.timemanager.TaskSerieItem;
import core.entities.timemanager.Taskgroup;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import javax.transaction.Transactional;
@Repository
public interface TaskSerieItemRepository extends CrudRepository<TaskSerieItem, Long> {
@Query(value = "DELETE FROM TaskSerieItem tsi WHERE tsi.task IN (SELECT t FROM Task t WHERE t.taskgroup = ?1)")
@Modifying
@Transactional
void deleteByTaskgroup(Taskgroup taskgroup);
}

View File

@ -1,9 +1,23 @@
package core.repositories.timemanager;
import core.entities.timemanager.TaskSerie;
import core.entities.timemanager.Taskgroup;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import javax.transaction.Transactional;
import java.util.List;
@Repository
public interface TaskSeriesRepository extends CrudRepository<TaskSerie, Long> {
@Query("SELECT DISTINCT ts FROM TaskSerie ts JOIN ts.tasks tsi JOIN tsi.task t WHERE t.taskgroup = :taskgroup")
List<TaskSerie> findByTaskgroup(@Param("taskgroup")Taskgroup taskgroup);
@Modifying
@Transactional
@Query(value = "DELETE FROM TaskSerie ts WHERE ts.tasks.size = 0")
void deleteUnreferenced();
}

View File

@ -6,6 +6,7 @@ import core.api.models.timemanager.tasks.repeatinginfo.TaskRepeatWeekInfo;
import core.entities.timemanager.Task;
import core.entities.timemanager.TaskSerie;
import core.entities.timemanager.TaskSerieItem;
import core.entities.timemanager.Taskgroup;
import core.repositories.timemanager.TaskRepository;
import core.repositories.timemanager.TaskSerieItemRepository;
import core.repositories.timemanager.TaskSeriesRepository;
@ -40,7 +41,6 @@ public class TaskSeriesService {
rootTask.setTaskSerieItem(rootItem);
LocalDate currentTaskDate = rootTask.getStartDate().plusDays(taskRepeatInfo.getOffset());
int index = 2;
while(currentTaskDate.isBefore(taskRepeatInfo.getEndingDate())) {
Task task = Task.cloneTask(rootTask);
task.setStartDate(currentTaskDate);
@ -53,7 +53,6 @@ public class TaskSeriesService {
taskList.add(task);
task.setTaskSerieItem(taskSerieItem);
currentTaskDate = currentTaskDate.plusDays(taskRepeatInfo.getOffset());
index++;
}
taskSeriesRepository.save(taskSerie);
@ -77,6 +76,11 @@ public class TaskSeriesService {
}
}
public void deleteTaskSerieByTaskgroup(Taskgroup taskgroup) {
taskSerieItemRepository.deleteByTaskgroup(taskgroup);
taskSeriesRepository.deleteUnreferenced();
}
public static String convertIndexToString(int index) {
if(index < 10) {
return "0" + index;

View File

@ -100,6 +100,7 @@ public class TaskService {
}
public void clearTasks(Taskgroup taskgroup) {
taskSeriesService.deleteTaskSerieByTaskgroup(taskgroup);
taskRepository.deleteAllByTaskgroup(taskgroup);
}