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:
NMerz
2020-10-03 17:37:46 -04:00
parent 69572b3a1f
commit f107ab023d
21 changed files with 398 additions and 52 deletions

View File

@@ -1,9 +1,36 @@
import com.google.gson.Gson;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
public class ItemGetter implements CallHandler{
private final DBConnector connector;
private final String GET_ITEM = "SELECT * FROM Product WHERE productID = ?;";
public ItemGetter(DBConnector connector, String cognitoID) {
this.connector = connector;
}
@Override
public String conductAction(Map<String, Object> bodyMap, String cognitoID) throws SQLException {
return null;
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryMap, String cognitoID) throws SQLException {
Connection connection = connector.getConnection();
try {
PreparedStatement statement = connection.prepareStatement(GET_ITEM);
statement.setInt(1, Integer.parseInt(queryMap.get("id")));
System.out.println(statement);
ResultSet queryResults = statement.executeQuery();
queryResults.first();
System.out.println(queryResults);
Item retrievedItem = new Item(queryResults);
System.out.println(retrievedItem);
return retrievedItem;
} finally {
connection.close();
}
}
}