BAEL-650: Small refactoring
This commit is contained in:
parent
c9bb4b9e37
commit
dd01588369
|
@ -17,18 +17,16 @@ public class SavePersonHandler implements RequestHandler<PersonRequest, PersonRe
|
||||||
|
|
||||||
private DynamoDB dynamoDb;
|
private DynamoDB dynamoDb;
|
||||||
|
|
||||||
private final String DYNAMODB_TABLE_NAME = "Person";
|
private String DYNAMODB_TABLE_NAME = "Person";
|
||||||
private final Regions REGION = Regions.US_WEST_2;
|
private Regions REGION = Regions.US_WEST_2;
|
||||||
|
|
||||||
public PersonResponse handleRequest(PersonRequest personRequest, Context context) {
|
public PersonResponse handleRequest(PersonRequest personRequest, Context context) {
|
||||||
context.getLogger().log("personRequest: " + personRequest);
|
|
||||||
this.initDynamoDbClient();
|
this.initDynamoDbClient();
|
||||||
|
|
||||||
persistData(personRequest);
|
persistData(personRequest);
|
||||||
|
|
||||||
PersonResponse personResponse = new PersonResponse();
|
PersonResponse personResponse = new PersonResponse();
|
||||||
personResponse.setMessage("Saved Successfully!!!");
|
personResponse.setMessage("Saved Successfully!!!");
|
||||||
context.getLogger().log("personResponse: " + personResponse);
|
|
||||||
return personResponse;
|
return personResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,12 +38,11 @@ public class SavePersonHandler implements RequestHandler<PersonRequest, PersonRe
|
||||||
.withString("firstName", personRequest.getFirstName())
|
.withString("firstName", personRequest.getFirstName())
|
||||||
.withString("lastName", personRequest.getLastName())
|
.withString("lastName", personRequest.getLastName())
|
||||||
.withNumber("age", personRequest.getAge())
|
.withNumber("age", personRequest.getAge())
|
||||||
.withString("address", personRequest.getAddress())
|
.withString("address", personRequest.getAddress())));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initDynamoDbClient() {
|
private void initDynamoDbClient() {
|
||||||
final AmazonDynamoDBClient client = new AmazonDynamoDBClient();
|
AmazonDynamoDBClient client = new AmazonDynamoDBClient();
|
||||||
client.setRegion(Region.getRegion(REGION));
|
client.setRegion(Region.getRegion(REGION));
|
||||||
this.dynamoDb = new DynamoDB(client);
|
this.dynamoDb = new DynamoDB(client);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.baeldung.lambda.dynamodb.bean;
|
package com.baeldung.lambda.dynamodb.bean;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
|
||||||
public class PersonRequest {
|
public class PersonRequest {
|
||||||
private int id;
|
private int id;
|
||||||
|
@ -20,7 +21,7 @@ public class PersonRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final Gson gson = new Gson();
|
final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||||
return gson.toJson(this);
|
return gson.toJson(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue