public APIGatewayProxyResponse FunctionHandler()

in Amazon.QLDB.DMVSample.Api/Functions/FindVehiclesFunction.cs [57:91]


        public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            string govId = request.QueryStringParameters["GovId"];
            
            IResult selectResult = this.qldbDriver.Execute(transactionExecutor =>
            {
                string personDocumentId = this.tableMetadataService.GetDocumentId(transactionExecutor, PersonTableName, "GovId", govId);
                context.Logger.Log($"Searching for vehicles where primary owner ID is {personDocumentId}.");

                IIonValue ionPersonDocumentId = this.valueFactory.NewString(personDocumentId);
                IResult result = transactionExecutor.Execute("SELECT v FROM Vehicle AS v INNER JOIN VehicleRegistration AS r "
                    + "ON v.VIN = r.VIN WHERE r.Owners.PrimaryOwner.PersonId = ?", ionPersonDocumentId);
                return result;
            });

            IEnumerable<Vehicle> vehicles = selectResult.Select(x => 
            {
                var ionVehicle = x.GetField("v");
                return new Vehicle 
                {
                    Vin = ionVehicle.GetField("VIN").StringValue,
                    Type = ionVehicle.GetField("Type").StringValue,
                    Year = ionVehicle.GetField("Year").IntValue,
                    Make = ionVehicle.GetField("Make").StringValue,
                    Model = ionVehicle.GetField("Model").StringValue,
                    Color = ionVehicle.GetField("Color").StringValue
                };
            });

            return new APIGatewayProxyResponse 
            { 
                StatusCode = vehicles.Any() ? (int)HttpStatusCode.OK : (int)HttpStatusCode.NotFound,
                Body = JsonConvert.SerializeObject(vehicles)
            };
        }