[#207] fix(api): clean up

This commit is contained in:
Ilnur Farukhshin 2021-07-15 15:18:33 +03:00
parent 3d5bbc854a
commit bd9f8280e8
5 changed files with 6 additions and 7 deletions

View file

@ -15,7 +15,6 @@ import reactor.core.publisher.Mono;
@Log4j2
public final class KsqlClient {
private final WebClient webClient;
private ObjectMapper objectMapper;
public Mono<Object> execute(KsqlStatementStrategy ksqlStatement) {
return webClient.post()

View file

@ -21,6 +21,6 @@ public class KsqlController implements KsqlApi {
public Mono<ResponseEntity<Object>> executeKsqlCommand(String clusterName,
Mono<KsqlCommand> ksqlCommand,
ServerWebExchange exchange) {
return Mono.just(ResponseEntity.ok(ksqlService.getListStreams(clusterName, ksqlCommand)));
return Mono.just(ResponseEntity.ok(ksqlService.executeKsqlCommand(clusterName, ksqlCommand)));
}
}

View file

@ -20,8 +20,8 @@ public class KsqlService {
private final ClustersStorage clustersStorage;
private final List<KsqlStatementStrategy> commandParamsStrategies;
public Mono<Object> getListStreams(String name, Mono<KsqlCommand> ksqlCommand) {
return Mono.justOrEmpty(clustersStorage.getClusterByName(name))
public Mono<Object> executeKsqlCommand(String clusterName, Mono<KsqlCommand> ksqlCommand) {
return Mono.justOrEmpty(clustersStorage.getClusterByName(clusterName))
.switchIfEmpty(Mono.error(ClusterNotFoundException::new))
.map(KafkaCluster::getKsqldbServer)
.switchIfEmpty(Mono.error(KsqlDbNotFoundException::new))
@ -38,7 +38,7 @@ public class KsqlService {
.map(s -> s.ksqlCommand(command))
.findFirst())
.flatMap(Mono::justOrEmpty)
// TODO: how to handle not parsed statements?
// TODO: handle not parsed statements?
.switchIfEmpty(Mono.error(new UnprocessableEntityException("Invalid sql")));
}
}

View file

@ -19,7 +19,7 @@ public class ListStreamsStrategy extends KsqlStatementStrategy {
@Override
public boolean test(String sql) {
return sql.trim().toLowerCase().matches("list streams;");
return sql.trim().toLowerCase().matches("(list|show) streams;");
}
@Override

View file

@ -16,7 +16,7 @@ public class ListTopicsStrategy extends KsqlStatementStrategy {
@Override
public boolean test(String sql) {
return sql.trim().toLowerCase().matches("list topics;");
return sql.trim().toLowerCase().matches("(list|show) topics;");
}
@Override