public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { var healthRecord = await _cosmosDbLogic.GetHealthPlanetPostDataAsync(); if (healthRecord == null) { return(new BadRequestErrorMessageResult("最新の身体データ取得に失敗しました。")); } var goal = await _cosmosDbLogic.GetGoalAsync(); await _postHealthDataLogic.PostHealthDataAsync(healthRecord, goal); return(new OkObjectResult("")); }
public async Task <IActionResult> GetToPost( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, ILogger log) { var now = DateTime.UtcNow; var period = 7; if (!(string.IsNullOrEmpty(req.Query["period"])) && !int.TryParse(req.Query["period"], out period)) { return(new BadRequestErrorMessageResult("期間指定の値が数値以外の値になっています。")); } if (0 > period || period > 120) { return(new BadRequestErrorMessageResult("期間指定の値は0から120までの値を指定してください。")); } var postWebHook = true; if (!(string.IsNullOrEmpty(req.Query["postwebhook"])) && !bool.TryParse(req.Query["postwebhook"], out postWebHook)) { return(new BadRequestErrorMessageResult("Webhook投稿の指定に誤りがあります。")); } var postGoogleFit = true; if (!(string.IsNullOrEmpty(req.Query["postgooglefit"])) && !bool.TryParse(req.Query["postgooglefit"], out postGoogleFit)) { return(new BadRequestErrorMessageResult("Webhook投稿の指定に誤りがあります。")); } //HealthPlanetからデータを取得 var(isSuccess, height, healthDataList) = await _healthPlanetLogic.GetHealthDataAsync(period); if (!isSuccess) { return(new BadRequestErrorMessageResult("HealthPlanetからのデータ取得に失敗しました。")); } if (healthDataList.Count == 0) { return(new BadRequestErrorMessageResult("期間内にHealthPlanetから有効なレコードが取得されませんでした。")); } //DB格納用のリストを生成 var healthRecordList = _healthPlanetLogic.ShapeHealthRecord(height, healthDataList); //身体データをDBに格納 await _cosmosDbLogic.SetHealthPlanetHealthDataAsync(healthRecordList); //Webhook投稿処理 if (postWebHook) { var goal = await _cosmosDbLogic.GetGoalAsync(); await _postHealthDataLogic.PostHealthDataAsync( healthRecordList.OrderByDescending(o => o.AssayDate).First(), goal); } //GoogleFitへ投稿 if (postGoogleFit) { await _googleFitLogic.SetGoogleFit(healthRecordList); } return(new OkObjectResult("取得及び投稿完了")); }