From 40dbe842cdc7ce160a2c78b84c4f8c07308462ad Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Mon, 13 Apr 2026 12:58:17 +0200 Subject: [PATCH 1/3] Move the variation to a field in the exercise --- lib/database/exercises/exercise_database.dart | 20 +- lib/database/exercises/type_converters.dart | 15 - lib/models/exercises/exercise.dart | 8 +- lib/models/exercises/exercise.g.dart | 6 +- lib/models/exercises/exercise_api.dart | 2 +- .../exercises/exercise_api.freezed.dart | 46 +- lib/models/exercises/exercise_api.g.dart | 4 +- lib/models/exercises/exercise_submission.dart | 2 +- .../exercise_submission.freezed.dart | 46 +- .../exercises/exercise_submission.g.dart | 4 +- lib/models/exercises/variation.dart | 33 -- lib/models/exercises/variation.g.dart | 16 - lib/providers/add_exercise.dart | 35 +- lib/providers/exercises.dart | 18 +- ...trition_ingredient_filters_riverpod.g.dart | 2 +- .../add_exercise/steps/step_2_variations.dart | 6 +- .../add_exercise/steps/step_6_overview.dart | 4 +- lib/widgets/exercises/exercises.dart | 6 +- test/core/settings_test.mocks.dart | 14 +- test/core/validators_test.mocks.dart | 99 ++++ .../contribute_exercise_image_test.mocks.dart | 185 +++---- test/exercises/contribute_exercise_test.dart | 2 +- .../contribute_exercise_test.mocks.dart | 497 +++++++++--------- .../exercises_detail_widget_test.dart | 2 +- .../exercises_detail_widget_test.mocks.dart | 14 +- test/exercises/model_exercise_test.dart | 2 +- .../exercises/exerciseinfo_response.json | 2 +- .../nutritional_plan_screen_test.mocks.dart | 8 + .../nutritional_plans_screen_test.mocks.dart | 8 + test/routine/gym_mode/gym_mode_test.dart | 2 +- .../routine/gym_mode/gym_mode_test.mocks.dart | 14 +- .../routine/routines_provider_test.mocks.dart | 14 +- .../gym_mode/log_page_test.mocks.dart | 14 +- 33 files changed, 603 insertions(+), 547 deletions(-) delete mode 100644 lib/models/exercises/variation.dart delete mode 100644 lib/models/exercises/variation.g.dart diff --git a/lib/database/exercises/exercise_database.dart b/lib/database/exercises/exercise_database.dart index 826935ff4..1cbff2113 100644 --- a/lib/database/exercises/exercise_database.dart +++ b/lib/database/exercises/exercise_database.dart @@ -1,3 +1,21 @@ +/* + * This file is part of wger Workout Manager . + * Copyright (c) 2026 wger Team + * + * wger Workout Manager is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + import 'package:drift/drift.dart'; import 'package:drift_flutter/drift_flutter.dart'; import 'package:logging/logging.dart'; @@ -74,7 +92,7 @@ class ExerciseDatabase extends _$ExerciseDatabase { /// Note that this needs to be bumped if the JSON response from the server changes @override - int get schemaVersion => 3; + int get schemaVersion => 4; /// There is not really a migration strategy. If we bump the version /// number, delete everything and recreate the new tables. The provider diff --git a/lib/database/exercises/type_converters.dart b/lib/database/exercises/type_converters.dart index 77d54559f..755a628b6 100644 --- a/lib/database/exercises/type_converters.dart +++ b/lib/database/exercises/type_converters.dart @@ -5,7 +5,6 @@ import 'package:wger/models/exercises/category.dart'; import 'package:wger/models/exercises/equipment.dart'; import 'package:wger/models/exercises/language.dart'; import 'package:wger/models/exercises/muscle.dart'; -import 'package:wger/models/exercises/variation.dart'; class MuscleConverter extends TypeConverter { const MuscleConverter(); @@ -62,17 +61,3 @@ class LanguageConverter extends TypeConverter { return json.encode(value.toJson()); } } - -class VariationConverter extends TypeConverter { - const VariationConverter(); - - @override - Variation fromSql(String fromDb) { - return Variation.fromJson(json.decode(fromDb) as Map); - } - - @override - String toSql(Variation value) { - return json.encode(value.toJson()); - } -} diff --git a/lib/models/exercises/exercise.dart b/lib/models/exercises/exercise.dart index dca5341d0..4ea6f774b 100644 --- a/lib/models/exercises/exercise.dart +++ b/lib/models/exercises/exercise.dart @@ -43,8 +43,8 @@ class Exercise extends Equatable { @JsonKey(required: true) late final String? uuid; - @JsonKey(required: true, name: 'variations') - late final int? variationId; + @JsonKey(required: true, name: 'variation_group') + late final String? variationGroup; @JsonKey(required: true, name: 'created') late final DateTime? created; @@ -100,7 +100,7 @@ class Exercise extends Equatable { this.created, this.lastUpdate, this.lastUpdateGlobal, - this.variationId, + this.variationGroup, List? muscles, List? musclesSecondary, List? equipment, @@ -184,7 +184,7 @@ class Exercise extends Equatable { authors = exerciseData.authors; authorsGlobal = exerciseData.authorsGlobal; - variationId = exerciseData.variationId; + variationGroup = exerciseData.variationGroup; } /// Returns translation for the given language diff --git a/lib/models/exercises/exercise.g.dart b/lib/models/exercises/exercise.g.dart index 83ae0b819..aa68369ca 100644 --- a/lib/models/exercises/exercise.g.dart +++ b/lib/models/exercises/exercise.g.dart @@ -12,7 +12,7 @@ Exercise _$ExerciseFromJson(Map json) { requiredKeys: const [ 'id', 'uuid', - 'variations', + 'variation_group', 'created', 'last_update', 'last_update_global', @@ -32,7 +32,7 @@ Exercise _$ExerciseFromJson(Map json) { lastUpdateGlobal: json['last_update_global'] == null ? null : DateTime.parse(json['last_update_global'] as String), - variationId: (json['variations'] as num?)?.toInt(), + variationGroup: json['variation_group'] as String?, translations: (json['translations'] as List?) ?.map((e) => Translation.fromJson(e as Map)) .toList(), @@ -53,7 +53,7 @@ Exercise _$ExerciseFromJson(Map json) { Map _$ExerciseToJson(Exercise instance) => { 'id': instance.id, 'uuid': instance.uuid, - 'variations': instance.variationId, + 'variation_group': instance.variationGroup, 'created': instance.created?.toIso8601String(), 'last_update': instance.lastUpdate?.toIso8601String(), 'last_update_global': instance.lastUpdateGlobal?.toIso8601String(), diff --git a/lib/models/exercises/exercise_api.dart b/lib/models/exercises/exercise_api.dart index b89eafc19..607a1483e 100644 --- a/lib/models/exercises/exercise_api.dart +++ b/lib/models/exercises/exercise_api.dart @@ -21,7 +21,7 @@ sealed class ExerciseApiData with _$ExerciseApiData { required int id, required String uuid, // ignore: invalid_annotation_target - @Default(null) @JsonKey(name: 'variations') int? variationId, + @Default(null) @JsonKey(name: 'variation_group') String? variationGroup, // ignore: invalid_annotation_target @JsonKey(name: 'created') required DateTime created, // ignore: invalid_annotation_target diff --git a/lib/models/exercises/exercise_api.freezed.dart b/lib/models/exercises/exercise_api.freezed.dart index cea2c699a..4ed8caa0d 100644 --- a/lib/models/exercises/exercise_api.freezed.dart +++ b/lib/models/exercises/exercise_api.freezed.dart @@ -23,7 +23,7 @@ ExerciseApiData _$ExerciseApiDataFromJson( mixin _$ExerciseApiData { int get id; String get uuid;// ignore: invalid_annotation_target -@JsonKey(name: 'variations') int? get variationId;// ignore: invalid_annotation_target +@JsonKey(name: 'variation_group') String? get variationGroup;// ignore: invalid_annotation_target @JsonKey(name: 'created') DateTime get created;// ignore: invalid_annotation_target @JsonKey(name: 'last_update') DateTime get lastUpdate;// ignore: invalid_annotation_target @JsonKey(name: 'last_update_global') DateTime get lastUpdateGlobal; ExerciseCategory get category; List get muscles;// ignore: invalid_annotation_target @@ -44,16 +44,16 @@ $ExerciseApiDataCopyWith get copyWith => _$ExerciseApiDataCopyW @override bool operator ==(Object other) { - return identical(this, other) || (other.runtimeType == runtimeType&&other is ExerciseApiData&&(identical(other.id, id) || other.id == id)&&(identical(other.uuid, uuid) || other.uuid == uuid)&&(identical(other.variationId, variationId) || other.variationId == variationId)&&(identical(other.created, created) || other.created == created)&&(identical(other.lastUpdate, lastUpdate) || other.lastUpdate == lastUpdate)&&(identical(other.lastUpdateGlobal, lastUpdateGlobal) || other.lastUpdateGlobal == lastUpdateGlobal)&&(identical(other.category, category) || other.category == category)&&const DeepCollectionEquality().equals(other.muscles, muscles)&&const DeepCollectionEquality().equals(other.musclesSecondary, musclesSecondary)&&const DeepCollectionEquality().equals(other.equipment, equipment)&&const DeepCollectionEquality().equals(other.translations, translations)&&const DeepCollectionEquality().equals(other.images, images)&&const DeepCollectionEquality().equals(other.videos, videos)&&const DeepCollectionEquality().equals(other.authors, authors)&&const DeepCollectionEquality().equals(other.authorsGlobal, authorsGlobal)); + return identical(this, other) || (other.runtimeType == runtimeType&&other is ExerciseApiData&&(identical(other.id, id) || other.id == id)&&(identical(other.uuid, uuid) || other.uuid == uuid)&&(identical(other.variationGroup, variationGroup) || other.variationGroup == variationGroup)&&(identical(other.created, created) || other.created == created)&&(identical(other.lastUpdate, lastUpdate) || other.lastUpdate == lastUpdate)&&(identical(other.lastUpdateGlobal, lastUpdateGlobal) || other.lastUpdateGlobal == lastUpdateGlobal)&&(identical(other.category, category) || other.category == category)&&const DeepCollectionEquality().equals(other.muscles, muscles)&&const DeepCollectionEquality().equals(other.musclesSecondary, musclesSecondary)&&const DeepCollectionEquality().equals(other.equipment, equipment)&&const DeepCollectionEquality().equals(other.translations, translations)&&const DeepCollectionEquality().equals(other.images, images)&&const DeepCollectionEquality().equals(other.videos, videos)&&const DeepCollectionEquality().equals(other.authors, authors)&&const DeepCollectionEquality().equals(other.authorsGlobal, authorsGlobal)); } @JsonKey(includeFromJson: false, includeToJson: false) @override -int get hashCode => Object.hash(runtimeType,id,uuid,variationId,created,lastUpdate,lastUpdateGlobal,category,const DeepCollectionEquality().hash(muscles),const DeepCollectionEquality().hash(musclesSecondary),const DeepCollectionEquality().hash(equipment),const DeepCollectionEquality().hash(translations),const DeepCollectionEquality().hash(images),const DeepCollectionEquality().hash(videos),const DeepCollectionEquality().hash(authors),const DeepCollectionEquality().hash(authorsGlobal)); +int get hashCode => Object.hash(runtimeType,id,uuid,variationGroup,created,lastUpdate,lastUpdateGlobal,category,const DeepCollectionEquality().hash(muscles),const DeepCollectionEquality().hash(musclesSecondary),const DeepCollectionEquality().hash(equipment),const DeepCollectionEquality().hash(translations),const DeepCollectionEquality().hash(images),const DeepCollectionEquality().hash(videos),const DeepCollectionEquality().hash(authors),const DeepCollectionEquality().hash(authorsGlobal)); @override String toString() { - return 'ExerciseApiData(id: $id, uuid: $uuid, variationId: $variationId, created: $created, lastUpdate: $lastUpdate, lastUpdateGlobal: $lastUpdateGlobal, category: $category, muscles: $muscles, musclesSecondary: $musclesSecondary, equipment: $equipment, translations: $translations, images: $images, videos: $videos, authors: $authors, authorsGlobal: $authorsGlobal)'; + return 'ExerciseApiData(id: $id, uuid: $uuid, variationGroup: $variationGroup, created: $created, lastUpdate: $lastUpdate, lastUpdateGlobal: $lastUpdateGlobal, category: $category, muscles: $muscles, musclesSecondary: $musclesSecondary, equipment: $equipment, translations: $translations, images: $images, videos: $videos, authors: $authors, authorsGlobal: $authorsGlobal)'; } @@ -64,7 +64,7 @@ abstract mixin class $ExerciseApiDataCopyWith<$Res> { factory $ExerciseApiDataCopyWith(ExerciseApiData value, $Res Function(ExerciseApiData) _then) = _$ExerciseApiDataCopyWithImpl; @useResult $Res call({ - int id, String uuid,@JsonKey(name: 'variations') int? variationId,@JsonKey(name: 'created') DateTime created,@JsonKey(name: 'last_update') DateTime lastUpdate,@JsonKey(name: 'last_update_global') DateTime lastUpdateGlobal, ExerciseCategory category, List muscles,@JsonKey(name: 'muscles_secondary') List musclesSecondary, List equipment,@JsonKey(name: 'translations', defaultValue: []) List translations, List images, List