mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2026-03-10 18:55:03 +00:00
List renaming
Added list reanming through a ListPUT lambda. Potentially could be used to alter other List aspects in the future. Also renamed itemID to listID for semantic unity
This commit is contained in:
@@ -3,7 +3,7 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class List {
|
||||
Integer itemID;
|
||||
Integer listID;
|
||||
String name;
|
||||
String owner;
|
||||
long lastUpdated;
|
||||
@@ -11,7 +11,7 @@ public class List {
|
||||
boolean shared;
|
||||
|
||||
public List(ResultSet listRow, boolean shared) throws SQLException {
|
||||
itemID = listRow.getInt("listID");
|
||||
listID = listRow.getInt("listID");
|
||||
name = listRow.getString("name");
|
||||
owner = listRow.getString("owner");
|
||||
lastUpdated = listRow.getTimestamp("lastUpdated").toInstant().toEpochMilli();
|
||||
@@ -26,7 +26,7 @@ public class List {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "List{" +
|
||||
"itemID=" + itemID +
|
||||
"listID=" + listID +
|
||||
", name='" + name + '\'' +
|
||||
", owner='" + owner + '\'' +
|
||||
", lastUpdated=" + lastUpdated +
|
||||
@@ -38,12 +38,12 @@ public class List {
|
||||
return entries.toArray(new ItemEntry[entries.size()]);
|
||||
}
|
||||
|
||||
public Integer getItemID() {
|
||||
return itemID;
|
||||
public Integer getListID() {
|
||||
return listID;
|
||||
}
|
||||
|
||||
public void setItemID(Integer itemID) {
|
||||
this.itemID = itemID;
|
||||
public void setListID(Integer listID) {
|
||||
this.listID = listID;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
11
Lambdas/Lists/List/src/ListPUT.java
Normal file
11
Lambdas/Lists/List/src/ListPUT.java
Normal file
@@ -0,0 +1,11 @@
|
||||
import com.amazonaws.services.lambda.runtime.Context;
|
||||
import com.amazonaws.services.lambda.runtime.RequestHandler;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ListPUT implements RequestHandler<Map<String,Object>, Object> {
|
||||
|
||||
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
|
||||
return BasicHandler.handleRequest(inputMap, unfilled, ListPutter.class);
|
||||
}
|
||||
}
|
||||
44
Lambdas/Lists/List/src/ListPutter.java
Normal file
44
Lambdas/Lists/List/src/ListPutter.java
Normal file
@@ -0,0 +1,44 @@
|
||||
import java.security.AccessControlException;
|
||||
import java.sql.*;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ListPutter implements CallHandler {
|
||||
private final Connection connection;
|
||||
private final String cognitoID;
|
||||
|
||||
private final String ACCESS_CHECK = "SELECT * from ListSharee WHERE userID = ? and listID = ?;";
|
||||
private final String LIST_RENAME = "UPDATE List SET name = ?, lastUpdated = ? WHERE listID = ?;";
|
||||
|
||||
public ListPutter(Connection connection, String cognitoID) {
|
||||
this.connection = connection;
|
||||
this.cognitoID = cognitoID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryMap, String cognitoID) throws SQLException {
|
||||
Integer listID = Integer.parseInt(bodyMap.get("listID").toString());
|
||||
|
||||
PreparedStatement accessCheck = connection.prepareStatement(ACCESS_CHECK);
|
||||
accessCheck.setString(1, cognitoID);
|
||||
accessCheck.setInt(2, listID);
|
||||
System.out.println(accessCheck);
|
||||
ResultSet userLists = accessCheck.executeQuery();
|
||||
if (!userLists.next()) {
|
||||
throw new AccessControlException("User does not have access to list");
|
||||
} else {
|
||||
if (!ListPermissions.hasPermission(userLists.getInt("permissionLevel"), "Delete")) {
|
||||
throw new AccessControlException("User " + cognitoID + " does not have permission to edit list " + listID);
|
||||
}
|
||||
}
|
||||
PreparedStatement renameList = connection.prepareStatement(LIST_RENAME);
|
||||
renameList.setString(1, bodyMap.get("name").toString());
|
||||
renameList.setTimestamp(2, Timestamp.from(Instant.now()));
|
||||
renameList.setInt(3, listID);
|
||||
System.out.println(renameList);
|
||||
renameList.executeUpdate();
|
||||
connection.commit();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user