Rest API and Rapid api plugin url encode the query parameters. The Providers returned are sorted by sortOrder in ascending order

This commit is contained in:
Trisha Anand 2020-03-18 20:35:50 +05:30
parent 4961f6ef23
commit 44d5dccbbb
3 changed files with 11 additions and 3 deletions

View File

@ -28,6 +28,8 @@ import reactor.core.publisher.Mono;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -271,7 +273,8 @@ public class RapidApiPlugin extends BasePlugin {
// If either the key or the value is empty, skip // If either the key or the value is empty, skip
if (queryParam.getKey() != null && !queryParam.getKey().isEmpty() && if (queryParam.getKey() != null && !queryParam.getKey().isEmpty() &&
queryParam.getValue() != null && !queryParam.getValue().isEmpty()) { queryParam.getValue() != null && !queryParam.getValue().isEmpty()) {
uriBuilder.queryParam(queryParam.getKey(), queryParam.getValue()); uriBuilder.queryParam(queryParam.getKey(), URLEncoder.encode(queryParam.getValue(),
StandardCharsets.UTF_8));
} }
} }
} }

View File

@ -28,6 +28,8 @@ import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
public class RestApiPlugin extends BasePlugin { public class RestApiPlugin extends BasePlugin {
@ -219,7 +221,8 @@ public class RestApiPlugin extends BasePlugin {
if (queryParams != null) { if (queryParams != null) {
for (Property queryParam : queryParams) { for (Property queryParam : queryParams) {
if (queryParam.getKey() != null && !queryParam.getKey().isEmpty()) { if (queryParam.getKey() != null && !queryParam.getKey().isEmpty()) {
uriBuilder.queryParam(queryParam.getKey(), queryParam.getValue()); uriBuilder.queryParam(queryParam.getKey(), URLEncoder.encode(queryParam.getValue(),
StandardCharsets.UTF_8));
} }
} }
} }

View File

@ -42,7 +42,7 @@ public class ProviderServiceImpl extends BaseService<ProviderRepository, Provide
@Override @Override
public Flux<Provider> get(MultiValueMap<String, String> params) { public Flux<Provider> get(MultiValueMap<String, String> params) {
Provider providerExample = new Provider(); Provider providerExample = new Provider();
Sort sort = Sort.by(FieldName.NAME); Sort sort = Sort.by("sortOrder");
if (params.getFirst(FieldName.NAME) != null) { if (params.getFirst(FieldName.NAME) != null) {
providerExample.setName(params.getFirst(FieldName.NAME)); providerExample.setName(params.getFirst(FieldName.NAME));
@ -58,6 +58,8 @@ public class ProviderServiceImpl extends BaseService<ProviderRepository, Provide
} }
providerExample.setCategories(categories); providerExample.setCategories(categories);
providerExample.setSortOrder(null);
return repository.findAll(Example.of(providerExample), sort); return repository.findAll(Example.of(providerExample), sort);
} }