Delete and clear Tasks
This commit is contained in:
parent
fd62585a5f
commit
9cafeee769
@ -6,7 +6,11 @@
|
|||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Implementing edit route for tasks">
|
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Implementing edit route for tasks">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/../frontend/src/app/tasks/task-editor/task-editor.component.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/tasks/task-editor/task-editor.component.ts" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/core/api/controller/TaskController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/api/controller/TaskController.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/main/java/core/api/controller/TaskgroupController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/api/controller/TaskgroupController.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/main/java/core/entities/timemanager/Task.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/entities/timemanager/Task.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/main/java/core/repositories/timemanager/TaskRepository.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/repositories/timemanager/TaskRepository.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/main/java/core/services/TaskService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/services/TaskService.java" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@ -29,6 +33,9 @@
|
|||||||
</option>
|
</option>
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="JpbToolWindowState">
|
||||||
|
<option name="isToolWindowVisible" value="false" />
|
||||||
|
</component>
|
||||||
<component name="ProjectColorInfo">{
|
<component name="ProjectColorInfo">{
|
||||||
"customColor": "",
|
"customColor": "",
|
||||||
"associatedIndex": 6
|
"associatedIndex": 6
|
||||||
@ -85,7 +92,9 @@
|
|||||||
<workItem from="1696399523081" duration="666000" />
|
<workItem from="1696399523081" duration="666000" />
|
||||||
<workItem from="1696517800445" duration="3887000" />
|
<workItem from="1696517800445" duration="3887000" />
|
||||||
<workItem from="1696573678147" duration="111000" />
|
<workItem from="1696573678147" duration="111000" />
|
||||||
<workItem from="1697923629354" duration="2959000" />
|
<workItem from="1697923629354" duration="3164000" />
|
||||||
|
<workItem from="1697958018921" duration="91000" />
|
||||||
|
<workItem from="1697958118995" duration="2830000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="Structure Taskgroups in Hierarchies">
|
<task id="LOCAL-00001" summary="Structure Taskgroups in Hierarchies">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
|
@ -81,4 +81,19 @@ public class TaskController {
|
|||||||
return ResponseEntity.status(409).body(new SimpleStatusResponse("failed"));
|
return ResponseEntity.status(409).body(new SimpleStatusResponse("failed"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/tasks/{taskID}")
|
||||||
|
public ResponseEntity<?> deleteTask(@PathVariable long taskID) {
|
||||||
|
PermissionResult<Task> taskPermissionResult = taskService.getTaskPermissions(taskID, SecurityContextHolder.getContext().getAuthentication().getName());
|
||||||
|
if (!taskPermissionResult.isHasPermissions()) {
|
||||||
|
return ResponseEntity.status(403).body(new SimpleStatusResponse("failed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taskPermissionResult.getExitCode() == ServiceExitCode.MISSING_ENTITY) {
|
||||||
|
return ResponseEntity.status(404).body(new SimpleStatusResponse("failed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
taskService.deleteTask(taskPermissionResult.getResult());
|
||||||
|
return ResponseEntity.ok(new SimpleStatusResponse("success"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,9 @@ import core.api.models.auth.SimpleStatusResponse;
|
|||||||
import core.api.models.timemanager.taskgroup.TaskgroupEntityInfo;
|
import core.api.models.timemanager.taskgroup.TaskgroupEntityInfo;
|
||||||
import core.api.models.timemanager.taskgroup.TaskgroupFieldInfo;
|
import core.api.models.timemanager.taskgroup.TaskgroupFieldInfo;
|
||||||
import core.entities.timemanager.Taskgroup;
|
import core.entities.timemanager.Taskgroup;
|
||||||
import core.services.PermissionResult;
|
import core.services.*;
|
||||||
import core.services.ServiceExitCode;
|
|
||||||
import core.services.ServiceResult;
|
|
||||||
import core.services.TaskgroupService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.scheduling.config.Task;
|
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@ -24,9 +20,11 @@ import java.util.Set;
|
|||||||
public class TaskgroupController {
|
public class TaskgroupController {
|
||||||
|
|
||||||
private final TaskgroupService taskgroupService;
|
private final TaskgroupService taskgroupService;
|
||||||
|
private final TaskService taskService;
|
||||||
|
|
||||||
public TaskgroupController(@Autowired TaskgroupService taskgroupService) {
|
public TaskgroupController(@Autowired TaskgroupService taskgroupService, @Autowired TaskService taskService) {
|
||||||
this.taskgroupService = taskgroupService;
|
this.taskgroupService = taskgroupService;
|
||||||
|
this.taskService = taskService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/taskgroups")
|
@PutMapping("/taskgroups")
|
||||||
@ -95,4 +93,19 @@ public class TaskgroupController {
|
|||||||
Set<Taskgroup> children = taskgroupPermissionResult.getResult().getChildren();
|
Set<Taskgroup> children = taskgroupPermissionResult.getResult().getChildren();
|
||||||
return ResponseEntity.ok(children.stream().map(TaskgroupEntityInfo::new));
|
return ResponseEntity.ok(children.stream().map(TaskgroupEntityInfo::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/taskgroups/{taskgroupID}/clear")
|
||||||
|
public ResponseEntity<?> clearTasks(@PathVariable long taskgroupID) {
|
||||||
|
PermissionResult<Taskgroup> taskgroupPermissionResult = taskgroupService.getTaskgroupByIDAndUsername(taskgroupID, SecurityContextHolder.getContext().getAuthentication().getName());
|
||||||
|
if (!taskgroupPermissionResult.isHasPermissions()) {
|
||||||
|
return ResponseEntity.status(403).body(new SimpleStatusResponse("failed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taskgroupPermissionResult.getExitCode() == ServiceExitCode.MISSING_ENTITY) {
|
||||||
|
return ResponseEntity.status(404).body(new SimpleStatusResponse("failed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
taskService.clearTasks(taskgroupPermissionResult.getResult());
|
||||||
|
return ResponseEntity.ok(new SimpleStatusResponse("success"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package core.entities.timemanager;
|
|||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "tasks")
|
@Table(name = "tasks")
|
||||||
@ -91,4 +92,17 @@ public class Task {
|
|||||||
public void setFinished(boolean finished) {
|
public void setFinished(boolean finished) {
|
||||||
this.finished = finished;
|
this.finished = finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Task task = (Task) o;
|
||||||
|
return taskID == task.taskID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(taskID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,24 @@
|
|||||||
package core.repositories.timemanager;
|
package core.repositories.timemanager;
|
||||||
|
|
||||||
import core.entities.timemanager.Task;
|
import core.entities.timemanager.Task;
|
||||||
|
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.CrudRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface TaskRepository extends CrudRepository<Task, Long> {
|
public interface TaskRepository extends CrudRepository<Task, Long> {
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@Modifying
|
||||||
|
@Query(value = "DELETE FROM Task t WHERE t.taskgroup = ?1")
|
||||||
|
void deleteAllByTaskgroup(Taskgroup taskgroup);
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
@Modifying
|
||||||
|
@Query(value = "DELETE FROM Task t WHERE t.taskID = ?1")
|
||||||
|
void deleteByTaskID(long taskID);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import core.api.models.timemanager.tasks.TaskFieldInfo;
|
|||||||
import core.entities.timemanager.Task;
|
import core.entities.timemanager.Task;
|
||||||
import core.entities.timemanager.Taskgroup;
|
import core.entities.timemanager.Taskgroup;
|
||||||
import core.repositories.timemanager.TaskRepository;
|
import core.repositories.timemanager.TaskRepository;
|
||||||
|
import core.repositories.timemanager.TaskgroupRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -15,9 +16,12 @@ import java.util.Optional;
|
|||||||
public class TaskService {
|
public class TaskService {
|
||||||
|
|
||||||
private final TaskRepository taskRepository;
|
private final TaskRepository taskRepository;
|
||||||
|
private final TaskgroupRepository taskgroupRepository;
|
||||||
|
|
||||||
public TaskService(@Autowired TaskRepository taskRepository) {
|
public TaskService(@Autowired TaskRepository taskRepository,
|
||||||
|
TaskgroupRepository taskgroupRepository) {
|
||||||
this.taskRepository = taskRepository;
|
this.taskRepository = taskRepository;
|
||||||
|
this.taskgroupRepository = taskgroupRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServiceResult<Task> createTask(Taskgroup taskgroup, TaskFieldInfo taskFieldInfo) {
|
public ServiceResult<Task> createTask(Taskgroup taskgroup, TaskFieldInfo taskFieldInfo) {
|
||||||
@ -61,4 +65,12 @@ public class TaskService {
|
|||||||
taskRepository.save(task);
|
taskRepository.save(task);
|
||||||
return new ServiceResult<>(task);
|
return new ServiceResult<>(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteTask(Task task) {
|
||||||
|
taskRepository.deleteByTaskID(task.getTaskID());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearTasks(Taskgroup taskgroup) {
|
||||||
|
taskRepository.deleteAllByTaskgroup(taskgroup);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user