Merge pull request #96 from ClaytonWWilson/chain-get

Add chainID to Chain class Lambda
This commit is contained in:
Nathan Merz 2020-11-01 21:08:26 -05:00 committed by GitHub
commit a355820c3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,35 @@
import java.sql.ResultSet;
import java.sql.SQLException;
public class Chain {
String name;
String website;
public Chain (ResultSet chainRow) throws SQLException {
this.name = chainRow.getString("name");
System.out.println(this.name);
this.website = chainRow.getString("website");
System.out.println(this.website);
}
public Chain(String name, String website) {
this.name = name;
this.website = website;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website;
}
}

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 ChainGET implements RequestHandler<Map<String,Object>, Object> {
public Object handleRequest(Map<String, Object> inputMap, Context unfilled) {
return BasicHandler.handleRequest(inputMap, unfilled, ChainGetter.class);
}
}

View File

@ -0,0 +1,29 @@
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 ChainGetter implements CallHandler {
private final Connection connection;
private final String GET_CHAIN = "SELECT * FROM Chain WHERE chainID = ?;";
public ChainGetter(Connection connection, String cognitoID) {
this.connection = connection;
}
@Override
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryMap, String cognitoID) throws SQLException {
PreparedStatement statement = connection.prepareStatement(GET_CHAIN);
statement.setInt(1, Integer.parseInt(queryMap.get("id")));
System.out.println(statement);
ResultSet queryResults = statement.executeQuery();
queryResults.first();
System.out.println(queryResults);
Chain retrievedChain = new Chain(queryResults);
System.out.println(retrievedChain);
return retrievedChain;
}
}

View File

@ -0,0 +1,27 @@
package com.example.listify.data;
public class Chain {
String name;
String website;
public Chain(String name, String website) {
this.name = name;
this.website = website;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website;
}
}