diff --git a/Lambdas/Lists/List/src/List.java b/Lambdas/Lists/List/src/List.java index 4fc6f98..02d9723 100644 --- a/Lambdas/Lists/List/src/List.java +++ b/Lambdas/Lists/List/src/List.java @@ -8,13 +8,15 @@ public class List { String owner; long lastUpdated; ArrayList entries; + boolean shared; - public List(ResultSet listRow) throws SQLException { + public List(ResultSet listRow, boolean shared) throws SQLException { itemID = listRow.getInt("listID"); name = listRow.getString("name"); owner = listRow.getString("owner"); lastUpdated = listRow.getTimestamp("lastUpdated").toInstant().toEpochMilli(); entries = new ArrayList<>(); + this.shared = shared; } public void addItemEntry(ItemEntry entry) { @@ -67,4 +69,12 @@ public class List { public void setLastUpdated(long lastUpdated) { this.lastUpdated = lastUpdated; } + + public boolean getShared() { + return shared; + } + + public void setShared(boolean shared) { + this.shared = shared; + } } diff --git a/Lambdas/Lists/List/src/ListGetter.java b/Lambdas/Lists/List/src/ListGetter.java index c5a9ed1..22bea8d 100644 --- a/Lambdas/Lists/List/src/ListGetter.java +++ b/Lambdas/Lists/List/src/ListGetter.java @@ -12,6 +12,7 @@ public class ListGetter implements CallHandler{ private final String GET_LIST = "SELECT * FROM List WHERE listID = ?;"; private final String GET_LISTS = "SELECT listID FROM ListSharee WHERE userID = ?;"; + private final String SHARE_CHECK = "SELECT * FROM ListSharee WHERE listID = ?;"; private final String GET_ENTRIES = "SELECT * FROM ListProduct WHERE listID = ?;"; public ListGetter(Connection connection, String cognitoID) { @@ -34,13 +35,25 @@ public class ListGetter implements CallHandler{ } return listIds; } + PreparedStatement checkAccess = connection.prepareStatement(SHARE_CHECK); + checkAccess.setInt(1, id); + System.out.println(checkAccess); + ResultSet accessResults = checkAccess.executeQuery(); + int sharees = 0; + while (sharees < 2 && accessResults.next()) { + sharees++; + } + boolean shared = false; + if (sharees > 1) { + shared = true; + } PreparedStatement getList = connection.prepareStatement(GET_LIST); getList.setInt(1, id); System.out.println(getList); ResultSet getListResults = getList.executeQuery(); getListResults.first(); System.out.println(getListResults); - List retrievedList = new List(getListResults); + List retrievedList = new List(getListResults, shared); System.out.println(retrievedList); PreparedStatement getListEntries = connection.prepareStatement(GET_ENTRIES); getListEntries.setInt(1, id); diff --git a/Listify/app/src/main/java/com/example/listify/data/List.java b/Listify/app/src/main/java/com/example/listify/data/List.java index 23d77ea..e04211f 100644 --- a/Listify/app/src/main/java/com/example/listify/data/List.java +++ b/Listify/app/src/main/java/com/example/listify/data/List.java @@ -8,17 +8,19 @@ public class List { String owner; long lastUpdated; final ListEntry[] entries; + boolean shared; - public List(Integer itemID, String name, String owner, long lastUpdated, ListEntry[] entries) { + public List(Integer itemID, String name, String owner, long lastUpdated, ListEntry[] entries, boolean shared) { this.itemID = itemID; this.name = name; this.owner = owner; this.lastUpdated = lastUpdated; this.entries = entries; + this.shared = false; } public List(Integer itemID, String name, String owner, long lastUpdated) { - this(itemID, name, owner, lastUpdated, null); + this(itemID, name, owner, lastUpdated, null, false); } @Override @@ -29,6 +31,7 @@ public class List { ", owner='" + owner + '\'' + ", lastUpdated=" + lastUpdated + ", entries=" + Arrays.toString(entries) + + ", shared=" + shared + '}'; } @@ -67,4 +70,12 @@ public class List { public ListEntry[] getEntries() { return entries; } + + public boolean isShared() { + return shared; + } + + public void setShared(boolean shared) { + this.shared = shared; + } }