-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from simonoppowa/90-feature-request-change-kc…
…al-intake 90 feature request change kcal intake
- Loading branch information
Showing
25 changed files
with
728 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:collection/collection.dart'; | ||
import 'package:opennutritracker/core/data/repository/config_repository.dart'; | ||
import 'package:opennutritracker/core/data/repository/user_activity_repository.dart'; | ||
import 'package:opennutritracker/core/data/repository/user_repository.dart'; | ||
import 'package:opennutritracker/core/domain/entity/user_entity.dart'; | ||
import 'package:opennutritracker/core/utils/calc/calorie_goal_calc.dart'; | ||
|
||
class GetKcalGoalUsecase { | ||
final UserRepository _userRepository; | ||
final ConfigRepository _configRepository; | ||
final UserActivityRepository _userActivityRepository; | ||
|
||
GetKcalGoalUsecase( | ||
this._userRepository, this._configRepository, this._userActivityRepository); | ||
|
||
Future<double> getKcalGoal( | ||
{UserEntity? userEntity, | ||
double? totalKcalActivitiesParam, | ||
double? kcalUserAdjustment}) async { | ||
final user = userEntity ?? await _userRepository.getUserData(); | ||
final config = await _configRepository.getConfig(); | ||
final totalKcalActivities = totalKcalActivitiesParam ?? | ||
(await _userActivityRepository.getAllUserActivityByDate(DateTime.now())) | ||
.map((activity) => activity.burnedKcal) | ||
.toList() | ||
.sum; | ||
return CalorieGoalCalc.getTotalKcalGoal(user, totalKcalActivities, | ||
kcalUserAdjustment: config.userKcalAdjustment); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:opennutritracker/core/data/repository/config_repository.dart'; | ||
import 'package:opennutritracker/core/utils/calc/macro_calc.dart'; | ||
|
||
class GetMacroGoalUsecase { | ||
final ConfigRepository _configRepository; | ||
|
||
GetMacroGoalUsecase(this._configRepository); | ||
|
||
Future<double> getCarbsGoal(double totalCalorieGoal) async { | ||
final config = await _configRepository.getConfig(); | ||
final userCarbGoal = config.userCarbGoalPct; | ||
|
||
return MacroCalc.getTotalCarbsGoal(totalCalorieGoal, | ||
userCarbsGoal: userCarbGoal); | ||
} | ||
|
||
Future<double> getFatsGoal(double totalCalorieGoal) async { | ||
final config = await _configRepository.getConfig(); | ||
final userFatGoal = config.userFatGoalPct; | ||
|
||
return MacroCalc.getTotalFatsGoal(totalCalorieGoal, | ||
userFatsGoal: userFatGoal); | ||
} | ||
|
||
Future<double> getProteinsGoal(double totalCalorieGoal) async { | ||
final config = await _configRepository.getConfig(); | ||
final userProteinGoal = config.userProteinGoalPct; | ||
|
||
return MacroCalc.getTotalProteinsGoal(totalCalorieGoal, | ||
userProteinsGoal: userProteinGoal); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.