#38 use java.net.uri for all ur is in the executor pool #55

Merged
reynisson merged 2 commits from #38_Use_java.net.URI_for_all_URIs_in_the_ExecutorPool into dev 2021-11-10 10:44:56 +00:00
18 changed files with 155 additions and 151 deletions

View File

@ -0,0 +1,51 @@
package ch.unisg.executorpool.adapter.common.formats;
import ch.unisg.executorpool.domain.ExecutorClass;
import lombok.Getter;
import lombok.Setter;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.List;
public class ExecutorJsonRepresentation {
public static final String EXECUTOR_MEDIA_TYPE = "application/json";
@Getter @Setter
private String executorUri;
@Getter @Setter
private String executorTaskType;
// TODO Check if this need Setters. Also applies to AuctionJsonRepresentation
public ExecutorJsonRepresentation(String executorUri, String executorTaskType){
this.executorUri = executorUri;
this.executorTaskType = executorTaskType;
}
public static String serialize(ExecutorClass executorClass) {
JSONObject payload = new JSONObject();
payload.put("executorUri", executorClass.getExecutorUri().getValue());
payload.put("executorTaskType", executorClass.getExecutorTaskType().getValue());
return payload.toString();
}
public static String serialize(List<ExecutorClass> listOfExecutors) {
JSONArray jsonArray = new JSONArray();
for (ExecutorClass executor: listOfExecutors) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("executorUri", executor.getExecutorUri().getValue());
jsonObject.put("executorTaskType", executor.getExecutorTaskType().getValue());
jsonArray.put(jsonObject);
}
return jsonArray.toString();
}
private ExecutorJsonRepresentation() { }
}

View File

@ -1,5 +1,6 @@
package ch.unisg.executorpool.adapter.in.web;
import ch.unisg.executorpool.adapter.common.formats.ExecutorJsonRepresentation;
import ch.unisg.executorpool.application.port.in.AddNewExecutorToExecutorPoolUseCase;
import ch.unisg.executorpool.application.port.in.AddNewExecutorToExecutorPoolCommand;
import ch.unisg.executorpool.domain.ExecutorClass;
@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
import javax.validation.ConstraintViolationException;
import java.net.URI;
@RestController
public class AddNewExecutorToExecutorPoolWebController {
@ -20,19 +22,20 @@ public class AddNewExecutorToExecutorPoolWebController {
this.addNewExecutorToExecutorPoolUseCase = addNewExecutorToExecutorPoolUseCase;
}
@PostMapping(path = "/executor-pool/AddExecutor", consumes = {ExecutorMediaType.EXECUTOR_MEDIA_TYPE})
public ResponseEntity<String> addNewExecutorToExecutorPool(@RequestBody ExecutorClass executorClass){
@PostMapping(path = "/executor-pool/AddExecutor", consumes = {ExecutorJsonRepresentation.EXECUTOR_MEDIA_TYPE})
public ResponseEntity<String> addNewExecutorToExecutorPool(@RequestBody ExecutorJsonRepresentation payload){
try{
AddNewExecutorToExecutorPoolCommand command = new AddNewExecutorToExecutorPoolCommand(
executorClass.getExecutorIp(), executorClass.getExecutorPort(), executorClass.getExecutorTaskType()
new ExecutorClass.ExecutorUri(URI.create(payload.getExecutorUri())),
new ExecutorClass.ExecutorTaskType(payload.getExecutorTaskType())
);
ExecutorClass newExecutor = addNewExecutorToExecutorPoolUseCase.addNewExecutorToExecutorPool(command);
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.add(HttpHeaders.CONTENT_TYPE, ExecutorMediaType.EXECUTOR_MEDIA_TYPE);
responseHeaders.add(HttpHeaders.CONTENT_TYPE, ExecutorJsonRepresentation.EXECUTOR_MEDIA_TYPE);
return new ResponseEntity<>(ExecutorMediaType.serialize(newExecutor), responseHeaders, HttpStatus.CREATED);
return new ResponseEntity<>(ExecutorJsonRepresentation.serialize(newExecutor), responseHeaders, HttpStatus.CREATED);
} catch (ConstraintViolationException e){
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
}

View File

@ -1,38 +0,0 @@
package ch.unisg.executorpool.adapter.in.web;
import ch.unisg.executorpool.domain.ExecutorClass;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.List;
final public class ExecutorMediaType {
public static final String EXECUTOR_MEDIA_TYPE = "application/json";
public static String serialize(ExecutorClass executorClass) {
JSONObject payload = new JSONObject();
payload.put("executorIp", executorClass.getExecutorIp().getValue());
payload.put("executorPort", executorClass.getExecutorPort().getValue());
payload.put("executorTaskType", executorClass.getExecutorTaskType().getValue());
return payload.toString();
}
public static String serialize(List<ExecutorClass> listOfExecutors) {
String serializedList = "[ \n";
for (ExecutorClass executor: listOfExecutors) {
serializedList += serialize(executor) + "\n";
}
// return serializedList + "\n ]";
JSONArray jsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
jsonObject.put("executorIp", "localhost");
jsonArray.put(jsonObject);
return jsonArray.toString();
}
private ExecutorMediaType() { }
}

View File

@ -1,35 +0,0 @@
package ch.unisg.executorpool.adapter.in.web;
import ch.unisg.executorpool.application.port.in.GetAllExecutorInExecutorPoolByTypeQuery;
import ch.unisg.executorpool.application.port.in.GetAllExecutorInExecutorPoolByTypeUseCase;
import ch.unisg.executorpool.domain.ExecutorClass;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorTaskType;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class GetAllExecutorInExecutorPoolByTypeWebController {
private final GetAllExecutorInExecutorPoolByTypeUseCase getAllExecutorInExecutorPoolByTypeUseCase;
public GetAllExecutorInExecutorPoolByTypeWebController(GetAllExecutorInExecutorPoolByTypeUseCase getAllExecutorInExecutorPoolByTypeUseCase){
this.getAllExecutorInExecutorPoolByTypeUseCase = getAllExecutorInExecutorPoolByTypeUseCase;
}
@GetMapping(path = "/executor-pool/GetAllExecutorInExecutorPoolByType/{taskType}")
public ResponseEntity<String> getAllExecutorInExecutorPoolByType(@PathVariable("taskType") String taskType){
GetAllExecutorInExecutorPoolByTypeQuery query = new GetAllExecutorInExecutorPoolByTypeQuery(new ExecutorTaskType(taskType));
List<ExecutorClass> matchedExecutors = getAllExecutorInExecutorPoolByTypeUseCase.getAllExecutorInExecutorPoolByType(query);
// Add the content type as a response header
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.add(HttpHeaders.CONTENT_TYPE, ExecutorMediaType.EXECUTOR_MEDIA_TYPE);
return new ResponseEntity<>(ExecutorMediaType.serialize(matchedExecutors), responseHeaders, HttpStatus.OK);
}
}

View File

@ -0,0 +1,36 @@
package ch.unisg.executorpool.adapter.in.web;
import ch.unisg.executorpool.adapter.common.formats.ExecutorJsonRepresentation;
import ch.unisg.executorpool.application.port.in.GetAllExecutorsInExecutorPoolByTypeQuery;
import ch.unisg.executorpool.application.port.in.GetAllExecutorsInExecutorPoolByTypeUseCase;
import ch.unisg.executorpool.domain.ExecutorClass;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorTaskType;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class GetAllExecutorsInExecutorPoolByTypeWebController {
private final GetAllExecutorsInExecutorPoolByTypeUseCase getAllExecutorsInExecutorPoolByTypeUseCase;
public GetAllExecutorsInExecutorPoolByTypeWebController(GetAllExecutorsInExecutorPoolByTypeUseCase getAllExecutorInExecutorPoolByTypeUseCase){
this.getAllExecutorsInExecutorPoolByTypeUseCase = getAllExecutorInExecutorPoolByTypeUseCase;
}
@GetMapping(path = "/executor-pool/GetAllExecutorsInExecutorPoolByType/{taskType}")
public ResponseEntity<String> getAllExecutorInExecutorPoolByType(@PathVariable("taskType") String taskType){
GetAllExecutorsInExecutorPoolByTypeQuery query = new GetAllExecutorsInExecutorPoolByTypeQuery(new ExecutorTaskType(taskType));
List<ExecutorClass> matchedExecutors = getAllExecutorsInExecutorPoolByTypeUseCase.getAllExecutorsInExecutorPoolByType(query);
// Add the content type as a response header
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.add(HttpHeaders.CONTENT_TYPE, ExecutorJsonRepresentation.EXECUTOR_MEDIA_TYPE);
return new ResponseEntity<>(ExecutorJsonRepresentation.serialize(matchedExecutors), responseHeaders, HttpStatus.OK);
}
}

View File

@ -1,5 +1,6 @@
package ch.unisg.executorpool.adapter.in.web;
import ch.unisg.executorpool.adapter.common.formats.ExecutorJsonRepresentation;
import ch.unisg.executorpool.application.port.in.GetAllExecutorsInExecutorPoolUseCase;
import ch.unisg.executorpool.domain.ExecutorClass;
import org.springframework.http.HttpHeaders;
@ -24,8 +25,8 @@ public class GetAllExecutorsInExecutorPoolWebController {
// Add the content type as a response header
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.add(HttpHeaders.CONTENT_TYPE, ExecutorMediaType.EXECUTOR_MEDIA_TYPE);
responseHeaders.add(HttpHeaders.CONTENT_TYPE, ExecutorJsonRepresentation.EXECUTOR_MEDIA_TYPE);
return new ResponseEntity<>(ExecutorMediaType.serialize(executorClassList), responseHeaders, HttpStatus.OK);
return new ResponseEntity<>(ExecutorJsonRepresentation.serialize(executorClassList), responseHeaders, HttpStatus.OK);
}
}

View File

@ -1,5 +1,6 @@
package ch.unisg.executorpool.adapter.in.web;
import ch.unisg.executorpool.adapter.common.formats.ExecutorJsonRepresentation;
import ch.unisg.executorpool.application.port.in.RemoveExecutorFromExecutorPoolCommand;
import ch.unisg.executorpool.application.port.in.RemoveExecutorFromExecutorPoolUseCase;
import ch.unisg.executorpool.domain.ExecutorClass;
@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
import java.net.URI;
import java.util.Optional;
@RestController
@ -21,9 +23,11 @@ public class RemoveExecutorFromExecutorPoolWebController {
this.removeExecutorFromExecutorPoolUseCase = removeExecutorFromExecutorPoolUseCase;
}
@PostMapping(path = "/executor-pool/RemoveExecutor", consumes = {ExecutorMediaType.EXECUTOR_MEDIA_TYPE})
public ResponseEntity<String> removeExecutorFromExecutorPool(@RequestBody ExecutorClass executorClass){
RemoveExecutorFromExecutorPoolCommand command = new RemoveExecutorFromExecutorPoolCommand(executorClass.getExecutorIp(), executorClass.getExecutorPort());
@PostMapping(path = "/executor-pool/RemoveExecutor", consumes = {ExecutorJsonRepresentation.EXECUTOR_MEDIA_TYPE})
public ResponseEntity<String> removeExecutorFromExecutorPool(@RequestBody ExecutorJsonRepresentation executorJsonRepresentation){
RemoveExecutorFromExecutorPoolCommand command = new RemoveExecutorFromExecutorPoolCommand(
new ExecutorClass.ExecutorUri(URI.create(executorJsonRepresentation.getExecutorUri()))
);
Optional<ExecutorClass> removedExecutor = removeExecutorFromExecutorPoolUseCase.removeExecutorFromExecutorPool(command);
if(removedExecutor.isEmpty()){
@ -31,9 +35,9 @@ public class RemoveExecutorFromExecutorPoolWebController {
}
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.add(HttpHeaders.CONTENT_TYPE, ExecutorMediaType.EXECUTOR_MEDIA_TYPE);
responseHeaders.add(HttpHeaders.CONTENT_TYPE, ExecutorJsonRepresentation.EXECUTOR_MEDIA_TYPE);
return new ResponseEntity<>(ExecutorMediaType.serialize(removedExecutor.get()), responseHeaders,
return new ResponseEntity<>(ExecutorJsonRepresentation.serialize(removedExecutor.get()), responseHeaders,
HttpStatus.OK);
}
}

View File

@ -2,8 +2,7 @@ package ch.unisg.executorpool.application.port.in;
import ch.unisg.common.SelfValidating;
import ch.unisg.executorpool.domain.ExecutorPool;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorIp;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorPort;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorUri;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorTaskType;
import lombok.Value;
import javax.validation.constraints.NotNull;
@ -11,17 +10,13 @@ import javax.validation.constraints.NotNull;
@Value
public class AddNewExecutorToExecutorPoolCommand extends SelfValidating<AddNewExecutorToExecutorPoolCommand> {
@NotNull
private final ExecutorIp executorIp;
@NotNull
private final ExecutorPort executorPort;
private final ExecutorUri executorUri;
@NotNull
private final ExecutorTaskType executorTaskType;
public AddNewExecutorToExecutorPoolCommand(ExecutorIp executorIp, ExecutorPort executorPort, ExecutorTaskType executorTaskType){
this.executorIp = executorIp;
this.executorPort = executorPort;
public AddNewExecutorToExecutorPoolCommand(ExecutorUri executorUri, ExecutorTaskType executorTaskType){
this.executorUri = executorUri;
this.executorTaskType = executorTaskType;
this.validateSelf();
}

View File

@ -1,9 +0,0 @@
package ch.unisg.executorpool.application.port.in;
import ch.unisg.executorpool.domain.ExecutorClass;
import java.util.List;
public interface GetAllExecutorInExecutorPoolByTypeUseCase {
List<ExecutorClass> getAllExecutorInExecutorPoolByType(GetAllExecutorInExecutorPoolByTypeQuery query);
}

View File

@ -7,11 +7,11 @@ import lombok.Value;
import javax.validation.constraints.NotNull;
@Value
public class GetAllExecutorInExecutorPoolByTypeQuery extends SelfValidating<GetAllExecutorInExecutorPoolByTypeQuery> {
public class GetAllExecutorsInExecutorPoolByTypeQuery extends SelfValidating<GetAllExecutorsInExecutorPoolByTypeQuery> {
@NotNull
private final ExecutorTaskType executorTaskType;
public GetAllExecutorInExecutorPoolByTypeQuery(ExecutorTaskType executorTaskType){
public GetAllExecutorsInExecutorPoolByTypeQuery(ExecutorTaskType executorTaskType){
this.executorTaskType = executorTaskType;
this.validateSelf();
}

View File

@ -0,0 +1,9 @@
package ch.unisg.executorpool.application.port.in;
import ch.unisg.executorpool.domain.ExecutorClass;
import java.util.List;
public interface GetAllExecutorsInExecutorPoolByTypeUseCase {
List<ExecutorClass> getAllExecutorsInExecutorPoolByType(GetAllExecutorsInExecutorPoolByTypeQuery query);
}

View File

@ -1,9 +1,7 @@
package ch.unisg.executorpool.application.port.in;
import ch.unisg.executorpool.domain.ExecutorClass;
import ch.unisg.common.SelfValidating;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorIp;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorPort;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorUri;
import lombok.Value;
import javax.validation.constraints.NotNull;
@ -11,14 +9,10 @@ import javax.validation.constraints.NotNull;
@Value
public class RemoveExecutorFromExecutorPoolCommand extends SelfValidating<RemoveExecutorFromExecutorPoolCommand> {
@NotNull
private final ExecutorIp executorIp;
private final ExecutorUri executorUri;
@NotNull
private final ExecutorPort executorPort;
public RemoveExecutorFromExecutorPoolCommand(ExecutorIp executorIp, ExecutorPort executorPort){
this.executorIp = executorIp;
this.executorPort = executorPort;
public RemoveExecutorFromExecutorPoolCommand(ExecutorUri executorUri){
this.executorUri = executorUri;
this.validateSelf();
}
}

View File

@ -20,6 +20,6 @@ public class AddNewExecutorToExecutorPoolService implements AddNewExecutorToExec
public ExecutorClass addNewExecutorToExecutorPool(AddNewExecutorToExecutorPoolCommand command){
ExecutorPool executorPool = ExecutorPool.getExecutorPool();
return executorPool.addNewExecutor(command.getExecutorIp(), command.getExecutorPort(), command.getExecutorTaskType());
return executorPool.addNewExecutor(command.getExecutorUri(), command.getExecutorTaskType());
}
}

View File

@ -1,7 +1,7 @@
package ch.unisg.executorpool.application.service;
import ch.unisg.executorpool.application.port.in.GetAllExecutorInExecutorPoolByTypeQuery;
import ch.unisg.executorpool.application.port.in.GetAllExecutorInExecutorPoolByTypeUseCase;
import ch.unisg.executorpool.application.port.in.GetAllExecutorsInExecutorPoolByTypeQuery;
import ch.unisg.executorpool.application.port.in.GetAllExecutorsInExecutorPoolByTypeUseCase;
import ch.unisg.executorpool.domain.ExecutorClass;
import ch.unisg.executorpool.domain.ExecutorPool;
import lombok.RequiredArgsConstructor;
@ -13,10 +13,10 @@ import java.util.List;
@RequiredArgsConstructor
@Component
@Transactional
public class GetAllExecutorInExecutorPoolByTypeService implements GetAllExecutorInExecutorPoolByTypeUseCase {
public class GetAllExecutorsInExecutorPoolByTypeService implements GetAllExecutorsInExecutorPoolByTypeUseCase {
@Override
public List<ExecutorClass> getAllExecutorInExecutorPoolByType(GetAllExecutorInExecutorPoolByTypeQuery query){
public List<ExecutorClass> getAllExecutorsInExecutorPoolByType(GetAllExecutorsInExecutorPoolByTypeQuery query){
ExecutorPool executorPool = ExecutorPool.getExecutorPool();
return executorPool.getAllExecutorsByType(query.getExecutorTaskType());
}

View File

@ -17,6 +17,6 @@ public class RemoveExecutorFromExecutorPoolService implements RemoveExecutorFrom
@Override
public Optional<ExecutorClass> removeExecutorFromExecutorPool(RemoveExecutorFromExecutorPoolCommand command){
ExecutorPool executorPool = ExecutorPool.getExecutorPool();
return executorPool.removeExecutorByIpAndPort(command.getExecutorIp(), command.getExecutorPort());
return executorPool.removeExecutorByIpAndPort(command.getExecutorUri());
}
}

View File

@ -3,36 +3,29 @@ package ch.unisg.executorpool.domain;
import lombok.Getter;
import lombok.Value;
import java.net.URI;
public class ExecutorClass {
@Getter
private final ExecutorIp executorIp;
@Getter
private final ExecutorPort executorPort;
private final ExecutorUri executorUri;
@Getter
private final ExecutorTaskType executorTaskType;
public ExecutorClass(ExecutorIp executorIp, ExecutorPort executorPort, ExecutorTaskType executorTaskType){
this.executorIp = executorIp;
this.executorPort = executorPort;
public ExecutorClass(ExecutorUri executorUri, ExecutorTaskType executorTaskType){
this.executorUri = executorUri;
this.executorTaskType = executorTaskType;
}
protected static ExecutorClass createExecutorClass(ExecutorIp executorIp, ExecutorPort executorPort, ExecutorTaskType executorTaskType){
System.out.println("New Task: " + executorIp.getValue() + " " + executorPort.getValue() + " " + executorTaskType.getValue());
return new ExecutorClass(executorIp, executorPort, executorTaskType);
protected static ExecutorClass createExecutorClass(ExecutorUri executorUri, ExecutorTaskType executorTaskType){
System.out.println("New Executor: " + executorUri.value.toString() + " " + executorTaskType.getValue());
return new ExecutorClass(executorUri, executorTaskType);
}
@Value
public static class ExecutorIp {
private String value;
}
@Value
public static class ExecutorPort {
private String value;
public static class ExecutorUri {
private URI value;
}
@Value

View File

@ -1,5 +1,8 @@
package ch.unisg.executorpool.domain;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorUri;
import ch.unisg.executorpool.domain.ExecutorClass.ExecutorTaskType;
import lombok.Getter;
import lombok.Value;
@ -20,19 +23,17 @@ public class ExecutorPool {
public static ExecutorPool getExecutorPool() { return executorPool; }
public ExecutorClass addNewExecutor(ExecutorClass.ExecutorIp executorIp, ExecutorClass.ExecutorPort executorPort, ExecutorClass.ExecutorTaskType executorTaskType){
ExecutorClass newExecutor = ExecutorClass.createExecutorClass(executorIp, executorPort, executorTaskType);
public ExecutorClass addNewExecutor(ExecutorUri executorUri, ExecutorTaskType executorTaskType){
ExecutorClass newExecutor = ExecutorClass.createExecutorClass(executorUri, executorTaskType);
listOfExecutors.value.add(newExecutor);
System.out.println("Number of executors: " + listOfExecutors.value.size());
return newExecutor;
}
public Optional<ExecutorClass> getExecutorByIpAndPort(ExecutorClass.ExecutorIp executorIp, ExecutorClass.ExecutorPort executorPort){
public Optional<ExecutorClass> getExecutorByUri(ExecutorUri executorUri){
for (ExecutorClass executor : listOfExecutors.value ) {
// TODO can this be simplified by overwriting equals()?
if(executor.getExecutorIp().getValue().equalsIgnoreCase(executorIp.getValue()) &&
executor.getExecutorPort().getValue().equalsIgnoreCase(executorPort.getValue())){
if(executor.getExecutorUri().getValue().equals(executorUri)){
return Optional.of(executor);
}
}
@ -54,11 +55,10 @@ public class ExecutorPool {
return matchedExecutors;
}
public Optional<ExecutorClass> removeExecutorByIpAndPort(ExecutorClass.ExecutorIp executorIp, ExecutorClass.ExecutorPort executorPort){
public Optional<ExecutorClass> removeExecutorByIpAndPort(ExecutorUri executorUri){
for (ExecutorClass executor : listOfExecutors.value ) {
// TODO can this be simplified by overwriting equals()?
if(executor.getExecutorIp().getValue().equalsIgnoreCase(executorIp.getValue()) &&
executor.getExecutorPort().getValue().equalsIgnoreCase(executorPort.getValue())){
if(executor.getExecutorUri().getValue().equals(executorUri.getValue())){
listOfExecutors.value.remove(executor);
return Optional.of(executor);
}

View File

@ -5,6 +5,7 @@ import ch.unisg.tapastasks.tasks.application.port.in.DeleteTaskCommand;
import ch.unisg.tapastasks.tasks.application.port.in.DeleteTaskUseCase;
import ch.unisg.tapastasks.tasks.domain.Task;
import ch.unisg.tapastasks.tasks.domain.TaskList;
import jdk.jshell.spi.ExecutionControl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
@ -23,11 +24,10 @@ public class DeleteTaskService implements DeleteTaskUseCase {
Optional<Task> updatedTask = taskList.retrieveTaskById(command.getTaskId());
Task newTask = updatedTask.get();
// TODO: Fill in the right condition into the if-statement and the else-statement
if (/*the task can be deleted*/){
if (true){
return taskList.deleteTaskById(command.getTaskId());
} else {
/*send message back to TaskList that the task cannot be deleted*/
}
// TODO Handle with a return message
return Optional.empty();
}
}