コード例 #1
0
ファイル: Handler.cs プロジェクト: mleyb/ims-api-app
        public async Task <APIGatewayProxyResponse> HandleRequestAsync(APIGatewayProxyRequest request, ILambdaContext context)
        {
            context.Logger.LogLine($"APIGateway request: {JsonConvert.SerializeObject(request)}");

            string vin = WebUtility.UrlDecode(request.PathParameters["id"]);

            IValidateVIN validateVIN = _sp.GetRequiredService <IValidateVIN>();

            if (!validateVIN.IsValid(vin))
            {
                return(APIGatewayProxyResponses.BadRequest());
            }

            IVehicleDataService dataService = _sp.GetRequiredService <IVehicleDataService>();

            VehicleData data = await dataService.GetVehicleDataAsync(vin);

            if (data == null)
            {
                return(APIGatewayProxyResponses.NotFound(vin));
            }

            var body = new ResponseBody
            {
                VIN          = data.VIN,
                CustomerId   = data.CustomerId,
                Make         = data.Make,
                Model        = data.Model,
                ModelYear    = data.ModelYear,
                ImportedDate = data.ImportedDate
            };

            return(APIGatewayProxyResponses.OKContent(body));
        }
コード例 #2
0
        public async Task <APIGatewayProxyResponse> HandleRequestAsync(APIGatewayProxyRequest request, ILambdaContext context)
        {
            context.Logger.LogLine($"APIGateway request: {JsonConvert.SerializeObject(request)}");

            ImportRequest requestBody = JsonConvert.DeserializeObject <ImportRequest>(request.Body);

            IValidateVIN validateVIN = _sp.GetRequiredService <IValidateVIN>();

            if (!validateVIN.IsValid(requestBody.VIN))
            {
                return(APIGatewayProxyResponses.BadRequest());
            }

            IVehicleDataService dataService = _sp.GetRequiredService <IVehicleDataService>();

            await dataService.ImportVehicleDataAsync(requestBody.CustomerId, requestBody.VIN);

            return(APIGatewayProxyResponses.OK());
        }