Replace exercise search API

We can now use the regular `exerciseinfo` endpoint, which returns regular exercise
responses instead of the old custom `exercise/search`
This commit is contained in:
Roland Geider
2026-03-03 21:54:43 +01:00
parent ae89b5c6ea
commit c8e2738501
8 changed files with 222 additions and 950 deletions

View File

@@ -1,3 +1,21 @@
/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* 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 <http://www.gnu.org/licenses/>.
*/
import 'dart:convert';
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -48,44 +66,3 @@ sealed class ExerciseApiData with _$ExerciseApiData {
factory ExerciseApiData.fromJson(Map<String, dynamic> json) => _$ExerciseApiDataFromJson(json);
}
/// Model for the search results returned from the /api/v2/exercise/search endpoint
///
@freezed
sealed class ExerciseSearchDetails with _$ExerciseSearchDetails {
factory ExerciseSearchDetails({
// ignore: invalid_annotation_target
@JsonKey(name: 'id') required int translationId,
// ignore: invalid_annotation_target
@JsonKey(name: 'base_id') required int exerciseId,
required String name,
required String category,
required String? image,
// ignore: invalid_annotation_target
@JsonKey(name: 'image_thumbnail') required String? imageThumbnail,
}) = _ExerciseSearchDetails;
factory ExerciseSearchDetails.fromJson(Map<String, dynamic> json) =>
_$ExerciseSearchDetailsFromJson(json);
}
@freezed
sealed class ExerciseSearchEntry with _$ExerciseSearchEntry {
factory ExerciseSearchEntry({
required String value,
required ExerciseSearchDetails data,
}) = _ExerciseSearchEntry;
factory ExerciseSearchEntry.fromJson(Map<String, dynamic> json) =>
_$ExerciseSearchEntryFromJson(json);
}
@freezed
sealed class ExerciseApiSearch with _$ExerciseApiSearch {
factory ExerciseApiSearch({
required List<ExerciseSearchEntry> suggestions,
}) = _ExerciseApiSearch;
factory ExerciseApiSearch.fromJson(Map<String, dynamic> json) =>
_$ExerciseApiSearchFromJson(json);
}

View File

@@ -1,3 +1,21 @@
/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* 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 <http://www.gnu.org/licenses/>.
*/
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// ignore_for_file: type=lint
@@ -386,825 +404,6 @@ as List<String>,
}
}
/// @nodoc
mixin _$ExerciseSearchDetails {
// ignore: invalid_annotation_target
@JsonKey(name: 'id') int get translationId;// ignore: invalid_annotation_target
@JsonKey(name: 'base_id') int get exerciseId; String get name; String get category; String? get image;// ignore: invalid_annotation_target
@JsonKey(name: 'image_thumbnail') String? get imageThumbnail;
/// Create a copy of ExerciseSearchDetails
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$ExerciseSearchDetailsCopyWith<ExerciseSearchDetails> get copyWith => _$ExerciseSearchDetailsCopyWithImpl<ExerciseSearchDetails>(this as ExerciseSearchDetails, _$identity);
/// Serializes this ExerciseSearchDetails to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is ExerciseSearchDetails&&(identical(other.translationId, translationId) || other.translationId == translationId)&&(identical(other.exerciseId, exerciseId) || other.exerciseId == exerciseId)&&(identical(other.name, name) || other.name == name)&&(identical(other.category, category) || other.category == category)&&(identical(other.image, image) || other.image == image)&&(identical(other.imageThumbnail, imageThumbnail) || other.imageThumbnail == imageThumbnail));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,translationId,exerciseId,name,category,image,imageThumbnail);
@override
String toString() {
return 'ExerciseSearchDetails(translationId: $translationId, exerciseId: $exerciseId, name: $name, category: $category, image: $image, imageThumbnail: $imageThumbnail)';
}
}
/// @nodoc
abstract mixin class $ExerciseSearchDetailsCopyWith<$Res> {
factory $ExerciseSearchDetailsCopyWith(ExerciseSearchDetails value, $Res Function(ExerciseSearchDetails) _then) = _$ExerciseSearchDetailsCopyWithImpl;
@useResult
$Res call({
@JsonKey(name: 'id') int translationId,@JsonKey(name: 'base_id') int exerciseId, String name, String category, String? image,@JsonKey(name: 'image_thumbnail') String? imageThumbnail
});
}
/// @nodoc
class _$ExerciseSearchDetailsCopyWithImpl<$Res>
implements $ExerciseSearchDetailsCopyWith<$Res> {
_$ExerciseSearchDetailsCopyWithImpl(this._self, this._then);
final ExerciseSearchDetails _self;
final $Res Function(ExerciseSearchDetails) _then;
/// Create a copy of ExerciseSearchDetails
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? translationId = null,Object? exerciseId = null,Object? name = null,Object? category = null,Object? image = freezed,Object? imageThumbnail = freezed,}) {
return _then(_self.copyWith(
translationId: null == translationId ? _self.translationId : translationId // ignore: cast_nullable_to_non_nullable
as int,exerciseId: null == exerciseId ? _self.exerciseId : exerciseId // ignore: cast_nullable_to_non_nullable
as int,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
as String,category: null == category ? _self.category : category // ignore: cast_nullable_to_non_nullable
as String,image: freezed == image ? _self.image : image // ignore: cast_nullable_to_non_nullable
as String?,imageThumbnail: freezed == imageThumbnail ? _self.imageThumbnail : imageThumbnail // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
/// Adds pattern-matching-related methods to [ExerciseSearchDetails].
extension ExerciseSearchDetailsPatterns on ExerciseSearchDetails {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _ExerciseSearchDetails value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _ExerciseSearchDetails() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _ExerciseSearchDetails value) $default,){
final _that = this;
switch (_that) {
case _ExerciseSearchDetails():
return $default(_that);}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _ExerciseSearchDetails value)? $default,){
final _that = this;
switch (_that) {
case _ExerciseSearchDetails() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function(@JsonKey(name: 'id') int translationId, @JsonKey(name: 'base_id') int exerciseId, String name, String category, String? image, @JsonKey(name: 'image_thumbnail') String? imageThumbnail)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _ExerciseSearchDetails() when $default != null:
return $default(_that.translationId,_that.exerciseId,_that.name,_that.category,_that.image,_that.imageThumbnail);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function(@JsonKey(name: 'id') int translationId, @JsonKey(name: 'base_id') int exerciseId, String name, String category, String? image, @JsonKey(name: 'image_thumbnail') String? imageThumbnail) $default,) {final _that = this;
switch (_that) {
case _ExerciseSearchDetails():
return $default(_that.translationId,_that.exerciseId,_that.name,_that.category,_that.image,_that.imageThumbnail);}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function(@JsonKey(name: 'id') int translationId, @JsonKey(name: 'base_id') int exerciseId, String name, String category, String? image, @JsonKey(name: 'image_thumbnail') String? imageThumbnail)? $default,) {final _that = this;
switch (_that) {
case _ExerciseSearchDetails() when $default != null:
return $default(_that.translationId,_that.exerciseId,_that.name,_that.category,_that.image,_that.imageThumbnail);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _ExerciseSearchDetails implements ExerciseSearchDetails {
_ExerciseSearchDetails({@JsonKey(name: 'id') required this.translationId, @JsonKey(name: 'base_id') required this.exerciseId, required this.name, required this.category, required this.image, @JsonKey(name: 'image_thumbnail') required this.imageThumbnail});
factory _ExerciseSearchDetails.fromJson(Map<String, dynamic> json) => _$ExerciseSearchDetailsFromJson(json);
// ignore: invalid_annotation_target
@override@JsonKey(name: 'id') final int translationId;
// ignore: invalid_annotation_target
@override@JsonKey(name: 'base_id') final int exerciseId;
@override final String name;
@override final String category;
@override final String? image;
// ignore: invalid_annotation_target
@override@JsonKey(name: 'image_thumbnail') final String? imageThumbnail;
/// Create a copy of ExerciseSearchDetails
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$ExerciseSearchDetailsCopyWith<_ExerciseSearchDetails> get copyWith => __$ExerciseSearchDetailsCopyWithImpl<_ExerciseSearchDetails>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$ExerciseSearchDetailsToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ExerciseSearchDetails&&(identical(other.translationId, translationId) || other.translationId == translationId)&&(identical(other.exerciseId, exerciseId) || other.exerciseId == exerciseId)&&(identical(other.name, name) || other.name == name)&&(identical(other.category, category) || other.category == category)&&(identical(other.image, image) || other.image == image)&&(identical(other.imageThumbnail, imageThumbnail) || other.imageThumbnail == imageThumbnail));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,translationId,exerciseId,name,category,image,imageThumbnail);
@override
String toString() {
return 'ExerciseSearchDetails(translationId: $translationId, exerciseId: $exerciseId, name: $name, category: $category, image: $image, imageThumbnail: $imageThumbnail)';
}
}
/// @nodoc
abstract mixin class _$ExerciseSearchDetailsCopyWith<$Res> implements $ExerciseSearchDetailsCopyWith<$Res> {
factory _$ExerciseSearchDetailsCopyWith(_ExerciseSearchDetails value, $Res Function(_ExerciseSearchDetails) _then) = __$ExerciseSearchDetailsCopyWithImpl;
@override @useResult
$Res call({
@JsonKey(name: 'id') int translationId,@JsonKey(name: 'base_id') int exerciseId, String name, String category, String? image,@JsonKey(name: 'image_thumbnail') String? imageThumbnail
});
}
/// @nodoc
class __$ExerciseSearchDetailsCopyWithImpl<$Res>
implements _$ExerciseSearchDetailsCopyWith<$Res> {
__$ExerciseSearchDetailsCopyWithImpl(this._self, this._then);
final _ExerciseSearchDetails _self;
final $Res Function(_ExerciseSearchDetails) _then;
/// Create a copy of ExerciseSearchDetails
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? translationId = null,Object? exerciseId = null,Object? name = null,Object? category = null,Object? image = freezed,Object? imageThumbnail = freezed,}) {
return _then(_ExerciseSearchDetails(
translationId: null == translationId ? _self.translationId : translationId // ignore: cast_nullable_to_non_nullable
as int,exerciseId: null == exerciseId ? _self.exerciseId : exerciseId // ignore: cast_nullable_to_non_nullable
as int,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
as String,category: null == category ? _self.category : category // ignore: cast_nullable_to_non_nullable
as String,image: freezed == image ? _self.image : image // ignore: cast_nullable_to_non_nullable
as String?,imageThumbnail: freezed == imageThumbnail ? _self.imageThumbnail : imageThumbnail // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
/// @nodoc
mixin _$ExerciseSearchEntry {
String get value; ExerciseSearchDetails get data;
/// Create a copy of ExerciseSearchEntry
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$ExerciseSearchEntryCopyWith<ExerciseSearchEntry> get copyWith => _$ExerciseSearchEntryCopyWithImpl<ExerciseSearchEntry>(this as ExerciseSearchEntry, _$identity);
/// Serializes this ExerciseSearchEntry to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is ExerciseSearchEntry&&(identical(other.value, value) || other.value == value)&&(identical(other.data, data) || other.data == data));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,value,data);
@override
String toString() {
return 'ExerciseSearchEntry(value: $value, data: $data)';
}
}
/// @nodoc
abstract mixin class $ExerciseSearchEntryCopyWith<$Res> {
factory $ExerciseSearchEntryCopyWith(ExerciseSearchEntry value, $Res Function(ExerciseSearchEntry) _then) = _$ExerciseSearchEntryCopyWithImpl;
@useResult
$Res call({
String value, ExerciseSearchDetails data
});
$ExerciseSearchDetailsCopyWith<$Res> get data;
}
/// @nodoc
class _$ExerciseSearchEntryCopyWithImpl<$Res>
implements $ExerciseSearchEntryCopyWith<$Res> {
_$ExerciseSearchEntryCopyWithImpl(this._self, this._then);
final ExerciseSearchEntry _self;
final $Res Function(ExerciseSearchEntry) _then;
/// Create a copy of ExerciseSearchEntry
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? value = null,Object? data = null,}) {
return _then(_self.copyWith(
value: null == value ? _self.value : value // ignore: cast_nullable_to_non_nullable
as String,data: null == data ? _self.data : data // ignore: cast_nullable_to_non_nullable
as ExerciseSearchDetails,
));
}
/// Create a copy of ExerciseSearchEntry
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ExerciseSearchDetailsCopyWith<$Res> get data {
return $ExerciseSearchDetailsCopyWith<$Res>(_self.data, (value) {
return _then(_self.copyWith(data: value));
});
}
}
/// Adds pattern-matching-related methods to [ExerciseSearchEntry].
extension ExerciseSearchEntryPatterns on ExerciseSearchEntry {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _ExerciseSearchEntry value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _ExerciseSearchEntry() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _ExerciseSearchEntry value) $default,){
final _that = this;
switch (_that) {
case _ExerciseSearchEntry():
return $default(_that);}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _ExerciseSearchEntry value)? $default,){
final _that = this;
switch (_that) {
case _ExerciseSearchEntry() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String value, ExerciseSearchDetails data)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _ExerciseSearchEntry() when $default != null:
return $default(_that.value,_that.data);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String value, ExerciseSearchDetails data) $default,) {final _that = this;
switch (_that) {
case _ExerciseSearchEntry():
return $default(_that.value,_that.data);}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String value, ExerciseSearchDetails data)? $default,) {final _that = this;
switch (_that) {
case _ExerciseSearchEntry() when $default != null:
return $default(_that.value,_that.data);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _ExerciseSearchEntry implements ExerciseSearchEntry {
_ExerciseSearchEntry({required this.value, required this.data});
factory _ExerciseSearchEntry.fromJson(Map<String, dynamic> json) => _$ExerciseSearchEntryFromJson(json);
@override final String value;
@override final ExerciseSearchDetails data;
/// Create a copy of ExerciseSearchEntry
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$ExerciseSearchEntryCopyWith<_ExerciseSearchEntry> get copyWith => __$ExerciseSearchEntryCopyWithImpl<_ExerciseSearchEntry>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$ExerciseSearchEntryToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ExerciseSearchEntry&&(identical(other.value, value) || other.value == value)&&(identical(other.data, data) || other.data == data));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,value,data);
@override
String toString() {
return 'ExerciseSearchEntry(value: $value, data: $data)';
}
}
/// @nodoc
abstract mixin class _$ExerciseSearchEntryCopyWith<$Res> implements $ExerciseSearchEntryCopyWith<$Res> {
factory _$ExerciseSearchEntryCopyWith(_ExerciseSearchEntry value, $Res Function(_ExerciseSearchEntry) _then) = __$ExerciseSearchEntryCopyWithImpl;
@override @useResult
$Res call({
String value, ExerciseSearchDetails data
});
@override $ExerciseSearchDetailsCopyWith<$Res> get data;
}
/// @nodoc
class __$ExerciseSearchEntryCopyWithImpl<$Res>
implements _$ExerciseSearchEntryCopyWith<$Res> {
__$ExerciseSearchEntryCopyWithImpl(this._self, this._then);
final _ExerciseSearchEntry _self;
final $Res Function(_ExerciseSearchEntry) _then;
/// Create a copy of ExerciseSearchEntry
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? value = null,Object? data = null,}) {
return _then(_ExerciseSearchEntry(
value: null == value ? _self.value : value // ignore: cast_nullable_to_non_nullable
as String,data: null == data ? _self.data : data // ignore: cast_nullable_to_non_nullable
as ExerciseSearchDetails,
));
}
/// Create a copy of ExerciseSearchEntry
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ExerciseSearchDetailsCopyWith<$Res> get data {
return $ExerciseSearchDetailsCopyWith<$Res>(_self.data, (value) {
return _then(_self.copyWith(data: value));
});
}
}
/// @nodoc
mixin _$ExerciseApiSearch {
List<ExerciseSearchEntry> get suggestions;
/// Create a copy of ExerciseApiSearch
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$ExerciseApiSearchCopyWith<ExerciseApiSearch> get copyWith => _$ExerciseApiSearchCopyWithImpl<ExerciseApiSearch>(this as ExerciseApiSearch, _$identity);
/// Serializes this ExerciseApiSearch to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is ExerciseApiSearch&&const DeepCollectionEquality().equals(other.suggestions, suggestions));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(suggestions));
@override
String toString() {
return 'ExerciseApiSearch(suggestions: $suggestions)';
}
}
/// @nodoc
abstract mixin class $ExerciseApiSearchCopyWith<$Res> {
factory $ExerciseApiSearchCopyWith(ExerciseApiSearch value, $Res Function(ExerciseApiSearch) _then) = _$ExerciseApiSearchCopyWithImpl;
@useResult
$Res call({
List<ExerciseSearchEntry> suggestions
});
}
/// @nodoc
class _$ExerciseApiSearchCopyWithImpl<$Res>
implements $ExerciseApiSearchCopyWith<$Res> {
_$ExerciseApiSearchCopyWithImpl(this._self, this._then);
final ExerciseApiSearch _self;
final $Res Function(ExerciseApiSearch) _then;
/// Create a copy of ExerciseApiSearch
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? suggestions = null,}) {
return _then(_self.copyWith(
suggestions: null == suggestions ? _self.suggestions : suggestions // ignore: cast_nullable_to_non_nullable
as List<ExerciseSearchEntry>,
));
}
}
/// Adds pattern-matching-related methods to [ExerciseApiSearch].
extension ExerciseApiSearchPatterns on ExerciseApiSearch {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _ExerciseApiSearch value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _ExerciseApiSearch() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _ExerciseApiSearch value) $default,){
final _that = this;
switch (_that) {
case _ExerciseApiSearch():
return $default(_that);}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _ExerciseApiSearch value)? $default,){
final _that = this;
switch (_that) {
case _ExerciseApiSearch() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( List<ExerciseSearchEntry> suggestions)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _ExerciseApiSearch() when $default != null:
return $default(_that.suggestions);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( List<ExerciseSearchEntry> suggestions) $default,) {final _that = this;
switch (_that) {
case _ExerciseApiSearch():
return $default(_that.suggestions);}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( List<ExerciseSearchEntry> suggestions)? $default,) {final _that = this;
switch (_that) {
case _ExerciseApiSearch() when $default != null:
return $default(_that.suggestions);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _ExerciseApiSearch implements ExerciseApiSearch {
_ExerciseApiSearch({required final List<ExerciseSearchEntry> suggestions}): _suggestions = suggestions;
factory _ExerciseApiSearch.fromJson(Map<String, dynamic> json) => _$ExerciseApiSearchFromJson(json);
final List<ExerciseSearchEntry> _suggestions;
@override List<ExerciseSearchEntry> get suggestions {
if (_suggestions is EqualUnmodifiableListView) return _suggestions;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_suggestions);
}
/// Create a copy of ExerciseApiSearch
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$ExerciseApiSearchCopyWith<_ExerciseApiSearch> get copyWith => __$ExerciseApiSearchCopyWithImpl<_ExerciseApiSearch>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$ExerciseApiSearchToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ExerciseApiSearch&&const DeepCollectionEquality().equals(other._suggestions, _suggestions));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(_suggestions));
@override
String toString() {
return 'ExerciseApiSearch(suggestions: $suggestions)';
}
}
/// @nodoc
abstract mixin class _$ExerciseApiSearchCopyWith<$Res> implements $ExerciseApiSearchCopyWith<$Res> {
factory _$ExerciseApiSearchCopyWith(_ExerciseApiSearch value, $Res Function(_ExerciseApiSearch) _then) = __$ExerciseApiSearchCopyWithImpl;
@override @useResult
$Res call({
List<ExerciseSearchEntry> suggestions
});
}
/// @nodoc
class __$ExerciseApiSearchCopyWithImpl<$Res>
implements _$ExerciseApiSearchCopyWith<$Res> {
__$ExerciseApiSearchCopyWithImpl(this._self, this._then);
final _ExerciseApiSearch _self;
final $Res Function(_ExerciseApiSearch) _then;
/// Create a copy of ExerciseApiSearch
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? suggestions = null,}) {
return _then(_ExerciseApiSearch(
suggestions: null == suggestions ? _self._suggestions : suggestions // ignore: cast_nullable_to_non_nullable
as List<ExerciseSearchEntry>,
));
}
}
// dart format on

View File

@@ -1,3 +1,21 @@
/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* 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 <http://www.gnu.org/licenses/>.
*/
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'exercise_api.dart';
@@ -57,47 +75,3 @@ Map<String, dynamic> _$ExerciseBaseDataToJson(_ExerciseBaseData instance) => <St
'author_history': instance.authors,
'total_authors_history': instance.authorsGlobal,
};
_ExerciseSearchDetails _$ExerciseSearchDetailsFromJson(
Map<String, dynamic> json,
) => _ExerciseSearchDetails(
translationId: (json['id'] as num).toInt(),
exerciseId: (json['base_id'] as num).toInt(),
name: json['name'] as String,
category: json['category'] as String,
image: json['image'] as String?,
imageThumbnail: json['image_thumbnail'] as String?,
);
Map<String, dynamic> _$ExerciseSearchDetailsToJson(
_ExerciseSearchDetails instance,
) => <String, dynamic>{
'id': instance.translationId,
'base_id': instance.exerciseId,
'name': instance.name,
'category': instance.category,
'image': instance.image,
'image_thumbnail': instance.imageThumbnail,
};
_ExerciseSearchEntry _$ExerciseSearchEntryFromJson(Map<String, dynamic> json) =>
_ExerciseSearchEntry(
value: json['value'] as String,
data: ExerciseSearchDetails.fromJson(
json['data'] as Map<String, dynamic>,
),
);
Map<String, dynamic> _$ExerciseSearchEntryToJson(
_ExerciseSearchEntry instance,
) => <String, dynamic>{'value': instance.value, 'data': instance.data};
_ExerciseApiSearch _$ExerciseApiSearchFromJson(Map<String, dynamic> json) => _ExerciseApiSearch(
suggestions: (json['suggestions'] as List<dynamic>)
.map((e) => ExerciseSearchEntry.fromJson(e as Map<String, dynamic>))
.toList(),
);
Map<String, dynamic> _$ExerciseApiSearchToJson(_ExerciseApiSearch instance) => <String, dynamic>{
'suggestions': instance.suggestions,
};

View File

@@ -686,26 +686,29 @@ class ExercisesProvider with ChangeNotifier {
// Send the request
final result = await baseProvider.fetch(
baseProvider.makeUrl(
exerciseSearchPath,
exerciseInfoUrlPath,
query: {'term': name, 'language': languages.join(',')},
),
);
// Load the exercises
final results = ExerciseApiSearch.fromJson(result);
// final tmp = result['results'].map((r) => ExerciseApiData.fromJson(r)).toList();
// print(tmp);
// return tmp.map((r) => Exercise.fromApiData(r, _languages)).toList();
final List<Exercise> out = [];
for (final result in results.suggestions) {
final exercise = await fetchAndSetExercise(result.data.exerciseId);
if (exercise != null) {
out.add(exercise);
}
}
// return Future.wait(
// results.suggestions.map((e) => fetchAndSetExercise(e.data.exerciseId)),
// );
final resultsList = (result['results'] as List<dynamic>?) ?? <dynamic>[];
// print(resultsList);
return out;
final exercises = resultsList
.map<Exercise>(
(r) => Exercise.fromApiData(
ExerciseApiData.fromJson(r as Map<String, dynamic>),
_languages,
),
)
.toList();
return exercises;
}
}

View File

@@ -3832,6 +3832,28 @@ class MockAppLocalizations extends _i1.Mock implements _i2.AppLocalizations {
)
as String);
@override
String get productNotFoundOpenFoodFacts =>
(super.noSuchMethod(
Invocation.getter(#productNotFoundOpenFoodFacts),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#productNotFoundOpenFoodFacts),
),
)
as String);
@override
String get addToOpenFoodFacts =>
(super.noSuchMethod(
Invocation.getter(#addToOpenFoodFacts),
returnValue: _i3.dummyValue<String>(
this,
Invocation.getter(#addToOpenFoodFacts),
),
)
as String);
@override
String exerciseNr(String? nr) =>
(super.noSuchMethod(

View File

@@ -48,7 +48,6 @@ void main() {
const String muscleUrl = 'muscle';
const String equipmentUrl = 'equipment';
const String languageUrl = 'language';
const String searchExerciseUrl = 'exercise/search';
final Uri tCategoryEntriesUri = Uri(
scheme: 'http',
@@ -83,7 +82,7 @@ void main() {
final Uri tSearchByNameUri = Uri(
scheme: 'http',
host: 'localhost',
path: 'api/v2/$searchExerciseUrl/',
path: 'api/v2/$exerciseInfoUrl/',
);
const category1 = ExerciseCategory(id: 1, name: 'Arms');
@@ -368,17 +367,17 @@ void main() {
tSearchByNameUri = Uri(
scheme: 'http',
host: 'localhost',
path: 'api/v2/$searchExerciseUrl/',
path: 'api/v2/$exerciseInfoUrl/',
queryParameters: query,
);
final Map<String, dynamic> tSearchResponse = jsonDecode(
fixture('exercises/exercise_search_entries.json'),
fixture('exercises/exerciseinfo_search_entries.json'),
);
// Mock exercise search
when(
mockBaseProvider.makeUrl(
searchExerciseUrl,
exerciseInfoUrl,
query: {'term': tSearchTerm, 'language': tSearchLanguage},
),
).thenReturn(tSearchByNameUri);
@@ -394,9 +393,12 @@ void main() {
// assert
verify(provider.baseProvider.fetch(tSearchByNameUri)).called(1);
final result1 = provider.filteredExercises[0];
final testExercise1 = data.getTestExercises()[0];
expect(result1.uuid, testExercise1.uuid);
expect(
provider.filteredExercises,
[data.getTestExercises()[0], data.getTestExercises()[1]],
result1.translations.map((e) => e.uuid).toList(),
testExercise1.translations.map((e) => e.uuid).toList(),
);
});
test('Should find items from selection but should filter them by search term', () async {

View File

@@ -1,26 +0,0 @@
{
"suggestions": [
{
"value": "Bench Press Narrow Grip",
"data": {
"id": 1,
"base_id": 1,
"name": "test exercise 1",
"category": "Arms",
"image": "/media/exercise-images/76/Narrow-grip-bench-press-2.png",
"image_thumbnail": "/media/exercise-images/76/Narrow-grip-bench-press-2.png.30x30_q85_crop-smart.png"
}
},
{
"value": "Close-grip Bench Press",
"data": {
"id": 2,
"base_id": 2,
"name": "test exercise 2",
"category": "Arms",
"image": null,
"image_thumbnail": null
}
}
]
}

View File

@@ -0,0 +1,121 @@
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 1,
"uuid": "364f196c-881b-4839-8bfc-9e8f651521b6",
"created": "2023-08-06T11:20:14.368566+02:00",
"last_update": "2023-04-22T12:18:33.904542+02:00",
"last_update_global": "2023-04-22T12:18:33.907201+02:00",
"category": {
"id": 1,
"name": "Arms"
},
"muscles": [
{
"id": 1,
"name": "Flutterus maximus",
"name_en": "Glutes",
"is_front": false,
"image_url_main": "/static/images/muscles/main/muscle-1.svg",
"image_url_secondary": "/static/images/muscles/secondary/muscle-1.svg"
},
{
"id": 2,
"name": "Biceps brachii",
"name_en": "Biceps",
"is_front": true,
"image_url_main": "/static/images/muscles/main/muscle-2.svg",
"image_url_secondary": "/static/images/muscles/secondary/muscle-2.svg"
}
],
"muscles_secondary": [
{
"id": 3,
"name": "Gluteus maximus",
"name_en": "Glutes",
"is_front": true,
"image_url_main": "/static/images/muscles/main/muscle-3.svg",
"image_url_secondary": "/static/images/muscles/secondary/muscle-3.svg"
}
],
"equipment": [
{
"id": 1,
"name": "Bench"
},
{
"id": 2,
"name": "Dumbbell"
}
],
"license": {
"id": 2,
"full_name": "Creative Commons Attribution Share Alike 4",
"short_name": "CC-BY-SA 4",
"url": "https://creativecommons.org/licenses/by-sa/4.0/deed.en"
},
"license_author": "deusinvictus",
"images": [],
"videos": [],
"translations": [
{
"id": 7,
"uuid": "f4cc326b-e497-4bd7-a71d-0eb1db522743",
"aliases": [
],
"name": "Bench press",
"exercise": 1,
"description": "add clever text",
"notes": [
],
"created": "2015-08-03T18:22:54.909478+02:00",
"language": 2,
"license": 2,
"license_author": "deusinvictus",
"license_title": "",
"license_object_url": "",
"license_author_url": "",
"license_derivative_source_url": "",
"author_history": [
"deusinvictus",
"Foo Bar"
]
},
{
"id": 1,
"uuid": "f4cc326b-e497-4bd7-a71d-0eb1db522743",
"aliases": [
],
"name": "Bankdrücken",
"exercise": 1,
"description": "add clever text",
"notes": [
],
"created": "2022-03-14T18:22:54.909478+02:00",
"language": 3,
"license": 2,
"license_author": "tester McTestface",
"license_title": "",
"license_object_url": "",
"license_author_url": "",
"license_derivative_source_url": "",
"author_history": [
"tester McTestface"
]
}
],
"variations": 25,
"author_history": [
"Foo Bar"
],
"total_authors_history": [
"Foo Bar",
"tester McTestface",
"Mr. X"
]
}
]
}