mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 02:38:47 +00:00
ListDELETE lambda
List deletion now working Integration tested independently. Still needs tests and user deletion should now use this.
This commit is contained in:
parent
c6b5e28755
commit
8233a989ef
12
Lambdas/Lists/List/src/ListDELETE.java
Normal file
12
Lambdas/Lists/List/src/ListDELETE.java
Normal file
@ -0,0 +1,12 @@
|
||||
import com.amazonaws.services.lambda.runtime.Context;
|
||||
import com.amazonaws.services.lambda.runtime.RequestHandler;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ListDELETE implements RequestHandler<Map<String,Object>, Object> {
|
||||
|
||||
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
|
||||
return BasicHandler.handleRequest(inputMap, unfilled, ListDeleter.class);
|
||||
}
|
||||
|
||||
}
|
||||
50
Lambdas/Lists/List/src/ListDeleter.java
Normal file
50
Lambdas/Lists/List/src/ListDeleter.java
Normal file
@ -0,0 +1,50 @@
|
||||
import java.security.AccessControlException;
|
||||
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 ListDeleter implements CallHandler {
|
||||
private final Connection connection;
|
||||
private final String cognitoID;
|
||||
|
||||
private final String GET_LISTS = "SELECT * FROM List WHERE (owner = ? AND listID = ?);";
|
||||
private final String DELETE_LIST = "DELETE FROM List WHERE listID = ?;";
|
||||
private final String DELETE_LIST_ACCESS = "DELETE FROM ListSharee where listID = ?;";
|
||||
private final String DELETE_LIST_ENTRIES = "DELETE FROM ListProduct where listID = ?;";
|
||||
|
||||
public ListDeleter(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(queryMap.get("id"));
|
||||
PreparedStatement accessCheck = connection.prepareStatement(GET_LISTS);
|
||||
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");
|
||||
}
|
||||
PreparedStatement cleanAccess = connection.prepareStatement(DELETE_LIST_ACCESS);
|
||||
cleanAccess.setInt(1, listID);
|
||||
System.out.println(cleanAccess);
|
||||
cleanAccess.executeUpdate();
|
||||
PreparedStatement deleteEntries = connection.prepareStatement(DELETE_LIST_ENTRIES);
|
||||
deleteEntries.setInt(1, listID);
|
||||
System.out.println(deleteEntries);
|
||||
deleteEntries.executeUpdate();
|
||||
PreparedStatement cleanList = connection.prepareStatement(DELETE_LIST);
|
||||
cleanList.setInt(1, listID);
|
||||
System.out.println(cleanList);
|
||||
cleanList.executeUpdate();
|
||||
connection.commit();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user