Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/models/nutrition/log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class Log {
@JsonKey(required: true)
int? id;

@JsonKey(required: false, name: 'meal')
int mealId;

@JsonKey(required: true, name: 'plan')
int planId;

Expand All @@ -56,6 +59,7 @@ class Log {

Log({
this.id,
required this.mealId,
required this.ingredientId,
required this.weightUnitId,
required this.amount,
Expand All @@ -64,7 +68,7 @@ class Log {
this.comment,
});

Log.fromMealItem(MealItem mealItem, this.planId, [DateTime? dateTime]) {
Log.fromMealItem(MealItem mealItem, this.planId, this.mealId, [DateTime? dateTime]) {
ingredientId = mealItem.ingredientId;
ingredientObj = mealItem.ingredientObj;
weightUnitId = mealItem.weightUnitId;
Expand Down
4 changes: 3 additions & 1 deletion lib/models/nutrition/log.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/providers/nutrition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class NutritionPlansProvider extends WgerBaseProvider with ChangeNotifier {
Future<void> logMealToDiary(Meal meal) async {
for (final item in meal.mealItems) {
final plan = findById(meal.planId);
final Log log = Log.fromMealItem(item, plan.id!);
final Log log = Log.fromMealItem(item, plan.id!, meal.id!);

final data = await post(log.toJson(), makeUrl(_nutritionDiaryPath));
log.id = data['id'];
Expand Down
6 changes: 3 additions & 3 deletions test_data/nutritional_plans.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ NutritionalPlan getNutritionalPlan() {
plan.meals = [meal1, meal2];

// Add logs
plan.logs.add(Log.fromMealItem(mealItem1, 1, DateTime(2021, 6, 1)));
plan.logs.add(Log.fromMealItem(mealItem2, 1, DateTime(2021, 6, 1)));
plan.logs.add(Log.fromMealItem(mealItem3, 1, DateTime(2021, 6, 10)));
plan.logs.add(Log.fromMealItem(mealItem1, 1,1, DateTime(2021, 6, 1)));
plan.logs.add(Log.fromMealItem(mealItem2, 1,1, DateTime(2021, 6, 1)));
plan.logs.add(Log.fromMealItem(mealItem3, 1,1, DateTime(2021, 6, 10)));

return plan;
}