mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2026-03-10 10:45:04 +00:00
Merge branch 'search-history' into sharing-permissions
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import com.amazonaws.services.lambda.AWSLambdaClientBuilder;
|
||||
import com.amazonaws.services.lambda.model.InvokeRequest;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@@ -18,13 +21,30 @@ public class ItemSearcher implements CallHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object conductAction(Map<String, Object> body, HashMap<String, String> queryParams, String s) throws SQLException {
|
||||
public Object conductAction(Map<String, Object> body, HashMap<String, String> queryParams, String cognitoID) 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);
|
||||
InvokeRequest invokeRequest = new InvokeRequest();
|
||||
invokeRequest.setFunctionName("SearchHistoryPOST");
|
||||
invokeRequest.setPayload("{" +
|
||||
" \"body\": {" +
|
||||
" \"searchTerm\": \"" + queryParams.get("id") + "\"" +
|
||||
" }," +
|
||||
" \"params\": {" +
|
||||
" \"querystring\": {" +
|
||||
" }" +
|
||||
" }," +
|
||||
" \"context\": {" +
|
||||
" \"sub\": \"" + cognitoID + "\"" +
|
||||
" }" +
|
||||
"}");
|
||||
invokeRequest.setInvocationType("Event");
|
||||
System.out.println(invokeRequest);
|
||||
AWSLambdaClientBuilder.defaultClient().invoke(invokeRequest);
|
||||
return searchResultsObject;
|
||||
}
|
||||
}
|
||||
|
||||
43
Lambdas/Lists/SearchHistory/src/SearchHistory.java
Normal file
43
Lambdas/Lists/SearchHistory/src/SearchHistory.java
Normal file
@@ -0,0 +1,43 @@
|
||||
import java.io.Serializable;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SearchHistory implements Serializable {
|
||||
ArrayList<String> searches;
|
||||
|
||||
public SearchHistory(ArrayList<String> searches) {
|
||||
this.searches = searches;
|
||||
}
|
||||
|
||||
public SearchHistory() {
|
||||
this.searches = new ArrayList<>();
|
||||
}
|
||||
|
||||
public SearchHistory(ResultSet row) throws SQLException {
|
||||
this.searches = new ArrayList<>();
|
||||
row.beforeFirst();
|
||||
while (row.next()) {
|
||||
this.searches.add(row.getString("search"));
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<String> getSearches() {
|
||||
return searches;
|
||||
}
|
||||
|
||||
public void setSearches(ArrayList<String> searches) {
|
||||
this.searches = searches;
|
||||
}
|
||||
|
||||
public void addSearch(String newSearch) {
|
||||
searches.add(newSearch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SearchHistory{" +
|
||||
"searches=" + searches +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
11
Lambdas/Lists/SearchHistory/src/SearchHistoryGET.java
Normal file
11
Lambdas/Lists/SearchHistory/src/SearchHistoryGET.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 SearchHistoryGET implements RequestHandler<Map<String,Object>, Object> {
|
||||
|
||||
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
|
||||
return BasicHandler.handleRequest(inputMap, unfilled, SearchHistoryGetter.class);
|
||||
}
|
||||
}
|
||||
31
Lambdas/Lists/SearchHistory/src/SearchHistoryGetter.java
Normal file
31
Lambdas/Lists/SearchHistory/src/SearchHistoryGetter.java
Normal file
@@ -0,0 +1,31 @@
|
||||
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 SearchHistoryGetter implements CallHandler {
|
||||
|
||||
private Connection connection;
|
||||
private String cognitoID;
|
||||
|
||||
public SearchHistoryGetter(Connection connection, String cognitoID) {
|
||||
this.connection = connection;
|
||||
this.cognitoID = cognitoID;
|
||||
}
|
||||
|
||||
final private String SELECT_HISTORY = "SELECT * from SearchHistory WHERE userID = ?;";
|
||||
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
||||
PreparedStatement select_history = connection.prepareStatement(SELECT_HISTORY);
|
||||
select_history.setString(1, cognitoID);
|
||||
System.out.println(select_history);
|
||||
ResultSet searchHistory = select_history.executeQuery();
|
||||
if (!searchHistory.first()) {
|
||||
return new SearchHistory();
|
||||
}
|
||||
System.out.println(new SearchHistory(searchHistory));
|
||||
return new SearchHistory(searchHistory);
|
||||
}
|
||||
}
|
||||
11
Lambdas/Lists/SearchHistory/src/SearchHistoryPOST.java
Normal file
11
Lambdas/Lists/SearchHistory/src/SearchHistoryPOST.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 SearchHistoryPOST implements RequestHandler<Map<String,Object>, Object> {
|
||||
|
||||
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
|
||||
return BasicHandler.handleRequest(inputMap, unfilled, SearchHistoryUpdater.class);
|
||||
}
|
||||
}
|
||||
28
Lambdas/Lists/SearchHistory/src/SearchHistoryUpdater.java
Normal file
28
Lambdas/Lists/SearchHistory/src/SearchHistoryUpdater.java
Normal file
@@ -0,0 +1,28 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SearchHistoryUpdater implements CallHandler {
|
||||
|
||||
private Connection connection;
|
||||
private String cognitoID;
|
||||
|
||||
public SearchHistoryUpdater(Connection connection, String cognitoID) {
|
||||
this.connection = connection;
|
||||
this.cognitoID = cognitoID;
|
||||
}
|
||||
|
||||
final private String UPDATE_HISTORY = "INSERT INTO SearchHistory(userID, search) VALUES(?, ?);";
|
||||
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
||||
PreparedStatement store_history = connection.prepareStatement(UPDATE_HISTORY);
|
||||
store_history.setString(1, cognitoID);
|
||||
store_history.setObject(2, bodyMap.get("searchTerm"));
|
||||
System.out.println(store_history);
|
||||
store_history.executeUpdate();
|
||||
connection.commit();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -94,6 +94,11 @@
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
<version>2.8.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>2.11.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user