public async Task <IActionResult> GetEatHealthParameters([FromQuery] DateTime dateInUtc) { var loggedUser = User.GetUserIdFromToken(); var user = await _userService.GetUserDevicesAsync(loggedUser); var userImcKcal = await _eatService.GetKCalImcAsync(loggedUser, dateInUtc); IHealthyHelper healthyHelper = new HealthyHelper(userImcKcal.imc, userImcKcal.kcal, _accountService, _dishService); var result = healthyHelper.GetUserEatHealtParameters(user); return(Ok(new ApiOkResponse(result))); }
/// <summary> /// Return list of plan summary assuming that only one user's eats are provided /// </summary> /// <param name="eats">List of eats of an user</param> /// <returns></returns> public async Task <List <PlanSummaryResponse> > GetPlanSummaryAsync(IEnumerable <Eat> eats) { var result = new List <PlanSummaryResponse>(); var anyEat = eats.FirstOrDefault(); if (anyEat == null) { return(result); } var user = await _userService.GetUserDevicesAsync(anyEat.UserId); foreach (var eat in eats) { var planDate = eat.CreatedAt; if (!result.Any(r => r.PlanDateTime.Date == planDate.Date)) { var userEats = eats.Where(e => e.CreatedAt.Date == planDate.Date); IHealthyHelper healthyHelper = new HealthyHelper(eat.ImcAtThatMoment, eat.KCalAtThatMoment, _accountService, _dishService); var userHealthParameters = healthyHelper.GetUserEatHealtParameters(user); var isBalancedSummary = healthyHelper.IsBalancedPlan(user, userEats); var planSummary = new PlanSummaryResponse { PlanDateTime = planDate, UserEatHealtParameters = userHealthParameters, EatBalancedSummary = isBalancedSummary }; result.Add(planSummary); } } return(result); }