Added Task Adding, Removing, Editing and corrected some relatex tests. Coverage still not 100%

This commit is contained in:
2025-12-03 19:08:16 +01:00
parent 4fa55c8607
commit 20daf315ca
68 changed files with 2398 additions and 400 deletions

View File

@@ -7,13 +7,15 @@ import java.util.Map;
public class AssignmentManager {
Map<Integer, Worker> workerMap;
List<Task> taskList;
Map<Integer, Task> taskMap;
int workerIdCounter;
int taskIdCounter;
public AssignmentManager() {
workerMap = new HashMap<>();
taskList = new ArrayList<>();
taskMap = new HashMap<>();
int workerIdCounter = 1000;
int taskIdCounter = 0;
}
public int createWorker(String name) {
@@ -22,18 +24,34 @@ public class AssignmentManager {
return workerIdCounter;
}
public int addTask(int workerId, String name, String description) {
return 0;
if (!workerMap.containsKey(workerId) || name == null || description == null) {
throw new IllegalArgumentException("WorkerId must exist and name or description can't be null");
}
Task task = new Task(++taskIdCounter, workerId, name, description, this);
taskMap.put(taskIdCounter, task);
return taskIdCounter;
}
public Task getTask(int taskId) {
return null;
if (!taskMap.containsKey(taskId)) {
throw new IllegalArgumentException("Task Id does not exist");
}
return taskMap.get(taskId);
}
public ArrayList<Task> getTaskList() {
return null;
public Map<Integer, Task> getTaskMap() {
return taskMap;
}
public void editTask(int workerId, int taskId, String name, String description) {
if (!workerMap.containsKey(workerId) || !taskMap.containsKey(taskId)) {
throw new IllegalArgumentException("Task Id or Worker Id does not exist");
}
Task task = taskMap.get(taskId);
task.setName(name);
task.setDescription(description);
}
public void removeTask(int taskId) {
if (!taskMap.containsKey(taskId)) {
throw new IllegalArgumentException("Task Id does not exist");
}
taskMap.remove(taskId);
}
}

View File

@@ -5,7 +5,9 @@ public class Task {
String description;
int taskId;
int workerId;
public Task(int taskId, int workerId, String name, String description) {
AssignmentManager manager;
public Task(int taskId, int workerId, String name, String description, AssignmentManager manager) {
this.manager = manager;
this.name = name;
this.description = description;
this.taskId = taskId;