mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2026-03-10 18:55:03 +00:00
Add list position changing Lambdas
Initial shot at repositioning Lambdas.
This commit is contained in:
60
Lambdas/Lists/ListReposition/src/ListRepositionActor.java
Normal file
60
Lambdas/Lists/ListReposition/src/ListRepositionActor.java
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
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 ListRepositionActor implements CallHandler {
|
||||||
|
|
||||||
|
private Connection connection;
|
||||||
|
private String cognitoID;
|
||||||
|
|
||||||
|
public ListRepositionActor(Connection connection, String cognitoID) {
|
||||||
|
this.connection = connection;
|
||||||
|
this.cognitoID = cognitoID;
|
||||||
|
}
|
||||||
|
|
||||||
|
final private String GET_PRIOR_POSITON = "SELECT uiPosition FROM ListSharee WHERE userID = ? AND listID = ?;";
|
||||||
|
final private String SET_NEW_POSITON = "UPDATE ListSharee SET uiPosition = ? WHERE userID = ? AND listID = ?;";
|
||||||
|
final private String DECREMENT_HIGHER_POSITIONS = "UPDATE ListSharee SET uiPosition = uiPosition - 1 WHERE uiPosition > ? AND userID = ?;";
|
||||||
|
final private String INCREMENT_GEQ_POSITIONS = "UPDATE ListSharee SET uiPosition = uiPosition + 1 WHERE uiPosition >= ? AND userID = ?;";
|
||||||
|
|
||||||
|
|
||||||
|
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
||||||
|
Integer listID = (Integer) bodyMap.get("listID");
|
||||||
|
Integer newPosition = (Integer) bodyMap.get("newPosition");
|
||||||
|
|
||||||
|
PreparedStatement getPriorPosition = connection.prepareStatement(GET_PRIOR_POSITON);
|
||||||
|
getPriorPosition.setString(1, cognitoID);
|
||||||
|
getPriorPosition.setInt(2, listID);
|
||||||
|
ResultSet priorPositionRS = getPriorPosition.executeQuery();
|
||||||
|
if (!priorPositionRS.next()) {
|
||||||
|
throw new IllegalArgumentException("Bad listID for user");
|
||||||
|
}
|
||||||
|
Integer priorPosition = priorPositionRS.getInt("uiPosition");
|
||||||
|
|
||||||
|
PreparedStatement fillPriorPosition = connection.prepareStatement(DECREMENT_HIGHER_POSITIONS);
|
||||||
|
fillPriorPosition.setInt(1, priorPosition);
|
||||||
|
fillPriorPosition.setString(2, cognitoID);
|
||||||
|
System.out.println(fillPriorPosition);
|
||||||
|
fillPriorPosition.executeUpdate();
|
||||||
|
|
||||||
|
PreparedStatement openNewPosition = connection.prepareStatement(INCREMENT_GEQ_POSITIONS);
|
||||||
|
openNewPosition.setInt(1, priorPosition);
|
||||||
|
openNewPosition.setString(2, cognitoID);
|
||||||
|
System.out.println(openNewPosition);
|
||||||
|
openNewPosition.executeUpdate();
|
||||||
|
|
||||||
|
PreparedStatement setNewPosition = connection.prepareStatement(SET_NEW_POSITON);
|
||||||
|
setNewPosition.setInt(1, newPosition);
|
||||||
|
setNewPosition.setString(2, cognitoID);
|
||||||
|
setNewPosition.setInt(3, listID);
|
||||||
|
System.out.println(setNewPosition);
|
||||||
|
setNewPosition.executeUpdate();
|
||||||
|
|
||||||
|
connection.commit();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
11
Lambdas/Lists/ListReposition/src/ListRepositionPUT.java
Normal file
11
Lambdas/Lists/ListReposition/src/ListRepositionPUT.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 ListRepositionPUT implements RequestHandler<Map<String,Object>, Object> {
|
||||||
|
|
||||||
|
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
|
||||||
|
return BasicHandler.handleRequest(inputMap, unfilled, ListRepositionActor.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,7 +22,8 @@ public class ListSharer implements CallHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final private String CHECK_ACCESS = "SELECT * from ListSharee WHERE listID = ? AND userID = ?;";
|
final private String CHECK_ACCESS = "SELECT * from ListSharee WHERE listID = ? AND userID = ?;";
|
||||||
final private String SHARE_LIST = "INSERT INTO ListSharee(listID, userID, permissionLevel) VALUES(?, ?, ?) ON DUPLICATE KEY UPDATE permissionLevel = ?;";
|
final private String SHARE_LIST = "INSERT INTO ListSharee(listID, userID, permissionLevel, ) VALUES(?, ?, ?, ?) ON DUPLICATE KEY UPDATE permissionLevel = ?;";
|
||||||
|
private final String UI_POSITION_CHECK = "SELECT Max(uiPosition) as maxUIPosition FROM ListSharee WHERE userID = ?;";
|
||||||
|
|
||||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
||||||
PreparedStatement checkAccess = connection.prepareStatement(CHECK_ACCESS);
|
PreparedStatement checkAccess = connection.prepareStatement(CHECK_ACCESS);
|
||||||
@@ -62,12 +63,21 @@ public class ListSharer implements CallHandler {
|
|||||||
// throw new InputMismatchException("The specified user already has access");
|
// throw new InputMismatchException("The specified user already has access");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
PreparedStatement uiPositionCheck = connection.prepareStatement(UI_POSITION_CHECK);
|
||||||
|
uiPositionCheck.setString(1, shareWithSub);
|
||||||
|
ResultSet uiPositionCheckRS = uiPositionCheck.executeQuery();
|
||||||
|
int nextPosition = 1;
|
||||||
|
if (uiPositionCheckRS.next()) {
|
||||||
|
nextPosition = uiPositionCheckRS.getInt("maxUIPosition") + 1;
|
||||||
|
}
|
||||||
|
|
||||||
PreparedStatement shareList = connection.prepareStatement(SHARE_LIST);
|
PreparedStatement shareList = connection.prepareStatement(SHARE_LIST);
|
||||||
shareList.setInt(1, listID);
|
shareList.setInt(1, listID);
|
||||||
shareList.setString(2, shareWithSub);
|
shareList.setString(2, shareWithSub);
|
||||||
Integer permissionLevel = Integer.parseInt(bodyMap.get("permissionLevel").toString());
|
Integer permissionLevel = Integer.parseInt(bodyMap.get("permissionLevel").toString());
|
||||||
shareList.setInt(3, permissionLevel);
|
shareList.setInt(3, permissionLevel);
|
||||||
shareList.setInt(4, permissionLevel);
|
shareList.setInt(4, nextPosition);
|
||||||
|
shareList.setInt(5, permissionLevel);
|
||||||
shareList.executeUpdate();
|
shareList.executeUpdate();
|
||||||
connection.commit();
|
connection.commit();
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.example.listify.data;
|
||||||
|
|
||||||
|
public class ListReposition {
|
||||||
|
Integer listID;
|
||||||
|
Integer newPosition;
|
||||||
|
|
||||||
|
public ListReposition(Integer listID, Integer newPosition) {
|
||||||
|
this.listID = listID;
|
||||||
|
this.newPosition = newPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ListReposition{" +
|
||||||
|
"listID=" + listID +
|
||||||
|
", newPosition=" + newPosition +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getListID() {
|
||||||
|
return listID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListID(Integer listID) {
|
||||||
|
this.listID = listID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getNewPosition() {
|
||||||
|
return newPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNewPosition(Integer newPosition) {
|
||||||
|
this.newPosition = newPosition;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user