diff --git a/.gitignore b/.gitignore
index 2fc6ec6..33561d7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -85,3 +85,5 @@ lint/outputs/
lint/tmp/
# lint/reports/
Lambdas/Lists/src/main/resources/dbProperties.json
+Lambdas/Lists/target/classes/dbProperties.json
+Lambdas/Lists/target/classes/META-INF/Lists.kotlin_module
diff --git a/Lambdas/Lists/pom.xml b/Lambdas/Lists/pom.xml
index 9442b49..8d77579 100644
--- a/Lambdas/Lists/pom.xml
+++ b/Lambdas/Lists/pom.xml
@@ -34,6 +34,11 @@
maven-compiler-plugin
3.8.1
+
+ org.mariadb.jdbc
+ mariadb-java-client
+ 2.7.0
+
1.11
diff --git a/Lambdas/Lists/src/main/java/DBConnector.java b/Lambdas/Lists/src/main/java/DBConnector.java
index c4f85b9..074f4de 100644
--- a/Lambdas/Lists/src/main/java/DBConnector.java
+++ b/Lambdas/Lists/src/main/java/DBConnector.java
@@ -12,14 +12,28 @@ public class DBConnector {
Connection connection;
- DBConnector() throws IOException, SQLException {
+ DBConnector() throws IOException, SQLException, ClassNotFoundException {
this(loadProperties("dbProperties.json"));
}
- DBConnector(Properties dbProperties) throws SQLException {
+ DBConnector(Properties dbProperties) throws SQLException, ClassNotFoundException {
+ Class.forName("org.mariadb.jdbc.Driver");
System.out.println(dbProperties);
- connection = DriverManager.getConnection(dbProperties.get("url").toString(), dbProperties);
+ System.out.println(DBConnector.buildURL(dbProperties));
+ connection = DriverManager.getConnection(dbProperties.get("url").toString(), dbProperties.get("user").toString(), dbProperties.get("password").toString());
+ System.out.println(connection);
+ }
+ public void close() {
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public Connection getConnection() {
+ return connection;
}
public static Properties loadProperties(String path) throws IOException {
@@ -29,4 +43,11 @@ public class DBConnector {
propertiesJSON.keys().forEachRemaining(key -> toReturn.setProperty(key, propertiesJSON.get(key).toString()));
return toReturn;
}
+
+ public static String buildURL(Properties dbProperties) {
+ String dbURL = dbProperties.get("url").toString();
+ dbURL += "?user=" + dbProperties.get("user").toString();
+ dbURL += "&password=" + dbProperties.get("password").toString();
+ return dbURL;
+ }
}
diff --git a/Lambdas/Lists/src/main/java/InputUtils.java b/Lambdas/Lists/src/main/java/InputUtils.java
index 0457585..46a0694 100644
--- a/Lambdas/Lists/src/main/java/InputUtils.java
+++ b/Lambdas/Lists/src/main/java/InputUtils.java
@@ -8,9 +8,21 @@ public class InputUtils {
if ((inputMap.get("context") != null) && (inputMap.get("context") instanceof Map, ?>)) {
contextMap = ((Map) inputMap.get("context"));
} else {
- throw new IllegalArgumentException("The key \"Context\" must exist and be a map");
+ throw new IllegalArgumentException("The key \"context\" must exist and be a map");
}
System.out.println(inputMap.get("context"));
System.out.println(contextMap.get("sub"));
+ return contextMap.get("sub").toString();
+ }
+
+ public static Map getBody(Map inputMap) {
+ return getMap(inputMap, "body");
+ }
+
+ public static Map getMap(Map parentMap, String childKey) {
+ if ((parentMap.get(childKey) != null) && (parentMap.get(childKey) instanceof Map, ?>)) {
+ return ((Map) parentMap.get(childKey));
+ }
+ throw new IllegalArgumentException("The key \"" + childKey + "\" must exist and be a map");
}
}
diff --git a/Lambdas/Lists/src/main/java/ListAdder.java b/Lambdas/Lists/src/main/java/ListAdder.java
index 413b7db..54745c5 100644
--- a/Lambdas/Lists/src/main/java/ListAdder.java
+++ b/Lambdas/Lists/src/main/java/ListAdder.java
@@ -1,4 +1,27 @@
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.Map;
+
public class ListAdder {
+ private DBConnector connector;
+ private String cognitoID;
+ private final String LIST_CREATE = "INSERT INTO Lists (Name, Owner) VALUES (?, ?)";
+
+ ListAdder(DBConnector connector, String cognitoID) {
+ this.connector = connector;
+ this.cognitoID = cognitoID;
+ }
+
+ public void add(Map bodyMap) throws SQLException {
+ Connection connection = connector.getConnection();
+ PreparedStatement statement = connection.prepareStatement(LIST_CREATE);
+ statement.setString(1, bodyMap.get("Name").toString());
+ statement.setString(2, cognitoID);
+ System.out.println(statement);
+ statement.executeUpdate();
+ connection.commit();
+ }
}
diff --git a/Lambdas/Lists/src/main/java/ListsPOST.java b/Lambdas/Lists/src/main/java/ListsPOST.java
index a4588a0..4068a4f 100644
--- a/Lambdas/Lists/src/main/java/ListsPOST.java
+++ b/Lambdas/Lists/src/main/java/ListsPOST.java
@@ -11,11 +11,17 @@ public class ListsPOST implements RequestHandler