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(); taskSerie.getTasks().clear();
taskSeriesRepository.delete(taskSerie); taskSeriesRepository.delete(taskSerie);
} else { } 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)); taskSerie.getTasks().sort(Comparator.comparingInt(TaskSerieItem::getSeriesIndex));
List<TaskSerieItem> updatedItems = new ArrayList<>(); List<TaskSerieItem> updatedItems = new ArrayList<>();
int currentIndex = 1;
for(TaskSerieItem taskSerieItem : taskSerie.getTasks()) { for(TaskSerieItem taskSerieItem : taskSerie.getTasks()) {
if(taskSerieItem.getSeriesIndex() != currentIndex) { if(taskSerieItem.getSeriesIndex() > deletedIndex) {
taskSerieItem.setSeriesIndex(currentIndex); taskSerieItem.setSeriesIndex(taskSerieItem.getSeriesIndex() -1);
updatedItems.add(taskSerieItem); updatedItems.add(taskSerieItem);
} }
currentIndex++;
} }
taskSerieItemRepository.saveAll(updatedItems); taskSerieItemRepository.saveAll(updatedItems);