public APIGatewayProxyResponse FunctionHandler()

in Amazon.QLDB.DMVSample.Api/Functions/AddVehicleFunction.cs [56:85]


        public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            Vehicle vehicle = JsonConvert.DeserializeObject<Vehicle>(request.Body);

            return this.qldbDriver.Execute(transactionExecutor =>
            {
                context.Logger.Log($"Checking vehicle already exists for VIN {vehicle.Vin}.");
                if (CheckIfVinAlreadyExists(transactionExecutor, vehicle.Vin))
                {
                    context.Logger.Log($"Vehicle does exist for VIN {vehicle.Vin}, returning not modified.");
                    return new APIGatewayProxyResponse 
                    { 
                        StatusCode = (int)HttpStatusCode.NotModified
                    };
                }
                else
                {
                    context.Logger.Log($"Inserting vehicle for VIN {vehicle.Vin}.");

                    IIonValue ionVehicle = ConvertObjectToIonValue(vehicle);
                    transactionExecutor.Execute($"INSERT INTO Vehicle ?", ionVehicle);

                    context.Logger.Log($"Inserted ionVehicle for VIN {vehicle.Vin}, returning OK.");
                    return new APIGatewayProxyResponse 
                    { 
                        StatusCode = (int)HttpStatusCode.OK
                    };
                }
            });
        }