in Amazon.QLDB.DMVSample.Api/Functions/AddVehicleRegistrationFunction.cs [57:97]
public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
{
VehicleRegistration vehicleRegistration = JsonConvert.DeserializeObject<VehicleRegistration>(request.Body);
return this.qldbDriver.Execute(transactionExecutor =>
{
context.Logger.Log($"Looking for person document ID {vehicleRegistration.Owners?.PrimaryOwner?.PersonId}.");
string primaryOwnerPersonDocumentId = this.tableMetadataService.GetDocumentId(transactionExecutor, PersonTableName, "GovId", vehicleRegistration.Owners?.PrimaryOwner?.PersonId);
if (string.IsNullOrWhiteSpace(primaryOwnerPersonDocumentId))
{
context.Logger.Log($"No person found with GovId {vehicleRegistration.Owners?.PrimaryOwner?.PersonId}, returning not found.");
return new APIGatewayProxyResponse
{
StatusCode = (int)HttpStatusCode.NotFound
};
}
context.Logger.Log($"Checking vehicle registration already exists for VIN {vehicleRegistration.Vin}.");
if (CheckIfVinAlreadyExists(transactionExecutor, vehicleRegistration.Vin))
{
context.Logger.Log($"Vehicle registration does exist for VIN {vehicleRegistration.Vin}, returning not modified.");
return new APIGatewayProxyResponse
{
StatusCode = (int)HttpStatusCode.NotModified
};
}
context.Logger.Log($"Inserting vehicle registration for VIN {vehicleRegistration.Vin}.");
vehicleRegistration.Owners.PrimaryOwner.PersonId = primaryOwnerPersonDocumentId;
IIonValue ionVehicleRegistration = ConvertObjectToIonValue(vehicleRegistration);
transactionExecutor.Execute($"INSERT INTO VehicleRegistration ?", ionVehicleRegistration);
context.Logger.Log($"Inserted vehicle registration for VIN {vehicleRegistration.Vin}, returning OK.");
return new APIGatewayProxyResponse
{
StatusCode = (int)HttpStatusCode.OK
};
});
}