Changing the query execution to execute by name. Will make the API a lot simpler.
This commit is contained in:
parent
bbb6e511d7
commit
2a5656afbb
|
|
@ -17,8 +17,8 @@ public class QueryController extends BaseController<QueryService, Query, String>
|
|||
super(service);
|
||||
}
|
||||
|
||||
@PostMapping("/execute/{id}")
|
||||
public Flux<Object> executeQuery(@PathVariable String id, @RequestBody CommandQueryParams params) {
|
||||
return service.executeQuery(id, params);
|
||||
@PostMapping("/execute/{name}")
|
||||
public Flux<Object> executeQuery(@PathVariable String name, @RequestBody CommandQueryParams params) {
|
||||
return service.executeQuery(name, params);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import lombok.Getter;
|
|||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.mongodb.core.index.Indexed;
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
|
|
@ -25,7 +26,10 @@ public class Query extends BaseDomain {
|
|||
|
||||
String confirmationMsg;
|
||||
|
||||
@Indexed(unique = true)
|
||||
String name;
|
||||
|
||||
List<Property> properties;
|
||||
|
||||
List<Property> headers;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ package com.mobtools.server.repositories;
|
|||
|
||||
import com.mobtools.server.domains.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Repository
|
||||
public interface QueryRepository extends BaseRepository<Query, String> {
|
||||
|
||||
Mono<Query> findByName(String name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ import reactor.core.publisher.Flux;
|
|||
|
||||
public interface QueryService extends CrudService<Query, String> {
|
||||
|
||||
Flux<Object> executeQuery(String id, CommandQueryParams params);
|
||||
Flux<Object> executeQuery(String name, CommandQueryParams params);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,12 +31,12 @@ public class QueryServiceImpl extends BaseService<QueryRepository, Query, String
|
|||
|
||||
|
||||
@Override
|
||||
public Flux<Object> executeQuery(String id, CommandQueryParams params) {
|
||||
log.debug("Going to execute query with id: {}", id);
|
||||
public Flux<Object> executeQuery(String name, CommandQueryParams params) {
|
||||
log.debug("Going to execute query with name: {}", name);
|
||||
|
||||
// 1. Fetch the query from the DB to get the type
|
||||
Mono<Query> queryMono = repository.findById(id)
|
||||
.switchIfEmpty(Mono.defer(() -> Mono.error(new MobtoolsException("Unable to find query by id: " + id))));
|
||||
Mono<Query> queryMono = repository.findByName(name)
|
||||
.switchIfEmpty(Mono.defer(() -> Mono.error(new MobtoolsException("Unable to find query by id: " + name))));
|
||||
|
||||
// 2. Instantiate the implementation class based on the query type
|
||||
Mono<PluginExecutor> pluginExecutorMono = queryMono.map(queryObj ->
|
||||
|
|
@ -50,5 +50,4 @@ public class QueryServiceImpl extends BaseService<QueryRepository, Query, String
|
|||
})
|
||||
.flatMapIterable(Flux::toIterable).subscribeOn(scheduler);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user