mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2026-03-11 02:55:04 +00:00
Update list sharing
Fix quite a variety of bugs with list sharing, mostly relating to ListShareGET not conforming to its contract
This commit is contained in:
@@ -9,9 +9,9 @@ public class ListShare {
|
||||
Integer uiPosition;
|
||||
ArrayList<ListShare> other;
|
||||
|
||||
public ListShare(ResultSet listRow) throws SQLException {
|
||||
public ListShare(ResultSet listRow, String shareWithEmail) throws SQLException {
|
||||
this.listID = listRow.getInt("listID");
|
||||
this.shareWithEmail = listRow.getString("userID");
|
||||
this.shareWithEmail = shareWithEmail;
|
||||
this.permissionLevel = listRow.getInt("permissionLevel");
|
||||
this.uiPosition = listRow.getInt("uiPosition");
|
||||
other = new ArrayList<>();
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import com.amazonaws.services.lambda.AWSLambdaClientBuilder;
|
||||
import com.amazonaws.services.lambda.model.InvokeRequest;
|
||||
import com.amazonaws.services.lambda.model.InvokeResult;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.InputMismatchException;
|
||||
import java.util.Map;
|
||||
|
||||
public class ListShareGetter implements CallHandler{
|
||||
@@ -24,14 +30,63 @@ public class ListShareGetter implements CallHandler{
|
||||
getList.setInt(1, listID);
|
||||
|
||||
ResultSet getListResults = getList.executeQuery();
|
||||
getListResults.first();
|
||||
System.out.println(getListResults);
|
||||
|
||||
ListShare first = null;
|
||||
while (getListResults.next() && first == null) {
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
invokeRequest.setFunctionName("UserGET");
|
||||
invokeRequest.setPayload("{" +
|
||||
" \"body\": {" +
|
||||
" }," +
|
||||
" \"params\": {" +
|
||||
" \"querystring\": {" +
|
||||
" \"id\": \"" + getListResults.getString("userID") + "\"" +
|
||||
" }" +
|
||||
" }," +
|
||||
" \"context\": {" +
|
||||
" \"sub\": \"not used\"" +
|
||||
" }" +
|
||||
"}");
|
||||
InvokeResult invokeResult = AWSLambdaClientBuilder.defaultClient().invoke(invokeRequest);
|
||||
if (invokeResult.getStatusCode() != 200) {
|
||||
throw new InputMismatchException("Could not find specified user to share with");
|
||||
}
|
||||
String shareWithEmail = new Gson().fromJson(new String(invokeResult.getPayload().array()), User.class).email;
|
||||
first = new ListShare(getListResults, shareWithEmail);
|
||||
if (first.permissionLevel == 0 || first.permissionLevel == 1) {
|
||||
first = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//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));
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
invokeRequest.setFunctionName("UserGET");
|
||||
invokeRequest.setPayload("{" +
|
||||
" \"body\": {" +
|
||||
" }," +
|
||||
" \"params\": {" +
|
||||
" \"querystring\": {" +
|
||||
" \"id\": \"" + getListResults.getString("userID") + "\"" +
|
||||
" }" +
|
||||
" }," +
|
||||
" \"context\": {" +
|
||||
" \"sub\": \"not used\"" +
|
||||
" }" +
|
||||
"}");
|
||||
InvokeResult invokeResult = AWSLambdaClientBuilder.defaultClient().invoke(invokeRequest);
|
||||
if (invokeResult.getStatusCode() != 200) {
|
||||
throw new InputMismatchException("Could not find specified user to share with");
|
||||
}
|
||||
String shareWithEmail = new Gson().fromJson(new String(invokeResult.getPayload().array()), User.class).email;
|
||||
ListShare newShare = new ListShare(getListResults, shareWithEmail);
|
||||
System.out.println(newShare);
|
||||
if (newShare.permissionLevel != 0 && newShare.permissionLevel != 1) {
|
||||
first.addtoList(newShare);
|
||||
}
|
||||
}
|
||||
|
||||
return first;
|
||||
|
||||
Reference in New Issue
Block a user