Item Search V1

Still needs testing.
This commit is contained in:
NMerz 2020-10-05 22:54:43 -04:00
parent c96a40f0df
commit 68051fdaca
5 changed files with 100 additions and 1 deletions

View File

@ -14,7 +14,7 @@ public class Item {
LocalDateTime retrievedDate; LocalDateTime 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);

View 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;
}
}

View 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);
}
}

View 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;
}
}
}

View File

@ -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;
}
}