mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 02:38:47 +00:00
Wrote the Lambdas API for getting and deleting list sharees -- testing still needed
This commit is contained in:
parent
36ef81ce16
commit
5f14d24625
@ -19,10 +19,6 @@ public class List {
|
|||||||
this.shared = shared;
|
this.shared = shared;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addItemEntry(ItemEntry entry) {
|
|
||||||
entries.add(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "List{" +
|
return "List{" +
|
||||||
@ -34,10 +30,6 @@ public class List {
|
|||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemEntry[] getEntries() {
|
|
||||||
return entries.toArray(new ItemEntry[entries.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getItemID() {
|
public Integer getItemID() {
|
||||||
return itemID;
|
return itemID;
|
||||||
}
|
}
|
||||||
@ -77,4 +69,12 @@ public class List {
|
|||||||
public void setShared(boolean shared) {
|
public void setShared(boolean shared) {
|
||||||
this.shared = shared;
|
this.shared = shared;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -67,10 +67,6 @@ public class List {
|
|||||||
this.lastUpdated = lastUpdated;
|
this.lastUpdated = lastUpdated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ListEntry[] getEntries() {
|
|
||||||
return entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isShared() {
|
public boolean isShared() {
|
||||||
return shared;
|
return shared;
|
||||||
}
|
}
|
||||||
@ -78,4 +74,8 @@ public class List {
|
|||||||
public void setShared(boolean shared) {
|
public void setShared(boolean shared) {
|
||||||
this.shared = shared;
|
this.shared = shared;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ListEntry[] getEntries() {
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,10 +3,18 @@ package com.example.listify.data;
|
|||||||
public class ListShare {
|
public class ListShare {
|
||||||
Integer listID;
|
Integer listID;
|
||||||
String shareWithEmail;
|
String shareWithEmail;
|
||||||
|
final ListShare[] other;
|
||||||
|
|
||||||
|
public ListShare(Integer listID, String shareWithEmail, ListShare[] other) {
|
||||||
|
this.listID = listID;
|
||||||
|
this.shareWithEmail = shareWithEmail;
|
||||||
|
this.other = other;
|
||||||
|
}
|
||||||
|
|
||||||
public ListShare(Integer listID, String shareWithEmail) {
|
public ListShare(Integer listID, String shareWithEmail) {
|
||||||
this.listID = listID;
|
this.listID = listID;
|
||||||
this.shareWithEmail = shareWithEmail;
|
this.shareWithEmail = shareWithEmail;
|
||||||
|
this.other = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getListID() {
|
public Integer getListID() {
|
||||||
@ -24,4 +32,8 @@ public class ListShare {
|
|||||||
public void setShareWithEmail(String shareWithEmail) {
|
public void setShareWithEmail(String shareWithEmail) {
|
||||||
this.shareWithEmail = shareWithEmail;
|
this.shareWithEmail = shareWithEmail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ListShare[] getEntries() {
|
||||||
|
return other;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user