32 lines
1.1 KiB
Java
32 lines
1.1 KiB
Java
package tk.antoine.roux.domain.usecases.operation;
|
|
|
|
import io.vavr.collection.List;
|
|
import org.springframework.stereotype.Service;
|
|
import tk.antoine.roux.domain.model.Node;
|
|
import tk.antoine.roux.domain.usecases.ByLabelCriteria;
|
|
import tk.antoine.roux.domain.usecases.ByNameCriteria;
|
|
import tk.antoine.roux.domain.usecases.ByRegexCriteria;
|
|
import tk.antoine.roux.domain.usecases.Command;
|
|
import tk.antoine.roux.infrastructure.out.NodeLister;
|
|
|
|
@Service
|
|
public final class GetNodesUseCase implements UseCase<List<Node>, Command> {
|
|
|
|
private final NodeLister nodeLister;
|
|
|
|
public GetNodesUseCase(NodeLister nodeLister) {
|
|
this.nodeLister = nodeLister;
|
|
}
|
|
|
|
@Override
|
|
public List<Node> invoke(Command command) {
|
|
return switch (command) {
|
|
case Command.EmptyCommand emptyCommand -> nodeLister.listAll();
|
|
case ByNameCriteria nameCriteria -> nodeLister.listAllByName(nameCriteria.value());
|
|
case ByRegexCriteria regexCriteria -> nodeLister.listAllByRegex(regexCriteria.regex());
|
|
case ByLabelCriteria byLabelCriteria -> nodeLister.listAll();
|
|
};
|
|
}
|
|
|
|
}
|