Refactoring RetrieveTaskFromTaskListCommand to *Query

This commit is contained in:
ronsei 2021-10-04 12:10:42 +02:00
parent 5b835bc6bc
commit ebb91a6010
4 changed files with 7 additions and 7 deletions

View File

@ -1,6 +1,6 @@
package ch.unisg.tapastasks.tasks.adapter.in.web; package ch.unisg.tapastasks.tasks.adapter.in.web;
import ch.unisg.tapastasks.tasks.application.port.in.RetrieveTaskFromTaskListCommand; import ch.unisg.tapastasks.tasks.application.port.in.RetrieveTaskFromTaskListQuery;
import ch.unisg.tapastasks.tasks.application.port.in.RetrieveTaskFromTaskListUseCase; import ch.unisg.tapastasks.tasks.application.port.in.RetrieveTaskFromTaskListUseCase;
import ch.unisg.tapastasks.tasks.domain.Task; import ch.unisg.tapastasks.tasks.domain.Task;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -21,7 +21,7 @@ public class RetrieveTaskFromTaskListWebController {
@GetMapping(path = "/tasks/{taskId}") @GetMapping(path = "/tasks/{taskId}")
public ResponseEntity<String> retrieveTaskFromTaskList(@PathVariable("taskId") String taskId) { public ResponseEntity<String> retrieveTaskFromTaskList(@PathVariable("taskId") String taskId) {
RetrieveTaskFromTaskListCommand command = new RetrieveTaskFromTaskListCommand(new Task.TaskId(taskId)); RetrieveTaskFromTaskListQuery command = new RetrieveTaskFromTaskListQuery(new Task.TaskId(taskId));
Optional<Task> updatedTaskOpt = retrieveTaskFromTaskListUseCase.retrieveTaskFromTaskList(command); Optional<Task> updatedTaskOpt = retrieveTaskFromTaskListUseCase.retrieveTaskFromTaskList(command);
// Check if the task with the given identifier exists // Check if the task with the given identifier exists

View File

@ -7,11 +7,11 @@ import lombok.Value;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
@Value @Value
public class RetrieveTaskFromTaskListCommand extends SelfValidating<RetrieveTaskFromTaskListCommand> { public class RetrieveTaskFromTaskListQuery extends SelfValidating<RetrieveTaskFromTaskListQuery> {
@NotNull @NotNull
private final TaskId taskId; private final TaskId taskId;
public RetrieveTaskFromTaskListCommand(TaskId taskId) { public RetrieveTaskFromTaskListQuery(TaskId taskId) {
this.taskId = taskId; this.taskId = taskId;
this.validateSelf(); this.validateSelf();
} }

View File

@ -5,5 +5,5 @@ import ch.unisg.tapastasks.tasks.domain.Task;
import java.util.Optional; import java.util.Optional;
public interface RetrieveTaskFromTaskListUseCase { public interface RetrieveTaskFromTaskListUseCase {
Optional<Task> retrieveTaskFromTaskList(RetrieveTaskFromTaskListCommand command); Optional<Task> retrieveTaskFromTaskList(RetrieveTaskFromTaskListQuery command);
} }

View File

@ -1,6 +1,6 @@
package ch.unisg.tapastasks.tasks.application.service; package ch.unisg.tapastasks.tasks.application.service;
import ch.unisg.tapastasks.tasks.application.port.in.RetrieveTaskFromTaskListCommand; import ch.unisg.tapastasks.tasks.application.port.in.RetrieveTaskFromTaskListQuery;
import ch.unisg.tapastasks.tasks.application.port.in.RetrieveTaskFromTaskListUseCase; import ch.unisg.tapastasks.tasks.application.port.in.RetrieveTaskFromTaskListUseCase;
import ch.unisg.tapastasks.tasks.domain.Task; import ch.unisg.tapastasks.tasks.domain.Task;
import ch.unisg.tapastasks.tasks.domain.TaskList; import ch.unisg.tapastasks.tasks.domain.TaskList;
@ -15,7 +15,7 @@ import java.util.Optional;
@Transactional @Transactional
public class RetrieveTaskFromTaskListService implements RetrieveTaskFromTaskListUseCase { public class RetrieveTaskFromTaskListService implements RetrieveTaskFromTaskListUseCase {
@Override @Override
public Optional<Task> retrieveTaskFromTaskList(RetrieveTaskFromTaskListCommand command) { public Optional<Task> retrieveTaskFromTaskList(RetrieveTaskFromTaskListQuery command) {
TaskList taskList = TaskList.getTapasTaskList(); TaskList taskList = TaskList.getTapasTaskList();
return taskList.retrieveTaskById(command.getTaskId()); return taskList.retrieveTaskById(command.getTaskId());
} }