mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2026-03-10 18:55:03 +00:00
Store uiPosition
This will later be changeable and can then be used to sort lists received by the UI controller
This commit is contained in:
@@ -9,14 +9,16 @@ public class List {
|
||||
long lastUpdated;
|
||||
ArrayList<ItemEntry> entries;
|
||||
boolean shared;
|
||||
Integer uiPosition;
|
||||
|
||||
public List(ResultSet listRow, boolean shared) throws SQLException {
|
||||
public List(ResultSet listRow, boolean shared, Integer uiPosition) 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;
|
||||
this.uiPosition = uiPosition;
|
||||
}
|
||||
|
||||
public void addItemEntry(ItemEntry entry) {
|
||||
@@ -31,6 +33,8 @@ public class List {
|
||||
", owner='" + owner + '\'' +
|
||||
", lastUpdated=" + lastUpdated +
|
||||
", entries=" + entries +
|
||||
", shared=" + shared +
|
||||
", uiPosition=" + uiPosition +
|
||||
'}';
|
||||
}
|
||||
|
||||
@@ -77,4 +81,12 @@ public class List {
|
||||
public void setShared(boolean shared) {
|
||||
this.shared = shared;
|
||||
}
|
||||
|
||||
public Integer getUiPosition() {
|
||||
return uiPosition;
|
||||
}
|
||||
|
||||
public void setUiPosition(Integer uiPosition) {
|
||||
this.uiPosition = uiPosition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ public class ListAdder implements CallHandler {
|
||||
private String cognitoID;
|
||||
|
||||
private final String LIST_CREATE = "INSERT INTO List (name, owner, lastUpdated) VALUES (?, ?, ?);";
|
||||
private final String LIST_ACCESS_GRANT = "INSERT INTO ListSharee(listID, userID, permissionLevel) VALUES(?, ?, ?);";
|
||||
private final String LIST_ACCESS_GRANT = "INSERT INTO ListSharee(listID, userID, permissionLevel, uiPosition) VALUES(?, ?, ?, ?);";
|
||||
private final String UI_POSITION_CHECK = "SELECT Max(uiPosition) as maxUIPosition FROM ListSharee WHERE userID = ?;";
|
||||
|
||||
public ListAdder(Connection connection, String cognitoID) {
|
||||
this.connection = connection;
|
||||
@@ -17,9 +18,17 @@ public class ListAdder implements CallHandler {
|
||||
}
|
||||
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
||||
PreparedStatement statement = connection.prepareStatement(LIST_CREATE, Statement.RETURN_GENERATED_KEYS);
|
||||
|
||||
String listName = bodyMap.get("name").toString();//Needs safe checking
|
||||
|
||||
PreparedStatement uiPositionCheck = connection.prepareStatement(UI_POSITION_CHECK);
|
||||
uiPositionCheck.setString(1, cognitoID);
|
||||
ResultSet uiPositionCheckRS = uiPositionCheck.executeQuery();
|
||||
int nextPosition = 1;
|
||||
if (uiPositionCheckRS.next()) {
|
||||
nextPosition = uiPositionCheckRS.getInt("maxUIPosition") + 1;
|
||||
}
|
||||
|
||||
PreparedStatement statement = connection.prepareStatement(LIST_CREATE, Statement.RETURN_GENERATED_KEYS);
|
||||
statement.setString(1, listName);
|
||||
statement.setString(2, cognitoID);
|
||||
statement.setTimestamp(3, Timestamp.from(Instant.now()));
|
||||
@@ -32,6 +41,7 @@ public class ListAdder implements CallHandler {
|
||||
accessGrant.setInt(1, newID);
|
||||
accessGrant.setString(2, cognitoID);
|
||||
accessGrant.setInt(3, ListPermissions.getAll());
|
||||
accessGrant.setInt(4, nextPosition);
|
||||
System.out.println(accessGrant);
|
||||
accessGrant.executeUpdate();
|
||||
connection.commit();
|
||||
|
||||
@@ -12,7 +12,7 @@ public class ListGetter implements CallHandler{
|
||||
private final String cognitoID;
|
||||
|
||||
private final String GET_LIST = "SELECT * FROM List WHERE listID = ?;";
|
||||
private final String GET_LISTS = "SELECT listID FROM ListSharee WHERE userID = ?;";
|
||||
private final String GET_LISTS = "SELECT listID FROM ListSharee WHERE userID = ? ORDER BY uiPosition;";
|
||||
private final String SHARE_CHECK = "SELECT * FROM ListSharee WHERE listID = ?;";
|
||||
private final String GET_ENTRIES = "SELECT * FROM ListProduct WHERE listID = ?;";
|
||||
|
||||
@@ -42,12 +42,14 @@ public class ListGetter implements CallHandler{
|
||||
ResultSet accessResults = checkAccess.executeQuery();
|
||||
int sharees = 0;
|
||||
boolean verifiedAccess = false;
|
||||
int uiPosition = 1;
|
||||
while ((sharees < 2 && accessResults.next()) || !verifiedAccess) {
|
||||
if (accessResults.getString("userID").equals(cognitoID)) {
|
||||
verifiedAccess = true;
|
||||
if (!ListPermissions.hasPermission(accessResults.getInt("permissionLevel"), "Read")) {
|
||||
throw new AccessControlException("User " + cognitoID + " does not have permission to read list " + id);
|
||||
}
|
||||
uiPosition = accessResults.getInt("uiPosition");
|
||||
}
|
||||
sharees++;
|
||||
}
|
||||
@@ -61,7 +63,7 @@ public class ListGetter implements CallHandler{
|
||||
ResultSet getListResults = getList.executeQuery();
|
||||
getListResults.first();
|
||||
System.out.println(getListResults);
|
||||
List retrievedList = new List(getListResults, shared);
|
||||
List retrievedList = new List(getListResults, shared, uiPosition);
|
||||
System.out.println(retrievedList);
|
||||
PreparedStatement getListEntries = connection.prepareStatement(GET_ENTRIES);
|
||||
getListEntries.setInt(1, id);
|
||||
|
||||
Reference in New Issue
Block a user