Implemented the remove task workflow. Still got one todo for the workflow that I want to discuss

This commit is contained in:
reynisson
2021-12-14 23:46:07 +01:00
parent 45edd76c8b
commit 3e141e5318
9 changed files with 37 additions and 38 deletions

View File

@@ -3,6 +3,7 @@ package ch.unisg.roster.roster.adapter.in.web;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@@ -22,10 +23,10 @@ public class DeleteTaskController {
* Controller to delete a task
* @return 200 OK, 409 Conflict
**/
@DeleteMapping(path = "/task", consumes = {"application/task+json"})
public ResponseEntity<Void> applyForTask(@RequestBody Task task) {
@DeleteMapping(path = "/task/{taskId}")
public ResponseEntity<Void> deleteTask(@PathVariable("taskId") String taskId) {
DeleteTaskCommand command = new DeleteTaskCommand(task.getTaskID(), task.getTaskType());
DeleteTaskCommand command = new DeleteTaskCommand(taskId);
if (deleteTaskUseCase.deleteTask(command)) {
return new ResponseEntity<>(HttpStatus.OK);

View File

@@ -13,12 +13,8 @@ public class DeleteTaskCommand extends SelfValidating<ApplyForTaskCommand> {
@NotNull
private final String taskId;
@NotNull
private final ExecutorType taskType;
public DeleteTaskCommand(String taskId, ExecutorType taskType) {
public DeleteTaskCommand(String taskId) {
this.taskId = taskId;
this.taskType = taskType;
this.validateSelf();
}
}

View File

@@ -21,7 +21,7 @@ public class DeleteTaskService implements DeleteTaskUseCase {
@Override
public boolean deleteTask(DeleteTaskCommand command) {
Roster roster = Roster.getInstance();
return roster.deleteTask(command.getTaskId(), command.getTaskType());
return roster.deleteTask(command.getTaskId());
}
}

View File

@@ -76,9 +76,14 @@ public class Roster {
* Deletes a task if it is still in the queue.
* @return Whether the task got deleted or not
**/
public boolean deleteTask(String taskID, ExecutorType taskType) {
public boolean deleteTask(String taskID) {
logger.log(Level.INFO, "Try to delete task with id {0}", taskID);
return queues.get(taskType.getValue()).removeIf(task -> task.getTaskID().equalsIgnoreCase(taskID));
for(var listOfTasks : queues.entrySet()){
if(listOfTasks.getValue().removeIf(task -> task.getTaskID().equals(taskID))){
return true;
}
}
return false;
}
public void initialiseRoster(List<RosterItem> rosterItemList){

View File

@@ -31,7 +31,7 @@ public class RosterTest {
assertThat(task.getTaskType().getValue().toString()).isEqualTo("TEST-TYPE");
assertThat(task.getTaskID()).isEqualTo("TEST-ID");
boolean empty_queue = roster.deleteTask("TEST-ID", new ExecutorType("TEST-TYPE"));
boolean empty_queue = roster.deleteTask("TEST-ID");
// TODO test that the task was removed from the Queue similar to below --> I don't know if it actually gets deleted or not
//assertThat(empty_queue).isEqualTo(true);
//assertThat(queues.size()).isEqualTo(0);
@@ -44,8 +44,8 @@ public class RosterTest {
queues.clear();
roster.addTaskToQueue(new Task("TEST-ID", "TEST-TYPE"));
boolean test = roster.deleteTask("TEST-ID", new ExecutorType("TEST-TYPE"));
boolean test = roster.deleteTask("TEST-ID");
// TODO Fix assert for queue
assertThat(test).isEqualTo(true);
assertThat(queues.size()).isEqualTo(1);
}