mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2026-03-10 18:55:03 +00:00
Merge branch 'master' into intra-list-ordering
This commit is contained in:
@@ -2,6 +2,7 @@ import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -9,6 +10,7 @@ public class ChainGetter implements CallHandler {
|
||||
private final Connection connection;
|
||||
|
||||
private final String GET_CHAIN = "SELECT * FROM Chain WHERE chainID = ?;";
|
||||
private final String GET_CHAINS = "SELECT chainID FROM Chain;";
|
||||
|
||||
public ChainGetter(Connection connection, String cognitoID) {
|
||||
this.connection = connection;
|
||||
@@ -16,8 +18,21 @@ public class ChainGetter implements CallHandler {
|
||||
|
||||
@Override
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryMap, String cognitoID) throws SQLException {
|
||||
Integer id = Integer.parseInt(queryMap.get("id"));
|
||||
if (id == -1) {
|
||||
PreparedStatement getChains = connection.prepareStatement(GET_CHAINS);
|
||||
System.out.println(getChains);
|
||||
ResultSet getChainsResults = getChains.executeQuery();
|
||||
System.out.println(getChainsResults);
|
||||
ArrayList<Integer> chainIDs = new ArrayList<>();
|
||||
while (getChainsResults.next()) {
|
||||
chainIDs.add(getChainsResults.getInt("chainID"));
|
||||
}
|
||||
return chainIDs;
|
||||
}
|
||||
|
||||
PreparedStatement statement = connection.prepareStatement(GET_CHAIN);
|
||||
statement.setInt(1, Integer.parseInt(queryMap.get("id")));
|
||||
statement.setInt(1, id);
|
||||
System.out.println(statement);
|
||||
ResultSet queryResults = statement.executeQuery();
|
||||
queryResults.first();
|
||||
|
||||
@@ -21,10 +21,6 @@ public class List {
|
||||
this.uiPosition = uiPosition;
|
||||
}
|
||||
|
||||
public void addItemEntry(ItemEntry entry) {
|
||||
entries.add(entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "List{" +
|
||||
@@ -38,10 +34,6 @@ public class List {
|
||||
'}';
|
||||
}
|
||||
|
||||
public ItemEntry[] getEntries() {
|
||||
return entries.toArray(new ItemEntry[entries.size()]);
|
||||
}
|
||||
|
||||
public Integer getItemID() {
|
||||
return itemID;
|
||||
}
|
||||
@@ -88,5 +80,12 @@ public class List {
|
||||
|
||||
public void setUiPosition(Integer uiPosition) {
|
||||
this.uiPosition = uiPosition;
|
||||
|
||||
public ItemEntry[] getEntries() {
|
||||
return entries.toArray(new ItemEntry[entries.size()]);
|
||||
}
|
||||
|
||||
public void addItemEntry(ItemEntry entry) {
|
||||
entries.add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
37
Lambdas/Lists/ListShare/src/ListShare.java
Normal file
37
Lambdas/Lists/ListShare/src/ListShare.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package com.example.listify.data;
|
||||
|
||||
public class ListShare {
|
||||
Integer listID;
|
||||
String shareWithEmail;
|
||||
ArrayList<ListShare> other;
|
||||
|
||||
public ListShare(ResultSet listRow) throws SQLException {
|
||||
this.listID = listRow.getInt("listID");
|
||||
this.shareWithEmail = listRow.getString("userID");
|
||||
other = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Integer getListID() {
|
||||
return listID;
|
||||
}
|
||||
|
||||
public void setListID(Integer listID) {
|
||||
this.listID = listID;
|
||||
}
|
||||
|
||||
public String getShareWithEmail() {
|
||||
return shareWithEmail;
|
||||
}
|
||||
|
||||
public void setShareWithEmail(String shareWithEmail) {
|
||||
this.shareWithEmail = shareWithEmail;
|
||||
}
|
||||
|
||||
public ListShare[] getEntries() {
|
||||
return other.toArray(new ListShare[other.size()]);
|
||||
}
|
||||
|
||||
public void addtoList(ListShare entry) {
|
||||
other.add(entry);
|
||||
}
|
||||
}
|
||||
12
Lambdas/Lists/ListShare/src/ListShareDELETE.java
Normal file
12
Lambdas/Lists/ListShare/src/ListShareDELETE.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 ListShareDELETE implements RequestHandler<Map<String,Object>, Object> {
|
||||
|
||||
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
|
||||
return BasicHandler.handleRequest(inputMap, unfilled, ListShareDeleter.class);
|
||||
}
|
||||
|
||||
}
|
||||
65
Lambdas/Lists/ListShare/src/ListShareDeleter.java
Normal file
65
Lambdas/Lists/ListShare/src/ListShareDeleter.java
Normal file
@@ -0,0 +1,65 @@
|
||||
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 ListShareDeleter implements CallHandler {
|
||||
private final Connection connection;
|
||||
private final String cognitoID;
|
||||
|
||||
private final String GET_LIST_ACCESS = "SELECT * FROM List WHERE (owner = ? AND listID = ?);";
|
||||
private final String REMOVE_SHAREE = "DELETE FROM ListSharee WHERE listID = ? AND user = ?;";
|
||||
|
||||
public ListShareDeleter(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"));
|
||||
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
invokeRequest.setFunctionName("UserGET");
|
||||
invokeRequest.setPayload("{" +
|
||||
" \"body\": {" +
|
||||
" \"emailToCheck\": \"" + bodyMap.get("shareWithEmail").toString() + "\"" +
|
||||
" }," +
|
||||
" \"params\": {" +
|
||||
" \"querystring\": {" +
|
||||
" }" +
|
||||
" }," +
|
||||
" \"context\": {" +
|
||||
" \"sub\": \"not used\"" +
|
||||
" }" +
|
||||
"}");
|
||||
InvokeResult invokeResult = AWSLambdaClientBuilder.defaultClient().invoke(invokeRequest);
|
||||
|
||||
String shareeID = new String(invokeResult.getPayload().array()).replace("\"", "");
|
||||
|
||||
//Ensure that the user who is unsharing a list is the owner of that list
|
||||
PreparedStatement accessCheck = connection.prepareStatement(GET_LIST_ACCESS);
|
||||
accessCheck.setString(1, cognitoID);
|
||||
accessCheck.setInt(2, listID);
|
||||
|
||||
ResultSet userLists = accessCheck.executeQuery();
|
||||
|
||||
//User does not own the list; unshare attempt fails
|
||||
if (!userLists.next()) {
|
||||
throw new AccessControlException("User does not have access to list");
|
||||
}
|
||||
|
||||
//Unshare the list with the specified sharee
|
||||
PreparedStatement unshareList = connection.prepareStatement(REMOVE_SHAREE);
|
||||
unshareList.setInt(1, listID);
|
||||
unshareList.setInt(2, shareeID);
|
||||
|
||||
cleanAccess.executeUpdate();
|
||||
connection.commit();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
11
Lambdas/Lists/ListShare/src/ListShareGET.java
Normal file
11
Lambdas/Lists/ListShare/src/ListShareGET.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 ListShareGET implements RequestHandler<Map<String,Object>, Object> {
|
||||
|
||||
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
|
||||
return BasicHandler.handleRequest(inputMap, unfilled, ListShareGetter.class);
|
||||
}
|
||||
}
|
||||
40
Lambdas/Lists/ListShare/src/ListShareGetter.java
Normal file
40
Lambdas/Lists/ListShare/src/ListShareGetter.java
Normal file
@@ -0,0 +1,40 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ListShareGetter implements CallHandler{
|
||||
private final Connection connection;
|
||||
private final String cognitoID;
|
||||
|
||||
private final String GET_LISTS = "SELECT * FROM ListSharee WHERE listID = ?;";
|
||||
|
||||
public ListShareGetter(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 getList = connection.prepareStatement(GET_LIST);
|
||||
getList.setInt(1, listID);
|
||||
|
||||
ResultSet getListResults = getList.executeQuery();
|
||||
getListResults.first();
|
||||
|
||||
//ListShare object to hold the data values of the first row retrived
|
||||
ListShare first = new ListShare(getListResults);
|
||||
|
||||
//Insert the ListShare objects to hold the data of the remaining rows into first's ListShare list
|
||||
while (getListResults.next()) {
|
||||
first.addtoList(new ListShare(getListResults));
|
||||
}
|
||||
|
||||
return first;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user