Listify/Lambdas/Lists/ItemSearch/src/ItemSearcher.java
NMerz 45c7ac15bd Limit item search results
Add a limit on item search results so the user is not overwhelmed.
2020-10-24 11:53:12 -04:00

31 lines
1.1 KiB
Java

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 {
Connection connection;
String cognitoID;
private final String GET_ITEM_MATCHES = "SELECT * FROM Product WHERE description LIKE ? LIMIT 100;";
public ItemSearcher(Connection connection, String cognitoID) {
this.connection = connection;
this.cognitoID = cognitoID;
}
@Override
public Object conductAction(Map<String, Object> body, HashMap<String, String> queryParams, String s) throws SQLException {
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;
}
}