mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 02:38:47 +00:00
Item Search V1
Still needs testing.
This commit is contained in:
parent
c96a40f0df
commit
68051fdaca
@ -14,7 +14,7 @@ public class Item {
|
||||
LocalDateTime retrievedDate;
|
||||
Integer fetchCounts;
|
||||
|
||||
Item(ResultSet itemRow) throws SQLException {
|
||||
public Item(ResultSet itemRow) throws SQLException {
|
||||
this.productID = itemRow.getInt(1);
|
||||
System.out.println(this.productID);
|
||||
this.chainID = itemRow.getInt(2);
|
||||
|
||||
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 %?%";
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user