mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2026-03-10 18:55:03 +00:00
GET strcuture
Build out infrastructure for get requests (along with the first couple). This includes changing the request engine from Volley to OKHTTP due to issues get Volley's callbacks to call back.
This commit is contained in:
@@ -4,17 +4,19 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class BasicHandler {
|
||||
public static <T extends CallHandler> String handleRequest(Map<String, Object> inputMap, Context unfilled, Class<T> toCall) {
|
||||
public static <T extends CallHandler> Object handleRequest(Map<String, Object> inputMap, Context unfilled, Class<T> toCall) {
|
||||
String cognitoID = InputUtils.getCognitoIDFromBody(inputMap);
|
||||
HashMap<String, String> queryMap = InputUtils.getQueryParams(inputMap);
|
||||
try {
|
||||
DBConnector connector = new DBConnector();
|
||||
try {
|
||||
Constructor<T> constructor = toCall.getConstructor(DBConnector.class, String.class);
|
||||
CallHandler callHandler = constructor.newInstance(connector, cognitoID);
|
||||
callHandler.conductAction(InputUtils.getBody(inputMap), "");
|
||||
return callHandler.conductAction(InputUtils.getBody(inputMap), queryMap, cognitoID);
|
||||
} catch (SQLException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public interface CallHandler {
|
||||
String conductAction(Map<String, Object> bodyMap, String cognitoID) throws SQLException;
|
||||
Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.utils.URLEncodedUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class InputUtils {
|
||||
@@ -19,10 +25,24 @@ public class InputUtils {
|
||||
return getMap(inputMap, "body");
|
||||
}
|
||||
|
||||
public static String getQueryString(Map<String, Object> inputMap) {
|
||||
private static String getQueryString(Map<String, Object> inputMap) {
|
||||
return (String) (getMap(inputMap, "params").get("querystring"));
|
||||
}
|
||||
|
||||
public static HashMap<String, String> getQueryParams(Map<String, Object> inputMap) {
|
||||
return (HashMap<String, String>) (getMap(inputMap, "params").get("querystring"));
|
||||
|
||||
// String queryString = getQueryString(inputMap);
|
||||
// List<NameValuePair> queryparams = URLEncodedUtils.parse(queryString, StandardCharsets.UTF_8);
|
||||
// HashMap<String, String> mappedParams = new HashMap<>();
|
||||
// for (NameValuePair param : queryparams) {
|
||||
// mappedParams.put(param.getName(), param.getValue());
|
||||
// }
|
||||
// return mappedParams;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Map<String, Object> getMap(Map<String, Object> parentMap, String childKey) {
|
||||
if ((parentMap.get(childKey) != null) && (parentMap.get(childKey) instanceof Map<?, ?>)) {
|
||||
return ((Map<String, Object>) parentMap.get(childKey));
|
||||
|
||||
Reference in New Issue
Block a user