feature: bind criteria to fetch request
This commit is contained in:
parent
eaf5412149
commit
30b3a8832d
@ -39,4 +39,7 @@ public record Criteria(String rawCriteria) {
|
|||||||
.getOrElse(false);
|
.getOrElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isEmpty(Criteria criteria) {
|
||||||
|
return criteria.rawCriteria.isEmpty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import tk.antoine.roux.domain.usecases.Command.EmptyCommand;
|
|||||||
import tk.antoine.roux.domain.usecases.operation.GetNodesUseCase;
|
import tk.antoine.roux.domain.usecases.operation.GetNodesUseCase;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("${backoffice.configuration.api-prefix}/v1")
|
@RequestMapping("${backoffice.configuration.api-prefix}/v1")
|
||||||
@ -31,6 +32,7 @@ public class NodeController {
|
|||||||
@GetMapping("/nodes")
|
@GetMapping("/nodes")
|
||||||
ResponseEntity<?> listNode(@RequestParam(required = false, value = "criteria") Optional<Criteria> optionalCriteria) {
|
ResponseEntity<?> listNode(@RequestParam(required = false, value = "criteria") Optional<Criteria> optionalCriteria) {
|
||||||
return Option.ofOptional(optionalCriteria)
|
return Option.ofOptional(optionalCriteria)
|
||||||
|
.filter(Predicate.not(Criteria::isEmpty))
|
||||||
.map(criteria -> criteria.toCommand().map(Command.class::cast))
|
.map(criteria -> criteria.toCommand().map(Command.class::cast))
|
||||||
.toEither(EMPTY_COMMAND)
|
.toEither(EMPTY_COMMAND)
|
||||||
.getOrElseGet(Either::right)
|
.getOrElseGet(Either::right)
|
||||||
|
@ -4,13 +4,12 @@ function Nodes({criteria}) {
|
|||||||
const [nodes, setNodes] = React.useState([]);
|
const [nodes, setNodes] = React.useState([]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
fetch("/api/v1/nodes")
|
let query = new URL("/api/v1/nodes", window.location.origin);
|
||||||
|
query.searchParams.append("criteria", criteria)
|
||||||
|
|
||||||
|
fetch(query)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(value => setNodes(value));
|
.then(value => setNodes(value));
|
||||||
}, []);
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
console.log(criteria);
|
|
||||||
}, [criteria]);
|
}, [criteria]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user