diff --git a/lib/helpers/consts.dart b/lib/helpers/consts.dart index 2b2ebc7e..6482ec3a 100644 --- a/lib/helpers/consts.dart +++ b/lib/helpers/consts.dart @@ -109,7 +109,7 @@ enum EXERCISE_IMAGE_ART_STYLE { } /// Dummy ID for pseudo meals -const PSEUDO_MEAL_ID = -1; +const PSEUDO_MEAL_ID = 'deadbeef'; /// Colors used for muscles const COLOR_MAIN_MUSCLES = Colors.red; diff --git a/lib/models/nutrition/log.dart b/lib/models/nutrition/log.dart index 0d3a61a6..362edf05 100644 --- a/lib/models/nutrition/log.dart +++ b/lib/models/nutrition/log.dart @@ -17,6 +17,7 @@ */ import 'package:json_annotation/json_annotation.dart'; +import 'package:powersync/powersync.dart'; import 'package:powersync/sqlite3.dart' as sqlite; import 'package:wger/helpers/json.dart'; import 'package:wger/models/nutrition/ingredient.dart'; @@ -25,20 +26,19 @@ import 'package:wger/models/nutrition/meal_item.dart'; import 'package:wger/models/nutrition/nutritional_values.dart'; import 'package:wger/models/schema.dart'; import 'package:wger/powersync.dart'; -import 'package:wger/providers/nutrition.dart'; part 'log.g.dart'; @JsonSerializable() class Log { @JsonKey(required: true) - int? id; + String? id; @JsonKey(required: false, name: 'meal') - int? mealId; + String? mealId; @JsonKey(required: true, name: 'plan') - int planId; + String planId; @JsonKey(required: true) late DateTime datetime; @@ -81,7 +81,7 @@ class Log { factory Log.fromRow(sqlite.Row row) { return Log( - id: int.parse(row['id']), + id: row['id'], mealId: row['meal_id'], ingredientId: row['ingredient_id'], weightUnitId: row['weight_unit_id'], @@ -107,12 +107,12 @@ class Log { return ingredient.nutritionalValues / (100 / weight); } - static Future> readByMealId(int mealId) async { + static Future> readByMealId(String mealId) async { final results = await db.getAll('SELECT * FROM $tableLogItems WHERE meal_id = ?', [mealId]); return results.map((r) => Log.fromRow(r)).toList(); } - static Future> readByPlanId(int planId) async { + static Future> readByPlanId(String planId) async { final results = await db.getAll('SELECT * FROM $tableLogItems WHERE plan_id = ?', [planId]); return results.map((r) => Log.fromRow(r)).toList(); } @@ -121,10 +121,23 @@ class Log { Future delete() async { await db.execute('DELETE FROM $logItemsTable WHERE id = ?', [id]); } + */ - static Future addPhoto(String photoId, String id) async { - await db.execute('UPDATE $logItemsTable SET photo_id = ? WHERE id = ?', [photoId, id]); + Future log() async { + print('DIETER Log.log called id=$id, planId=$planId'); + await db.execute( + 'INSERT INTO $tableLogItems (id, meal_id, ingredient_id, weight_unit_id, amount, plan_id, datetime, comment) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', + [ + // generate an id using uuid + uuid.v4(), + mealId, + ingredientId, + weightUnitId, + amount, + planId, + datetime.toIso8601String(), + comment, + ], + ); } -} - */ } diff --git a/lib/models/nutrition/log.g.dart b/lib/models/nutrition/log.g.dart index 72e0a6ae..11e5eb54 100644 --- a/lib/models/nutrition/log.g.dart +++ b/lib/models/nutrition/log.g.dart @@ -19,12 +19,12 @@ Log _$LogFromJson(Map json) { ], ); return Log( - id: (json['id'] as num?)?.toInt(), - mealId: (json['meal'] as num?)?.toInt(), + id: json['id'] as String?, + mealId: json['meal'] as String?, ingredientId: (json['ingredient'] as num).toInt(), weightUnitId: (json['weight_unit'] as num?)?.toInt(), amount: stringToNum(json['amount'] as String?), - planId: (json['plan'] as num).toInt(), + planId: json['plan'] as String, datetime: DateTime.parse(json['datetime'] as String), comment: json['comment'] as String?, ); diff --git a/lib/models/nutrition/meal.dart b/lib/models/nutrition/meal.dart index 3057220b..10b6109c 100644 --- a/lib/models/nutrition/meal.dart +++ b/lib/models/nutrition/meal.dart @@ -33,10 +33,10 @@ part 'meal.g.dart'; @JsonSerializable() class Meal { @JsonKey(required: false) - late int? id; + late String? id; @JsonKey(name: 'plan') - late int planId; + late String planId; @JsonKey(toJson: timeToString, fromJson: stringToTime) TimeOfDay? time; @@ -55,7 +55,7 @@ class Meal { Meal({ this.id, - int? plan, + String? plan, this.time, String? name, List? mealItems, @@ -92,7 +92,7 @@ class Meal { factory Meal.fromRow(sqlite.Row row) { return Meal( - id: int.parse(row['id']), + id: row['id'], plan: row['plan_id'], time: stringToTime(row['time']), name: row['name'], @@ -102,8 +102,8 @@ class Meal { Map toJson() => _$MealToJson(this); Meal copyWith({ - int? id, - int? plan, + String? id, + String? plan, TimeOfDay? time, String? name, List? mealItems, @@ -127,12 +127,12 @@ class Meal { ); } - static Future read(int id) async { + static Future read(String id) async { final results = await db.get('SELECT * FROM $tableMeals WHERE id = ?', [id]); return Meal.fromRow(results); } - static Future> readByPlanId(int planId) async { + static Future> readByPlanId(String planId) async { print('Meal.readByPlanId: SELECT * FROM $tableMeals WHERE plan_id = $planId'); final results = await db.getAll('SELECT * FROM $tableMeals WHERE plan_id = ?', [planId]); print(results.rows.length); diff --git a/lib/models/nutrition/meal.g.dart b/lib/models/nutrition/meal.g.dart index 2258775c..187537b4 100644 --- a/lib/models/nutrition/meal.g.dart +++ b/lib/models/nutrition/meal.g.dart @@ -7,10 +7,10 @@ part of 'meal.dart'; // ************************************************************************** Meal _$MealFromJson(Map json) => Meal( - id: (json['id'] as num?)?.toInt(), + id: json['id'] as String?, time: stringToTime(json['time'] as String?), name: json['name'] as String?, - )..planId = (json['plan'] as num).toInt(); + )..planId = json['plan'] as String; Map _$MealToJson(Meal instance) => { 'id': instance.id, diff --git a/lib/models/nutrition/meal_item.dart b/lib/models/nutrition/meal_item.dart index 811f86e9..e740d4c2 100644 --- a/lib/models/nutrition/meal_item.dart +++ b/lib/models/nutrition/meal_item.dart @@ -34,7 +34,7 @@ class MealItem { int? id; @JsonKey(required: false, name: 'meal') - late int mealId; + late String mealId; @JsonKey(required: false, name: 'ingredient') late int ingredientId; @@ -53,7 +53,7 @@ class MealItem { MealItem({ this.id, - int? mealId, + String? mealId, required this.ingredientId, this.weightUnitId, required this.amount, @@ -107,7 +107,7 @@ class MealItem { MealItem copyWith({ int? id, - int? mealId, + String? mealId, int? ingredientId, int? weightUnitId, num? amount, @@ -126,7 +126,7 @@ class MealItem { return m; } - static Future> readByMealId(int mealId) async { + static Future> readByMealId(String mealId) async { final results = await db.getAll('SELECT * FROM $tableMealItems WHERE meal_id = ?', [mealId]); return results.map((r) => MealItem.fromRow(r)).toList(); } diff --git a/lib/models/nutrition/meal_item.g.dart b/lib/models/nutrition/meal_item.g.dart index 256f9cce..e503d3fc 100644 --- a/lib/models/nutrition/meal_item.g.dart +++ b/lib/models/nutrition/meal_item.g.dart @@ -13,7 +13,7 @@ MealItem _$MealItemFromJson(Map json) { ); return MealItem( id: (json['id'] as num?)?.toInt(), - mealId: (json['meal'] as num?)?.toInt(), + mealId: json['meal'] as String?, ingredientId: (json['ingredient'] as num).toInt(), weightUnitId: (json['weight_unit'] as num?)?.toInt(), amount: stringToNum(json['amount'] as String?), diff --git a/lib/models/nutrition/nutritional_plan.dart b/lib/models/nutrition/nutritional_plan.dart index 213fdfd4..a8cbbef6 100644 --- a/lib/models/nutrition/nutritional_plan.dart +++ b/lib/models/nutrition/nutritional_plan.dart @@ -35,8 +35,8 @@ part 'nutritional_plan.g.dart'; @JsonSerializable(explicitToJson: true) class NutritionalPlan { - @JsonKey(required: true) - int? id; + @JsonKey(required: false) + String? id; @JsonKey(required: true) late String description; @@ -87,7 +87,7 @@ class NutritionalPlan { factory NutritionalPlan.fromRow(sqlite.Row row) { return NutritionalPlan( - id: int.parse(row['id']), + id: row['id'], description: row['description'], creationDate: DateTime.parse(row['creation_date']), onlyLogging: row['only_logging'] == 1, @@ -100,7 +100,7 @@ class NutritionalPlan { } NutritionalPlan copyWith({ - int? id, + String? id, String? description, DateTime? creationDate, bool? onlyLogging, @@ -299,7 +299,7 @@ class NutritionalPlan { ); } - static Future read(int id) async { + static Future read(String id) async { final row = await db.get('SELECT * FROM $tableNutritionPlans WHERE id = ?', [id]); return NutritionalPlan.fromRow(row).loadChildren(); } @@ -327,18 +327,21 @@ class NutritionalPlan { }); } - static Stream watchNutritionPlan(int id) { + static Stream watchNutritionPlan(String id) { return db.onChange([tableNutritionPlans, tableLogItems, tableMeals]).asyncMap((event) async { final row = await db.getOptional('SELECT * FROM $tableNutritionPlans WHERE id = ?', [id]); return row == null ? null : NutritionalPlan.fromRow(row).loadChildren(); }); } - static Stream watchNutritionPlanLast() { + static Stream watchNutritionPlanLast() { return db.onChange([tableNutritionPlans, tableLogItems, tableMeals]).asyncMap((event) async { - final row = - await db.get('SELECT * FROM $tableNutritionPlans ORDER BY creation_date DESC LIMIT 1'); - return NutritionalPlan.fromRow(row).loadChildren(); + final res = + await db.getAll('SELECT * FROM $tableNutritionPlans ORDER BY creation_date DESC LIMIT 1'); + if (res.isEmpty) { + return null; + } + return NutritionalPlan.fromRow(res.first).loadChildren(); }); } /* diff --git a/lib/models/nutrition/nutritional_plan.g.dart b/lib/models/nutrition/nutritional_plan.g.dart index b4a8bbe7..93445942 100644 --- a/lib/models/nutrition/nutritional_plan.g.dart +++ b/lib/models/nutrition/nutritional_plan.g.dart @@ -10,7 +10,6 @@ NutritionalPlan _$NutritionalPlanFromJson(Map json) { $checkKeys( json, requiredKeys: const [ - 'id', 'description', 'creation_date', 'only_logging', @@ -22,7 +21,7 @@ NutritionalPlan _$NutritionalPlanFromJson(Map json) { ], ); return NutritionalPlan( - id: (json['id'] as num?)?.toInt(), + id: json['id'] as String?, description: json['description'] as String, creationDate: DateTime.parse(json['creation_date'] as String), onlyLogging: json['only_logging'] as bool? ?? false, diff --git a/lib/models/schema.dart b/lib/models/schema.dart index 0b5b72c7..08ecd01b 100644 --- a/lib/models/schema.dart +++ b/lib/models/schema.dart @@ -33,6 +33,7 @@ Schema schema = const Schema([ Column.text('description'), Column.integer('has_goal_calories'), Column.integer('user_id'), + Column.integer('remote_id'), Column.integer('only_logging'), Column.integer('goal_carbohydrates'), Column.integer('goal_energy'), @@ -47,10 +48,11 @@ Schema schema = const Schema([ Column.text('datetime'), Column.text('comment'), Column.integer('amount'), + Column.integer('remote_id'), Column.integer('ingredient_id'), - Column.integer('plan_id'), + Column.text('plan_id'), Column.integer('weight_unit_id'), - Column.integer('meal_id'), // optional + Column.text('meal_id'), // optional ], indexes: [ // Index('plan', [IndexedColumn('plan_id')]) @@ -60,8 +62,9 @@ Schema schema = const Schema([ tableMeals, [ Column.integer('order'), + Column.integer('remote_id'), Column.text('time'), - Column.integer('plan_id'), + Column.text('plan_id'), Column.text('name'), ], ), @@ -71,7 +74,8 @@ Schema schema = const Schema([ Column.integer('order'), Column.integer('amount'), Column.integer('ingredient_id'), - Column.integer('meal_id'), + Column.text('meal_id'), + Column.integer('remote_id'), Column.integer('weight_unit_id'), ], ), diff --git a/lib/powersync.dart b/lib/powersync.dart index 4532ae0f..0a2122c9 100644 --- a/lib/powersync.dart +++ b/lib/powersync.dart @@ -60,6 +60,8 @@ class DjangoConnector extends PowerSyncBackendConnector { 'data': {'id': op.id, ...?op.opData}, }; + log.fine('DIETER Uploading record', record); + switch (op.op) { case UpdateType.put: await apiClient.upsert(record); diff --git a/lib/providers/nutrition.dart b/lib/providers/nutrition.dart index a092a663..62c8ef3f 100644 --- a/lib/providers/nutrition.dart +++ b/lib/providers/nutrition.dart @@ -74,13 +74,14 @@ class NutritionPlansProvider with ChangeNotifier { } return null; } - +/* NutritionalPlan findById(int id) { return _plans.firstWhere( (plan) => plan.id == id, orElse: () => throw const NoSuchEntryException(), ); } + Meal? findMealById(int id) { for (final plan in _plans) { @@ -91,6 +92,7 @@ class NutritionPlansProvider with ChangeNotifier { } return null; } + */ Future _enrichPlan(NutritionalPlan plan) async { // TODO: set up ingredient images @@ -119,7 +121,7 @@ class NutritionPlansProvider with ChangeNotifier { return plan; } - Stream watchNutritionPlan(int id) { + Stream watchNutritionPlan(String id) { return NutritionalPlan.watchNutritionPlan(id).transform( StreamTransformer.fromHandlers( handleData: (plan, sink) async { @@ -137,6 +139,9 @@ class NutritionPlansProvider with ChangeNotifier { return NutritionalPlan.watchNutritionPlanLast().transform( StreamTransformer.fromHandlers( handleData: (plan, sink) async { + if (plan == null) { + return; + } sink.add(await _enrichPlan(plan)); }, ), @@ -172,31 +177,16 @@ TODO implement: } Future editPlan(NutritionalPlan plan) async { - await baseProvider.patch( - plan.toJson(), - baseProvider.makeUrl(_nutritionalPlansPath, id: plan.id), - ); - notifyListeners(); +// TODO } - Future deletePlan(int id) async { - final existingPlanIndex = _plans.indexWhere((element) => element.id == id); - final existingPlan = _plans[existingPlanIndex]; - _plans.removeAt(existingPlanIndex); - notifyListeners(); - - final response = await baseProvider.deleteRequest(_nutritionalPlansPath, id); - - if (response.statusCode >= 400) { - _plans.insert(existingPlanIndex, existingPlan); - notifyListeners(); - throw WgerHttpException(response.body); - } - //existingPlan = null; + Future deletePlan(String id) async { +// TODO } /// Adds a meal to a plan - Future addMeal(Meal meal, int planId) async { + Future addMeal(Meal meal, String planId) async { + /* final plan = findById(planId); final data = await baseProvider.post( meal.toJson(), @@ -208,10 +198,13 @@ TODO implement: notifyListeners(); return meal; + */ + return meal; } /// Edits an existing meal Future editMeal(Meal meal) async { + /* final data = await baseProvider.patch( meal.toJson(), baseProvider.makeUrl(_mealPath, id: meal.id), @@ -219,11 +212,13 @@ TODO implement: meal = Meal.fromJson(data); notifyListeners(); + */ return meal; } /// Deletes a meal Future deleteMeal(Meal meal) async { + /* // Get the meal final plan = findById(meal.planId); final mealIndex = plan.meals.indexWhere((e) => e.id == meal.id); @@ -238,6 +233,8 @@ TODO implement: notifyListeners(); throw WgerHttpException(response.body); } + */ + return; } /// Adds a meal item to a meal @@ -257,6 +254,7 @@ TODO implement: /// Deletes a meal Future deleteMealItem(MealItem mealItem) async { + /* // Get the meal final meal = findMealById(mealItem.mealId)!; final mealItemIndex = meal.mealItems.indexWhere((e) => e.id == mealItem.id); @@ -271,6 +269,7 @@ TODO implement: notifyListeners(); throw WgerHttpException(response.body); } + */ } Future clearIngredientCache() async { @@ -380,6 +379,7 @@ TODO implement: /// Log meal to nutrition diary Future logMealToDiary(Meal meal) async { + /* for (final item in meal.mealItems) { final plan = findById(meal.planId); final Log log = Log.fromMealItem(item, plan.id!, meal.id); @@ -392,34 +392,29 @@ TODO implement: plan.diaryEntries.add(log); } notifyListeners(); + */ } /// Log custom ingredient to nutrition diary Future logIngredientToDiary( MealItem mealItem, - int planId, [ + String planId, [ DateTime? dateTime, - ]) async { - final plan = findById(planId); - mealItem.ingredient = await fetchIngredient(mealItem.ingredientId); - final Log log = Log.fromMealItem(mealItem, plan.id!, null, dateTime); - - final data = await baseProvider.post( - log.toJson(), - baseProvider.makeUrl(_nutritionDiaryPath), - ); - log.id = data['id']; - plan.diaryEntries.add(log); - notifyListeners(); + ]) { + print( + 'DIETER logIngredientToDiary called ingredient=${mealItem.ingredientId}, planId=$planId, dateTime=$dateTime'); + return Log.fromMealItem(mealItem, planId, null, dateTime).log(); } /// Deletes a log entry - Future deleteLog(int logId, int planId) async { + Future deleteLog(String logId, String planId) async { + /* await baseProvider.deleteRequest(_nutritionDiaryPath, logId); final plan = findById(planId); plan.diaryEntries.removeWhere((element) => element.id == logId); notifyListeners(); + */ } /// Load nutrition diary entries for plan diff --git a/lib/screens/nutritional_diary_screen.dart b/lib/screens/nutritional_diary_screen.dart index 1ea1c15c..72d97daf 100644 --- a/lib/screens/nutritional_diary_screen.dart +++ b/lib/screens/nutritional_diary_screen.dart @@ -28,7 +28,7 @@ import 'package:wger/widgets/nutrition/nutritional_diary_detail.dart'; /// Arguments passed to the form screen class NutritionalDiaryArguments { /// Nutritional plan - final int plan; + final String plan; /// Date to show data for final DateTime date; diff --git a/lib/screens/nutritional_plan_screen.dart b/lib/screens/nutritional_plan_screen.dart index 6201433d..4f1c5ec9 100644 --- a/lib/screens/nutritional_plan_screen.dart +++ b/lib/screens/nutritional_plan_screen.dart @@ -49,7 +49,7 @@ class _NutritionalPlanScreenState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); - final id = ModalRoute.of(context)!.settings.arguments as int; + final id = ModalRoute.of(context)!.settings.arguments as String; //final id = 111; final stream = diff --git a/lib/widgets/nutrition/forms.dart b/lib/widgets/nutrition/forms.dart index 785e9bac..faad4a6f 100644 --- a/lib/widgets/nutrition/forms.dart +++ b/lib/widgets/nutrition/forms.dart @@ -36,7 +36,7 @@ import 'package:wger/widgets/nutrition/widgets.dart'; class MealForm extends StatelessWidget { late final Meal _meal; - final int _planId; + final String _planId; final _form = GlobalKey(); final _timeController = TextEditingController(); @@ -128,7 +128,7 @@ Widget MealItemForm( ]) { return IngredientForm( // TODO we use planId 0 here cause we don't have one and we don't need it I think? - recent: recent.map((e) => Log.fromMealItem(e, 0, e.mealId)).toList(), + recent: recent.map((e) => Log.fromMealItem(e, "0", e.mealId)).toList(), onSave: (BuildContext context, MealItem mealItem, DateTime? dt) { mealItem.mealId = meal.id!; Provider.of(context, listen: false).addMealItem(mealItem, meal); diff --git a/test/core/settings_test.mocks.dart b/test/core/settings_test.mocks.dart index 30321609..5812e036 100644 --- a/test/core/settings_test.mocks.dart +++ b/test/core/settings_test.mocks.dart @@ -711,79 +711,34 @@ class MockNutritionPlansProvider extends _i1.Mock ); @override - _i10.NutritionalPlan findById(int? id) => (super.noSuchMethod( + _i15.Stream<_i10.NutritionalPlan?> watchNutritionPlan(String? id) => + (super.noSuchMethod( Invocation.method( - #findById, + #watchNutritionPlan, [id], ), - returnValue: _FakeNutritionalPlan_8( - this, - Invocation.method( - #findById, - [id], - ), - ), - ) as _i10.NutritionalPlan); - - @override - _i11.Meal? findMealById(int? id) => (super.noSuchMethod(Invocation.method( - #findMealById, - [id], - )) as _i11.Meal?); - - @override - _i15.Future fetchAndSetAllPlansSparse() => (super.noSuchMethod( - Invocation.method( - #fetchAndSetAllPlansSparse, - [], - ), - returnValue: _i15.Future.value(), - returnValueForMissingStub: _i15.Future.value(), - ) as _i15.Future); - - @override - _i15.Future fetchAndSetAllPlansFull() => (super.noSuchMethod( - Invocation.method( - #fetchAndSetAllPlansFull, - [], - ), - returnValue: _i15.Future.value(), - returnValueForMissingStub: _i15.Future.value(), - ) as _i15.Future); + returnValue: _i15.Stream<_i10.NutritionalPlan?>.empty(), + ) as _i15.Stream<_i10.NutritionalPlan?>); @override - _i15.Future<_i10.NutritionalPlan> fetchAndSetPlanSparse(int? planId) => + _i15.Stream<_i10.NutritionalPlan> watchNutritionPlanLast() => (super.noSuchMethod( Invocation.method( - #fetchAndSetPlanSparse, - [planId], + #watchNutritionPlanLast, + [], ), - returnValue: - _i15.Future<_i10.NutritionalPlan>.value(_FakeNutritionalPlan_8( - this, - Invocation.method( - #fetchAndSetPlanSparse, - [planId], - ), - )), - ) as _i15.Future<_i10.NutritionalPlan>); + returnValue: _i15.Stream<_i10.NutritionalPlan>.empty(), + ) as _i15.Stream<_i10.NutritionalPlan>); @override - _i15.Future<_i10.NutritionalPlan> fetchAndSetPlanFull(int? planId) => + _i15.Stream> watchNutritionPlans() => (super.noSuchMethod( Invocation.method( - #fetchAndSetPlanFull, - [planId], + #watchNutritionPlans, + [], ), - returnValue: - _i15.Future<_i10.NutritionalPlan>.value(_FakeNutritionalPlan_8( - this, - Invocation.method( - #fetchAndSetPlanFull, - [planId], - ), - )), - ) as _i15.Future<_i10.NutritionalPlan>); + returnValue: _i15.Stream>.empty(), + ) as _i15.Stream>); @override _i15.Future<_i10.NutritionalPlan> addPlan(_i10.NutritionalPlan? planData) => @@ -813,7 +768,7 @@ class MockNutritionPlansProvider extends _i1.Mock ) as _i15.Future); @override - _i15.Future deletePlan(int? id) => (super.noSuchMethod( + _i15.Future deletePlan(String? id) => (super.noSuchMethod( Invocation.method( #deletePlan, [id], @@ -825,7 +780,7 @@ class MockNutritionPlansProvider extends _i1.Mock @override _i15.Future<_i11.Meal> addMeal( _i11.Meal? meal, - int? planId, + String? planId, ) => (super.noSuchMethod( Invocation.method( @@ -991,7 +946,7 @@ class MockNutritionPlansProvider extends _i1.Mock @override _i15.Future logIngredientToDiary( _i12.MealItem? mealItem, - int? planId, [ + String? planId, [ DateTime? dateTime, ]) => (super.noSuchMethod( @@ -1009,8 +964,8 @@ class MockNutritionPlansProvider extends _i1.Mock @override _i15.Future deleteLog( - int? logId, - int? planId, + String? logId, + String? planId, ) => (super.noSuchMethod( Invocation.method( diff --git a/test/nutrition/nutritional_meal_form_test.dart b/test/nutrition/nutritional_meal_form_test.dart index fdb781f6..a053b19f 100644 --- a/test/nutrition/nutritional_meal_form_test.dart +++ b/test/nutrition/nutritional_meal_form_test.dart @@ -60,7 +60,7 @@ void main() { localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, navigatorKey: key, - home: Scaffold(body: MealForm(1, meal)), + home: Scaffold(body: MealForm("1", meal)), routes: { NutritionalPlanScreen.routeName: (ctx) => const NutritionalPlanScreen(), }, diff --git a/test/nutrition/nutritional_meal_form_test.mocks.dart b/test/nutrition/nutritional_meal_form_test.mocks.dart index 3df6d7b2..08ce46e6 100644 --- a/test/nutrition/nutritional_meal_form_test.mocks.dart +++ b/test/nutrition/nutritional_meal_form_test.mocks.dart @@ -165,79 +165,34 @@ class MockNutritionPlansProvider extends _i1.Mock ); @override - _i4.NutritionalPlan findById(int? id) => (super.noSuchMethod( + _i9.Stream<_i4.NutritionalPlan?> watchNutritionPlan(String? id) => + (super.noSuchMethod( Invocation.method( - #findById, + #watchNutritionPlan, [id], ), - returnValue: _FakeNutritionalPlan_2( - this, - Invocation.method( - #findById, - [id], - ), - ), - ) as _i4.NutritionalPlan); - - @override - _i5.Meal? findMealById(int? id) => (super.noSuchMethod(Invocation.method( - #findMealById, - [id], - )) as _i5.Meal?); - - @override - _i9.Future fetchAndSetAllPlansSparse() => (super.noSuchMethod( - Invocation.method( - #fetchAndSetAllPlansSparse, - [], - ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i9.Stream<_i4.NutritionalPlan?>.empty(), + ) as _i9.Stream<_i4.NutritionalPlan?>); @override - _i9.Future fetchAndSetAllPlansFull() => (super.noSuchMethod( - Invocation.method( - #fetchAndSetAllPlansFull, - [], - ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); - - @override - _i9.Future<_i4.NutritionalPlan> fetchAndSetPlanSparse(int? planId) => + _i9.Stream<_i4.NutritionalPlan> watchNutritionPlanLast() => (super.noSuchMethod( Invocation.method( - #fetchAndSetPlanSparse, - [planId], + #watchNutritionPlanLast, + [], ), - returnValue: - _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2( - this, - Invocation.method( - #fetchAndSetPlanSparse, - [planId], - ), - )), - ) as _i9.Future<_i4.NutritionalPlan>); + returnValue: _i9.Stream<_i4.NutritionalPlan>.empty(), + ) as _i9.Stream<_i4.NutritionalPlan>); @override - _i9.Future<_i4.NutritionalPlan> fetchAndSetPlanFull(int? planId) => + _i9.Stream> watchNutritionPlans() => (super.noSuchMethod( Invocation.method( - #fetchAndSetPlanFull, - [planId], + #watchNutritionPlans, + [], ), - returnValue: - _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2( - this, - Invocation.method( - #fetchAndSetPlanFull, - [planId], - ), - )), - ) as _i9.Future<_i4.NutritionalPlan>); + returnValue: _i9.Stream>.empty(), + ) as _i9.Stream>); @override _i9.Future<_i4.NutritionalPlan> addPlan(_i4.NutritionalPlan? planData) => @@ -267,7 +222,7 @@ class MockNutritionPlansProvider extends _i1.Mock ) as _i9.Future); @override - _i9.Future deletePlan(int? id) => (super.noSuchMethod( + _i9.Future deletePlan(String? id) => (super.noSuchMethod( Invocation.method( #deletePlan, [id], @@ -279,7 +234,7 @@ class MockNutritionPlansProvider extends _i1.Mock @override _i9.Future<_i5.Meal> addMeal( _i5.Meal? meal, - int? planId, + String? planId, ) => (super.noSuchMethod( Invocation.method( @@ -445,7 +400,7 @@ class MockNutritionPlansProvider extends _i1.Mock @override _i9.Future logIngredientToDiary( _i6.MealItem? mealItem, - int? planId, [ + String? planId, [ DateTime? dateTime, ]) => (super.noSuchMethod( @@ -463,8 +418,8 @@ class MockNutritionPlansProvider extends _i1.Mock @override _i9.Future deleteLog( - int? logId, - int? planId, + String? logId, + String? planId, ) => (super.noSuchMethod( Invocation.method( diff --git a/test/nutrition/nutritional_plan_form_test.dart b/test/nutrition/nutritional_plan_form_test.dart index e366ef51..ce89c0fe 100644 --- a/test/nutrition/nutritional_plan_form_test.dart +++ b/test/nutrition/nutritional_plan_form_test.dart @@ -35,7 +35,7 @@ void main() { var mockNutrition = MockNutritionPlansProvider(); final plan1 = NutritionalPlan( - id: 1, + id: 'deadbeef', creationDate: DateTime(2021, 1, 1), description: 'test plan 1', ); diff --git a/test/nutrition/nutritional_plan_form_test.mocks.dart b/test/nutrition/nutritional_plan_form_test.mocks.dart index 3b48c530..735d1537 100644 --- a/test/nutrition/nutritional_plan_form_test.mocks.dart +++ b/test/nutrition/nutritional_plan_form_test.mocks.dart @@ -165,79 +165,34 @@ class MockNutritionPlansProvider extends _i1.Mock ); @override - _i4.NutritionalPlan findById(int? id) => (super.noSuchMethod( + _i9.Stream<_i4.NutritionalPlan?> watchNutritionPlan(String? id) => + (super.noSuchMethod( Invocation.method( - #findById, + #watchNutritionPlan, [id], ), - returnValue: _FakeNutritionalPlan_2( - this, - Invocation.method( - #findById, - [id], - ), - ), - ) as _i4.NutritionalPlan); - - @override - _i5.Meal? findMealById(int? id) => (super.noSuchMethod(Invocation.method( - #findMealById, - [id], - )) as _i5.Meal?); - - @override - _i9.Future fetchAndSetAllPlansSparse() => (super.noSuchMethod( - Invocation.method( - #fetchAndSetAllPlansSparse, - [], - ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i9.Stream<_i4.NutritionalPlan?>.empty(), + ) as _i9.Stream<_i4.NutritionalPlan?>); @override - _i9.Future fetchAndSetAllPlansFull() => (super.noSuchMethod( - Invocation.method( - #fetchAndSetAllPlansFull, - [], - ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); - - @override - _i9.Future<_i4.NutritionalPlan> fetchAndSetPlanSparse(int? planId) => + _i9.Stream<_i4.NutritionalPlan> watchNutritionPlanLast() => (super.noSuchMethod( Invocation.method( - #fetchAndSetPlanSparse, - [planId], + #watchNutritionPlanLast, + [], ), - returnValue: - _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2( - this, - Invocation.method( - #fetchAndSetPlanSparse, - [planId], - ), - )), - ) as _i9.Future<_i4.NutritionalPlan>); + returnValue: _i9.Stream<_i4.NutritionalPlan>.empty(), + ) as _i9.Stream<_i4.NutritionalPlan>); @override - _i9.Future<_i4.NutritionalPlan> fetchAndSetPlanFull(int? planId) => + _i9.Stream> watchNutritionPlans() => (super.noSuchMethod( Invocation.method( - #fetchAndSetPlanFull, - [planId], + #watchNutritionPlans, + [], ), - returnValue: - _i9.Future<_i4.NutritionalPlan>.value(_FakeNutritionalPlan_2( - this, - Invocation.method( - #fetchAndSetPlanFull, - [planId], - ), - )), - ) as _i9.Future<_i4.NutritionalPlan>); + returnValue: _i9.Stream>.empty(), + ) as _i9.Stream>); @override _i9.Future<_i4.NutritionalPlan> addPlan(_i4.NutritionalPlan? planData) => @@ -267,7 +222,7 @@ class MockNutritionPlansProvider extends _i1.Mock ) as _i9.Future); @override - _i9.Future deletePlan(int? id) => (super.noSuchMethod( + _i9.Future deletePlan(String? id) => (super.noSuchMethod( Invocation.method( #deletePlan, [id], @@ -279,7 +234,7 @@ class MockNutritionPlansProvider extends _i1.Mock @override _i9.Future<_i5.Meal> addMeal( _i5.Meal? meal, - int? planId, + String? planId, ) => (super.noSuchMethod( Invocation.method( @@ -445,7 +400,7 @@ class MockNutritionPlansProvider extends _i1.Mock @override _i9.Future logIngredientToDiary( _i6.MealItem? mealItem, - int? planId, [ + String? planId, [ DateTime? dateTime, ]) => (super.noSuchMethod( @@ -463,8 +418,8 @@ class MockNutritionPlansProvider extends _i1.Mock @override _i9.Future deleteLog( - int? logId, - int? planId, + String? logId, + String? planId, ) => (super.noSuchMethod( Invocation.method( diff --git a/test/nutrition/nutritional_plans_screen_test.dart b/test/nutrition/nutritional_plans_screen_test.dart index 5a60b250..eea8de89 100644 --- a/test/nutrition/nutritional_plans_screen_test.dart +++ b/test/nutrition/nutritional_plans_screen_test.dart @@ -67,12 +67,12 @@ void main() { mockBaseProvider, [ NutritionalPlan( - id: 1, + id: 'deadbeefa', description: 'test plan 1', creationDate: DateTime(2021, 01, 01), ), NutritionalPlan( - id: 2, + id: 'deadbeefb', description: 'test plan 2', creationDate: DateTime(2021, 01, 10), ), diff --git a/test_data/nutritional_plans.dart b/test_data/nutritional_plans.dart index 1b3a42cc..9a202bc4 100644 --- a/test_data/nutritional_plans.dart +++ b/test_data/nutritional_plans.dart @@ -156,32 +156,32 @@ NutritionalPlan getNutritionalPlan() { mealItem3.ingredient = ingredient3; final meal1 = Meal( - id: 1, - plan: 1, + id: 'deadbeefa', + plan: '1', time: const TimeOfDay(hour: 17, minute: 0), name: 'Initial Name 1', ); meal1.mealItems = [mealItem1, mealItem2]; final meal2 = Meal( - id: 2, - plan: 1, + id: 'deadbeefb', + plan: '1', time: const TimeOfDay(hour: 22, minute: 5), name: 'Initial Name 2', ); meal2.mealItems = [mealItem3]; final NutritionalPlan plan = NutritionalPlan( - id: 1, + id: 'deadbeefc', description: 'Less fat, more protein', creationDate: DateTime(2021, 5, 23), ); plan.meals = [meal1, meal2]; // Add logs - plan.diaryEntries.add(Log.fromMealItem(mealItem1, 1, 1, DateTime(2021, 6, 1))); - plan.diaryEntries.add(Log.fromMealItem(mealItem2, 1, 1, DateTime(2021, 6, 1))); - plan.diaryEntries.add(Log.fromMealItem(mealItem3, 1, 1, DateTime(2021, 6, 10))); + plan.diaryEntries.add(Log.fromMealItem(mealItem1, '1', '1', DateTime(2021, 6, 1))); + plan.diaryEntries.add(Log.fromMealItem(mealItem2, '1', '1', DateTime(2021, 6, 1))); + plan.diaryEntries.add(Log.fromMealItem(mealItem3, '1', '1', DateTime(2021, 6, 10))); return plan; } @@ -194,32 +194,32 @@ NutritionalPlan getNutritionalPlanScreenshot() { final mealItem3 = MealItem(ingredientId: 3, amount: 100, ingredient: apple); final meal1 = Meal( - id: 1, - plan: 1, + id: 'deadbeefa', + plan: '1', time: const TimeOfDay(hour: 8, minute: 30), name: 'Breakfast', mealItems: [mealItem1, mealItem2], ); final meal2 = Meal( - id: 2, - plan: 1, + id: 'deadbeefb', + plan: '1', time: const TimeOfDay(hour: 11, minute: 0), name: 'Snack 1', mealItems: [mealItem3], ); final NutritionalPlan plan = NutritionalPlan( - id: 1, + id: '1', description: 'Diet', creationDate: DateTime(2021, 5, 23), meals: [meal1, meal2], ); // Add logs - plan.diaryEntries.add(Log.fromMealItem(mealItem1, 1, 1, DateTime.now())); - plan.diaryEntries.add(Log.fromMealItem(mealItem2, 1, 1, DateTime.now())); - plan.diaryEntries.add(Log.fromMealItem(mealItem3, 1, 1, DateTime.now())); + plan.diaryEntries.add(Log.fromMealItem(mealItem1, '1', '1', DateTime.now())); + plan.diaryEntries.add(Log.fromMealItem(mealItem2, '1', '1', DateTime.now())); + plan.diaryEntries.add(Log.fromMealItem(mealItem3, '1', '1', DateTime.now())); for (final i in plan.diaryEntries) { i.datetime = DateTime.now();