issue-106 #107

Merged
sebastian merged 18 commits from issue-106 into master 2024-03-17 09:17:11 +01:00
Showing only changes of commit 56d75fead9 - Show all commits

View File

@ -141,21 +141,19 @@ public class TaskSeriesService {
taskSerie.getTasks().clear();
taskSeriesRepository.delete(taskSerie);
} else {
repearIndexing(taskSerie);
repearIndexing(taskSerie, item.getSeriesIndex());
}
}
private void repearIndexing(TaskSerie taskSerie) {
private void repearIndexing(TaskSerie taskSerie, int deletedIndex) {
taskSerie.getTasks().sort(Comparator.comparingInt(TaskSerieItem::getSeriesIndex));
List<TaskSerieItem> updatedItems = new ArrayList<>();
int currentIndex = 1;
for(TaskSerieItem taskSerieItem : taskSerie.getTasks()) {
if(taskSerieItem.getSeriesIndex() != currentIndex) {
taskSerieItem.setSeriesIndex(currentIndex);
if(taskSerieItem.getSeriesIndex() > deletedIndex) {
taskSerieItem.setSeriesIndex(taskSerieItem.getSeriesIndex() -1);
updatedItems.add(taskSerieItem);
}
currentIndex++;
}
taskSerieItemRepository.saveAll(updatedItems);