Changing the query execution to execute by name. Will make the API a lot simpler.

This commit is contained in:
Arpit Mohan 2019-04-02 21:55:19 +05:30
parent bbb6e511d7
commit 2a5656afbb
5 changed files with 15 additions and 9 deletions

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}
}