Clear Subtasks and fix indexing only when non subtask is deleted
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-17 09:16:20 +01:00
parent 56d75fead9
commit 4059500fa4
5 changed files with 54 additions and 2 deletions

View File

@ -196,4 +196,15 @@ public class TaskController {
Collection<Task> subtasks = taskPermissionResult.getResult().getSubtasks(); Collection<Task> subtasks = taskPermissionResult.getResult().getSubtasks();
return ResponseEntity.ok(subtasks.stream().map(TaskEntityInfo::new).toList()); return ResponseEntity.ok(subtasks.stream().map(TaskEntityInfo::new).toList());
} }
@DeleteMapping("/tasks/{taskID}/subtasks")
public ResponseEntity<?> onClearSubtasks(@PathVariable long taskID) {
var taskPermissionResult = taskService.getTaskPermissions(taskID, SecurityContextHolder.getContext().getAuthentication().getName());
if(taskPermissionResult.hasIssue()) {
return taskPermissionResult.mapToResponseEntity();
}
ServiceExitCode result = taskService.clearSubTasks(taskPermissionResult.getResult());
return result.mapToResponseEntity();
}
} }

View File

@ -44,4 +44,9 @@ public interface TaskRepository extends CrudRepository<Task, Long> {
@Transactional @Transactional
@Query(value = "UPDATE Task t SET t.parent = null WHERE t.taskgroup = ?1") @Query(value = "UPDATE Task t SET t.parent = null WHERE t.taskgroup = ?1")
void deleteTaskHierarchyWhereTaskgroup(Taskgroup taskgroup); void deleteTaskHierarchyWhereTaskgroup(Taskgroup taskgroup);
@Modifying
@Transactional
@Query(value = "DELETE Task t WHERE t.parent = ?1")
void deleteTasksByParent(Task parentTask);
} }

View File

@ -140,7 +140,7 @@ public class TaskSeriesService {
} }
taskSerie.getTasks().clear(); taskSerie.getTasks().clear();
taskSeriesRepository.delete(taskSerie); taskSeriesRepository.delete(taskSerie);
} else { } else if(task.getParent() == null){
repearIndexing(taskSerie, item.getSeriesIndex()); repearIndexing(taskSerie, item.getSeriesIndex());
} }
} }

View File

@ -159,4 +159,9 @@ public class TaskService {
} }
} }
public ServiceExitCode clearSubTasks(Task parentTask) {
taskRepository.deleteTasksByParent(parentTask);
return ServiceExitCode.OK;
}
} }

View File

@ -1349,7 +1349,38 @@ paths:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/SimpleStatusResponse' $ref: '#/components/schemas/SimpleStatusResponse'
delete:
security:
- API_TOKEN: []
tags:
- task
parameters:
- name: taskID
in: path
description: internal id of task
required: true
schema:
type: number
example: 1
responses:
200:
description: Operation successfull
content:
application/json:
schema:
$ref: '#/components/schemas/SimpleStatusResponse'
403:
description: No permission
content:
application/json:
schema:
$ref: '#/components/schemas/SimpleStatusResponse'
404:
description: Task not found
content:
application/json:
schema:
$ref: '#/components/schemas/SimpleStatusResponse'
/schedules: /schedules: