Finish V1 of List and Item Lambdas

List and Item Lambdas and client calls should be roughly finished (pending full testing once databse config is done).
This commit is contained in:
NMerz
2020-10-03 18:35:27 -04:00
parent f107ab023d
commit 1f361cf401
8 changed files with 227 additions and 12 deletions

View File

@@ -13,4 +13,36 @@ public class ItemEntry {
addedDate = listRow.getObject(3, LocalDateTime.class);
purchased = listRow.getBoolean(4);
}
public Integer getProductID() {
return productID;
}
public void setProductID(Integer productID) {
this.productID = productID;
}
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
public LocalDateTime getAddedDate() {
return addedDate;
}
public void setAddedDate(LocalDateTime addedDate) {
this.addedDate = addedDate;
}
public Boolean getPurchased() {
return purchased;
}
public void setPurchased(Boolean purchased) {
this.purchased = purchased;
}
}

View File

@@ -1,18 +1,60 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.ArrayList;
public class List {
Integer itemID;
String name;
String owner;
LocalDateTime lastUpdated;
ArrayList<ItemEntry> entries;
public List(ResultSet listRow) throws SQLException {
itemID = listRow.getInt(1);
name = listRow.getString(2);
owner = listRow.getString(3);
lastUpdated = listRow.getObject(8, LocalDateTime.class);
lastUpdated = listRow.getObject(4, LocalDateTime.class);
entries = new ArrayList<>();
}
public void addItemEntry(ItemEntry entry) {
entries.add(entry);
}
public ItemEntry[] getEntries() {
return entries.toArray(new ItemEntry[entries.size()]);
}
public Integer getItemID() {
return itemID;
}
public void setItemID(Integer itemID) {
this.itemID = itemID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public LocalDateTime getLastUpdated() {
return lastUpdated;
}
public void setLastUpdated(LocalDateTime lastUpdated) {
this.lastUpdated = lastUpdated;
}
}

View File

@@ -4,6 +4,7 @@ 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;
@@ -12,6 +13,8 @@ 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 List WHERE owner = ?;";
private final String GET_ENTRIES = "SELECT * FROM ListProduct WHERE listID = ?;";
public ListGetter(DBConnector connector, String cognitoID) {
this.connector = connector;
@@ -21,17 +24,33 @@ public class ListGetter implements CallHandler{
@Override
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryMap, String cognitoID) throws SQLException {
Connection connection = connector.getConnection();
Integer id = Integer.parseInt(queryMap.get("id"));
try {
PreparedStatement statement = connection.prepareStatement(GET_LIST);
statement.setInt(1, Integer.parseInt(queryMap.get("id")));
System.out.println(statement);
ResultSet queryResults = statement.executeQuery();
queryResults.first();
System.out.println(queryResults);
String returnValue;
List retrievedItem = new List(queryResults);
System.out.println(retrievedItem);
return retrievedItem;
if (id == -1) {
PreparedStatement getLists = connection.prepareStatement(GET_LISTS);
getLists.setString(1, cognitoID);
ResultSet getListsResults = getLists.executeQuery();
ArrayList<Integer> listIds = new ArrayList<>();
while (getListsResults.next()) {
listIds.add(getListsResults.getInt(1));
}
return listIds;
}
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);
System.out.println(retrievedList);
PreparedStatement getListEntries = connection.prepareStatement(GET_ENTRIES);
getListEntries.setInt(1, id);
ResultSet getEntryResults = getListEntries.executeQuery();
while (getEntryResults.next()) {
retrievedList.addItemEntry(new ItemEntry(getEntryResults));
}
return retrievedList;
} finally {
connection.close();
}