mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 18:48:48 +00:00
commit
0ef75e3461
@ -1,7 +1,6 @@
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
public class Item {
|
public class Item {
|
||||||
Integer productID;
|
Integer productID;
|
||||||
@ -11,10 +10,10 @@ public class Item {
|
|||||||
BigDecimal price;
|
BigDecimal price;
|
||||||
String imageURL;
|
String imageURL;
|
||||||
String department;
|
String department;
|
||||||
LocalDateTime retrievedDate;
|
long retrievedDate;
|
||||||
Integer fetchCounts;
|
Integer fetchCounts;
|
||||||
|
|
||||||
Item(ResultSet itemRow) throws SQLException {
|
public Item(ResultSet itemRow) throws SQLException {
|
||||||
this.productID = itemRow.getInt(1);
|
this.productID = itemRow.getInt(1);
|
||||||
System.out.println(this.productID);
|
System.out.println(this.productID);
|
||||||
this.chainID = itemRow.getInt(2);
|
this.chainID = itemRow.getInt(2);
|
||||||
@ -29,7 +28,7 @@ public class Item {
|
|||||||
System.out.println(imageURL);
|
System.out.println(imageURL);
|
||||||
this.department = itemRow.getString(7);
|
this.department = itemRow.getString(7);
|
||||||
System.out.println(department);
|
System.out.println(department);
|
||||||
this.retrievedDate = itemRow.getObject(8, LocalDateTime.class);
|
this.retrievedDate = itemRow.getTimestamp(8).toInstant().toEpochMilli();
|
||||||
System.out.println(retrievedDate);
|
System.out.println(retrievedDate);
|
||||||
this.fetchCounts = itemRow.getInt(9);
|
this.fetchCounts = itemRow.getInt(9);
|
||||||
System.out.println(fetchCounts);
|
System.out.println(fetchCounts);
|
||||||
@ -106,11 +105,11 @@ public class Item {
|
|||||||
this.department = department;
|
this.department = department;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDateTime getRetrievedDate() {
|
public long getRetrievedDate() {
|
||||||
return retrievedDate;
|
return retrievedDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRetrievedDate(LocalDateTime retrievedDate) {
|
public void setRetrievedDate(long retrievedDate) {
|
||||||
this.retrievedDate = retrievedDate;
|
this.retrievedDate = retrievedDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
29
Lambdas/Lists/ItemSearch/src/ItemSearch.java
Normal file
29
Lambdas/Lists/ItemSearch/src/ItemSearch.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ItemSearch {
|
||||||
|
ArrayList<Item> results;
|
||||||
|
|
||||||
|
ItemSearch(ResultSet searchResults) throws SQLException {
|
||||||
|
results = new ArrayList<>();
|
||||||
|
while (searchResults.next()) {
|
||||||
|
results.add(new Item(searchResults));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ItemSearch{" +
|
||||||
|
"results=" + results +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Item> getResults() {
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResults(ArrayList<Item> results) {
|
||||||
|
this.results = results;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Lambdas/Lists/ItemSearch/src/ItemSearchGET.java
Normal file
11
Lambdas/Lists/ItemSearch/src/ItemSearchGET.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 ItemSearchGET implements RequestHandler<Map<String,Object>, Object> {
|
||||||
|
|
||||||
|
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
|
||||||
|
return BasicHandler.handleRequest(inputMap, unfilled, ItemSearcher.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
32
Lambdas/Lists/ItemSearch/src/ItemSearcher.java
Normal file
32
Lambdas/Lists/ItemSearch/src/ItemSearcher.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
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 ItemSearcher implements CallHandler {
|
||||||
|
|
||||||
|
DBConnector connector;
|
||||||
|
String cognitoID;
|
||||||
|
|
||||||
|
private final String GET_ITEM_MATCHES = "SELECT * FROM Product WHERE description LIKE ?";
|
||||||
|
|
||||||
|
public ItemSearcher(DBConnector connector, String cognitoID) {
|
||||||
|
this.connector = connector;
|
||||||
|
this.cognitoID = cognitoID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object conductAction(Map<String, Object> body, HashMap<String, String> queryParams, String s) throws SQLException {
|
||||||
|
try (Connection connection = connector.getConnection()) {
|
||||||
|
PreparedStatement getItemMatches = connection.prepareStatement(GET_ITEM_MATCHES);
|
||||||
|
getItemMatches.setString(1, "%" + queryParams.get("id") + "%");
|
||||||
|
System.out.println(getItemMatches);
|
||||||
|
ResultSet searchResults = getItemMatches.executeQuery();
|
||||||
|
ItemSearch searchResultsObject = new ItemSearch(searchResults);
|
||||||
|
System.out.println(searchResultsObject);
|
||||||
|
return searchResultsObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -6,13 +6,13 @@ public class ItemEntry {
|
|||||||
Integer listID;
|
Integer listID;
|
||||||
Integer productID;
|
Integer productID;
|
||||||
Integer quantity;
|
Integer quantity;
|
||||||
LocalDateTime addedDate;
|
long addedDate;
|
||||||
Boolean purchased;
|
Boolean purchased;
|
||||||
public ItemEntry(Integer listID, ResultSet listRow) throws SQLException {
|
public ItemEntry(Integer listID, ResultSet listRow) throws SQLException {
|
||||||
this.listID = listID;
|
this.listID = listID;
|
||||||
productID = listRow.getInt(1);
|
productID = listRow.getInt(1);
|
||||||
quantity = listRow.getInt(2);
|
quantity = listRow.getInt(2);
|
||||||
addedDate = listRow.getObject(3, LocalDateTime.class);
|
addedDate = listRow.getTimestamp(3).toInstant().toEpochMilli();
|
||||||
purchased = listRow.getBoolean(4);
|
purchased = listRow.getBoolean(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,11 +32,11 @@ public class ItemEntry {
|
|||||||
this.quantity = quantity;
|
this.quantity = quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDateTime getAddedDate() {
|
public long getAddedDate() {
|
||||||
return addedDate;
|
return addedDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAddedDate(LocalDateTime addedDate) {
|
public void setAddedDate(long addedDate) {
|
||||||
this.addedDate = addedDate;
|
this.addedDate = addedDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -25,7 +26,7 @@ public class ListEntryAdder implements CallHandler {
|
|||||||
statement.setInt(1, (Integer) bodyMap.get("productID"));
|
statement.setInt(1, (Integer) bodyMap.get("productID"));
|
||||||
statement.setInt(2, (Integer) bodyMap.get("listID"));
|
statement.setInt(2, (Integer) bodyMap.get("listID"));
|
||||||
statement.setInt(3, (Integer) bodyMap.get("quantity"));
|
statement.setInt(3, (Integer) bodyMap.get("quantity"));
|
||||||
statement.setObject(4, Instant.now().atZone(ZoneOffset.UTC).toLocalDateTime());
|
statement.setTimestamp(4, Timestamp.from(Instant.now()));
|
||||||
statement.setBoolean(5, (Boolean) bodyMap.get("purchased"));
|
statement.setBoolean(5, (Boolean) bodyMap.get("purchased"));
|
||||||
System.out.println(statement);
|
System.out.println(statement);
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import androidx.navigation.ui.AppBarConfiguration;
|
|||||||
import androidx.navigation.ui.NavigationUI;
|
import androidx.navigation.ui.NavigationUI;
|
||||||
import com.amplifyframework.auth.AuthException;
|
import com.amplifyframework.auth.AuthException;
|
||||||
import com.example.listify.data.Item;
|
import com.example.listify.data.Item;
|
||||||
|
import com.example.listify.data.ItemSearch;
|
||||||
import com.example.listify.data.List;
|
import com.example.listify.data.List;
|
||||||
import com.example.listify.data.ListEntry;
|
import com.example.listify.data.ListEntry;
|
||||||
import com.google.android.material.navigation.NavigationView;
|
import com.google.android.material.navigation.NavigationView;
|
||||||
@ -21,7 +22,6 @@ import org.json.JSONException;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZoneOffset;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@ -84,7 +84,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
//The name is the only part of this that is used, the rest is generated by the Lambda.
|
//The name is the only part of this that is used, the rest is generated by the Lambda.
|
||||||
List testList = new List(-1, "New List", "user filled by lambda", Instant.now().toEpochMilli());
|
List testList = new List(-1, "New List", "user filled by lambda", Instant.now().toEpochMilli());
|
||||||
//Everything except addedDate is used for ItemEntry
|
//Everything except addedDate is used for ItemEntry
|
||||||
ListEntry entry = new ListEntry(1, 1, new Random().nextInt(), Instant.now().atZone(ZoneOffset.UTC).toLocalDateTime(),false);
|
ListEntry entry = new ListEntry(1, 4, Math.abs(new Random().nextInt()), Instant.now().toEpochMilli(),false);
|
||||||
SynchronousReceiver<Integer> idReceiver = new SynchronousReceiver<>();
|
SynchronousReceiver<Integer> idReceiver = new SynchronousReceiver<>();
|
||||||
try {
|
try {
|
||||||
requestor.postObject(testList, idReceiver, idReceiver);
|
requestor.postObject(testList, idReceiver, idReceiver);
|
||||||
@ -100,10 +100,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
requestor.getObject("39", List.class, listReceiver, listReceiver);
|
requestor.getObject("39", List.class, listReceiver, listReceiver);
|
||||||
SynchronousReceiver<Integer[]> listIdsReceiver = new SynchronousReceiver<>();
|
SynchronousReceiver<Integer[]> listIdsReceiver = new SynchronousReceiver<>();
|
||||||
requestor.getListOfIds(List.class, listIdsReceiver, listIdsReceiver);
|
requestor.getListOfIds(List.class, listIdsReceiver, listIdsReceiver);
|
||||||
|
SynchronousReceiver<ItemSearch> itemSearchReceiver = new SynchronousReceiver<>();
|
||||||
|
requestor.getObject("r", ItemSearch.class, itemSearchReceiver, itemSearchReceiver);
|
||||||
try {
|
try {
|
||||||
System.out.println(itemReceiver.await());
|
System.out.println(itemReceiver.await());
|
||||||
System.out.println(listReceiver.await());
|
System.out.println(listReceiver.await());
|
||||||
System.out.println(Arrays.toString(listIdsReceiver.await()));
|
System.out.println(Arrays.toString(listIdsReceiver.await()));
|
||||||
|
System.out.println(itemSearchReceiver.await());
|
||||||
} catch (Exception receiverError) {
|
} catch (Exception receiverError) {
|
||||||
receiverError.printStackTrace();
|
receiverError.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package com.example.listify.data;
|
package com.example.listify.data;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
public class Item {
|
public class Item {
|
||||||
Integer productID;
|
Integer productID;
|
||||||
@ -11,11 +10,11 @@ public class Item {
|
|||||||
BigDecimal price;
|
BigDecimal price;
|
||||||
String imageURL;
|
String imageURL;
|
||||||
String department;
|
String department;
|
||||||
LocalDateTime retrievedDate;
|
long retrievedDate;
|
||||||
Integer fetchCounts;
|
Integer fetchCounts;
|
||||||
|
|
||||||
public Item(Integer productID, Integer chainID, String upc, String description, BigDecimal price,
|
public Item(Integer productID, Integer chainID, String upc, String description, BigDecimal price,
|
||||||
String imageURL, String department, LocalDateTime retrievedDate, Integer fetchCounts) {
|
String imageURL, String department, long retrievedDate, Integer fetchCounts) {
|
||||||
this.productID = productID;
|
this.productID = productID;
|
||||||
this.chainID = chainID;
|
this.chainID = chainID;
|
||||||
this.upc = upc;
|
this.upc = upc;
|
||||||
@ -37,7 +36,7 @@ public class Item {
|
|||||||
", price=" + price +
|
", price=" + price +
|
||||||
", imageURL='" + imageURL + '\'' +
|
", imageURL='" + imageURL + '\'' +
|
||||||
", department='" + department + '\'' +
|
", department='" + department + '\'' +
|
||||||
", retrievedDate=" + (retrievedDate == null ? null : retrievedDate) +
|
", retrievedDate=" + retrievedDate +
|
||||||
", fetchCounts=" + fetchCounts +
|
", fetchCounts=" + fetchCounts +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
@ -98,11 +97,11 @@ public class Item {
|
|||||||
this.department = department;
|
this.department = department;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDateTime getRetrievedDate() {
|
public long getRetrievedDate() {
|
||||||
return retrievedDate;
|
return retrievedDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRetrievedDate(LocalDateTime retrievedDate) {
|
public void setRetrievedDate(long retrievedDate) {
|
||||||
this.retrievedDate = retrievedDate;
|
this.retrievedDate = retrievedDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,27 @@
|
|||||||
|
package com.example.listify.data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ItemSearch {
|
||||||
|
ArrayList<Item> results;
|
||||||
|
|
||||||
|
public ItemSearch(ArrayList<Item> results) {
|
||||||
|
this.results = results;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ItemSearch{" +
|
||||||
|
"results=" + results +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Item> getResults() {
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResults(ArrayList<Item> results) {
|
||||||
|
this.results = results;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -1,15 +1,13 @@
|
|||||||
package com.example.listify.data;
|
package com.example.listify.data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
public class ListEntry {
|
public class ListEntry {
|
||||||
Integer listID;
|
Integer listID;
|
||||||
Integer productID;
|
Integer productID;
|
||||||
Integer quantity;
|
Integer quantity;
|
||||||
LocalDateTime addedDate;
|
long addedDate;
|
||||||
Boolean purchased;
|
Boolean purchased;
|
||||||
|
|
||||||
public ListEntry(Integer listID, Integer productID, Integer quantity, LocalDateTime addedDate, Boolean purchased) {
|
public ListEntry(Integer listID, Integer productID, Integer quantity, long addedDate, Boolean purchased) {
|
||||||
this.listID = listID;
|
this.listID = listID;
|
||||||
this.productID = productID;
|
this.productID = productID;
|
||||||
this.quantity = quantity;
|
this.quantity = quantity;
|
||||||
@ -52,11 +50,11 @@ public class ListEntry {
|
|||||||
this.quantity = quantity;
|
this.quantity = quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDateTime getAddedDate() {
|
public long getAddedDate() {
|
||||||
return addedDate;
|
return addedDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAddedDate(LocalDateTime addedDate) {
|
public void setAddedDate(long addedDate) {
|
||||||
this.addedDate = addedDate;
|
this.addedDate = addedDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user