in Amazon.QLDB.DMVSample.Api/Functions/AddPersonFunction.cs [57:86]
public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
{
Person person = JsonConvert.DeserializeObject<Person>(request.Body, new JsonSerializerSettings { DateFormatString = "yyyy-MM-dd" });
return this.qldbDriver.Execute(transactionExecutor =>
{
context.Logger.Log($"Checking person already exists for GovId {person.GovId}.");
if (CheckIfPersonAlreadyExists(transactionExecutor, person.GovId))
{
context.Logger.Log($"Person does exist for GovId {person.GovId}, returning not modified.");
return new APIGatewayProxyResponse
{
StatusCode = (int)HttpStatusCode.NotModified
};
}
else
{
context.Logger.Log($"Inserting person for GovId {person.GovId}.");
IIonValue ionPerson = ConvertObjectToIonValue(person);
transactionExecutor.Execute($"INSERT INTO Person ?", ionPerson);
context.Logger.Log($"Inserted person for GovId {person.GovId}, returning OK.");
return new APIGatewayProxyResponse
{
StatusCode = (int)HttpStatusCode.OK
};
}
});
}