Treat ListSharee as access table

This is so that multiple users can be paired with a single list.

In the future, we may want to reconsider list deletion behavior to simply remove a user's access and only delete it when no one has access.

We may also want the user deletion Lambda to use the list deletion Lambda when it is created.
This commit is contained in:
NMerz
2020-10-24 14:46:56 -04:00
parent 2637cab282
commit 34d74aae6a
6 changed files with 112 additions and 7 deletions

View File

@@ -8,7 +8,8 @@ public class ListAdder implements CallHandler {
private Connection connection;
private String cognitoID;
private final String LIST_CREATE = "INSERT INTO List (name, owner, lastUpdated) VALUES (?, ?, ?)";
private final String LIST_CREATE = "INSERT INTO List (name, owner, lastUpdated) VALUES (?, ?, ?);";
private final String LIST_ACCESS_GRANT = "INSERT INTO ListSharee(listID, userID) VALUES(?, ?);";
public ListAdder(Connection connection, String cognitoID) {
this.connection = connection;
@@ -17,7 +18,9 @@ public class ListAdder implements CallHandler {
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
PreparedStatement statement = connection.prepareStatement(LIST_CREATE, Statement.RETURN_GENERATED_KEYS);
statement.setString(1, bodyMap.get("name").toString());//Needs safe checking
String listName = bodyMap.get("name").toString();//Needs safe checking
statement.setString(1, listName);
statement.setString(2, cognitoID);
statement.setTimestamp(3, Timestamp.from(Instant.now()));
System.out.println(statement);
@@ -25,7 +28,13 @@ public class ListAdder implements CallHandler {
ResultSet newIDRS = statement.getGeneratedKeys();
newIDRS.first();
Integer newID = newIDRS.getInt(1);
PreparedStatement accessGrant = connection.prepareStatement(LIST_ACCESS_GRANT);
accessGrant.setInt(1, newID);
accessGrant.setString(2, cognitoID);
System.out.println(accessGrant);
accessGrant.executeUpdate();
connection.commit();
System.out.println(newID);
return newID;
}
}

View File

@@ -11,7 +11,7 @@ public class ListGetter implements CallHandler{
private final String cognitoID;
private final String GET_LIST = "SELECT * FROM List WHERE listID = ?;";
private final String GET_LISTS = "SELECT listID FROM List WHERE owner = ?;";
private final String GET_LISTS = "SELECT listID FROM ListSharee WHERE userID = ?;";
private final String GET_ENTRIES = "SELECT * FROM ListProduct WHERE listID = ?;";
public ListGetter(Connection connection, String cognitoID) {