mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 02:38:47 +00:00
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.
37 lines
1.2 KiB
Java
37 lines
1.2 KiB
Java
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 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();
|
|
}
|
|
}
|
|
}
|