Skip to content

Commit

Permalink
Refactored EditTaskDetails to Edit Task
Browse files Browse the repository at this point in the history
  • Loading branch information
wennapengooin committed Aug 11, 2023
1 parent 1966692 commit 64bf569
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface ProjectViewingAndModificationOutputBoundary {

void displayDeletedColumn(ColumnModel columnModel);

void displayChangedTaskDetails(UUID taskID, TaskViewModel task, UUID columnID);
void displayChangedTaskDetails(TaskModel task, UUID columnID);

void displayDeleteProject(ProjectViewModel project, UUID projectId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public DeleteTask(Project currentProject) {
// Review whether entities should have arraylists or lists.ArrayLists more
// flexible
// Review whether models should be updated like entities
public void deleteTask(UUID ColumnID, TaskModel taskModel) {
public void deleteTask(UUID columnID, TaskModel taskModel) {
// Delete Task from Column entity's list of tasks'
// First get the list of columns in the current project
List<Column> listOfColumns = currentProject.getColumns();
// Then search for the column entity
Column currentColumn = Column.IDToColumn(ColumnID, listOfColumns);
Column currentColumn = Column.IDToColumn(columnID, listOfColumns);
// Then search for the Task entity
List<Task> listOfTasks = currentColumn.getTasks();
Task task = Task.IDToTask(taskModel.getID(), (ArrayList<Task>) listOfTasks);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package b_application_business_rules.use_cases.project_viewing_and_modification_use_cases;

import a_enterprise_business_rules.entities.Project;

import b_application_business_rules.entity_models.TaskModel;

import java.util.UUID;

/**
* A use case class for editing task details (name and description)
*/
public class EditTask {

private final Project currentProject;

public EditTask(Project currentProject) {
this.currentProject = currentProject;
}

/**
* Edits the task's details
*/
public void editTask(UUID columnID, TaskModel taskModel) {
// This feature initializes calls other use cases to avoid duplicate code
DeleteTask deleteTaskUseCase = new DeleteTask(currentProject);
deleteTaskUseCase.deleteTask(columnID, taskModel);
AddTask addTaskUseCase = new AddTask(currentProject);
addTaskUseCase.addTask(columnID, taskModel);

}



}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
import b_application_business_rules.use_cases.CurrentProjectRepository;
import b_application_business_rules.use_cases.project_selection_gateways.IDBInsert;
import b_application_business_rules.use_cases.project_selection_gateways.IDBRemove;
import b_application_business_rules.use_cases.project_selection_gateways.IDBSearch;
import b_application_business_rules.use_cases.project_selection_gateways.IDbIdToModel;
import b_application_business_rules.use_cases.project_selection_use_cases.DeleteProject;
import c_interface_adapters.view_models.TaskViewModel;
import d_frameworks_and_drivers.database_management.DBControllers.DBManagerInsertController;
import d_frameworks_and_drivers.database_management.DBControllers.DBManagerRemoveController;
import d_frameworks_and_drivers.database_management.DBControllers.DBManagerSearchController;
import d_frameworks_and_drivers.database_management.DBControllers.DbIDToModel;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
Expand Down Expand Up @@ -186,22 +187,42 @@ public void editColumnDetails(UUID columnBoxId, String newColumnName) {

/**
* Changes the task details given the new TaskModel task. Calls the use case to
* make
* changes to the entities and database then calls the presenter to display the
* make changes to the entities and database then calls the presenter to display the
* updated changes
*
* @param task Task Model
* @param TaskUIid ID of task entity
*
*/
@Override
public void changeTaskDetails(TaskModel task, UUID TaskUIid, UUID ParentColumn) {
EditTaskDetails useCase = new EditTaskDetails(task, TaskUIid);
try {
useCase.editTask(ParentColumn);
//Call to presenter here was moved to the controller (changeTaskDetails)
}
catch(Exception e) {
e.printStackTrace();
}
public void changeTaskDetails(TaskModel updatedTask, UUID taskID, UUID columnID) {
// Initializes and call use case
EditTask editTask = new EditTask(currentProject);
editTask.editTask(columnID, updatedTask);

// calls presenter to display message
presenter.displayChangedTaskDetails(updatedTask, columnID);

// Initializing the controllers
IDBRemove removeTask = new DBManagerRemoveController();
IDBInsert insertTask = new DBManagerInsertController();
IDBSearch findOldTask = new DBManagerSearchController();

// Removing the existing task requires a TaskModel, which we don't have any
// So we need to make one: by finding all the information about the old task
// Then using the TaskFactory to create a TaskModel

ArrayList<String> oldTaskInfo = findOldTask.DBTaskSearch(taskID.toString());
String oldTaskName = oldTaskInfo.get(1);
String oldTaskDescription = oldTaskInfo.get(2);
boolean oldTaskStatus = Boolean.parseBoolean(oldTaskInfo.get(3));
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
LocalDateTime oldTaskDate = LocalDateTime.parse(oldTaskInfo.get(4), formatter);
// LocalDateTime oldTaskDate = LocalDateTime.parse(oldTaskInfo.get(4));
TaskModel oldTask = TaskModelFactory.create(oldTaskName, taskID,
oldTaskDescription, oldTaskStatus, oldTaskDate);

// Removing the old task
removeTask.DBRemove(oldTask, taskID);

// Inserting the new task
insertTask.DBInsert(updatedTask);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import b_application_business_rules.entity_models.TaskModel;
import b_application_business_rules.factories.TaskModelFactory;
import b_application_business_rules.use_cases.project_viewing_and_modification_use_cases.ProjectViewingAndModificationInteractor;
import c_interface_adapters.view_models.TaskViewModel;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
Expand Down Expand Up @@ -141,12 +140,6 @@ void changeTaskDetails(TaskModel task, HBox hbox, String newTaskName,
newDueDate);
interactor.changeTaskDetails(changedTask, taskID, columnID);

//Creating a TaskViewModel for display purposes
TaskViewModel newTask = new TaskViewModel(newTaskName, taskID, newTaskName,
taskStatus, newDueDate);

//Calling a handler to display the final task changes
presenter.displayChangedTaskDetails(taskID, newTask, columnID);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import b_application_business_rules.entity_models.ProjectModel;
import b_application_business_rules.entity_models.TaskModel;
import c_interface_adapters.view_models.ProjectViewModel;
import c_interface_adapters.view_models.TaskViewModel;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
Expand Down Expand Up @@ -206,14 +205,14 @@ public void displayDeletedColumn(ColumnModel columnModel) {
* This method renames the existing task and changes the task description and shows the final
* changes on the screen
*
* @param taskID
* @param task
* @param task updated task's entity model.
* @param columnID column ID of column that held task.
*/
@Override
public void displayChangedTaskDetails(UUID taskID, TaskViewModel task, UUID columnID) {
public void displayChangedTaskDetails(TaskModel task, UUID columnID) {
String taskName = task.getName();

Text taskNameUI = uiComponentLocator.findTaskName(taskID, columnID);
Text taskNameUI = uiComponentLocator.findTaskName(task.getID(), columnID);
if (taskNameUI != null) {
taskNameUI.setText(taskName);
} else {
Expand Down

0 comments on commit 64bf569

Please sign in to comment.