Files
flutter/lib/models/exercises/exercise.dart
Roland Geider f56619939e Simplify loading of exercise data
While this has more manual steps than I would prefer, it is definitely better
than loading the individual entries and mapping them to an forth
2022-05-11 00:03:05 +02:00

103 lines
2.5 KiB
Dart

/*
* This file is part of wger Workout Manager <https://github.com/wger-project>.
* Copyright (C) 2020, 2021 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 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:wger/models/exercises/alias.dart';
import 'package:wger/models/exercises/base.dart';
import 'package:wger/models/exercises/comment.dart';
import 'package:wger/models/exercises/language.dart';
part 'exercise.g.dart';
@JsonSerializable()
class Exercise extends Equatable {
@JsonKey(required: true)
final int? id;
@JsonKey(required: true)
final String? uuid;
@JsonKey(required: true, name: 'language')
late int languageId;
@JsonKey(ignore: true)
late Language languageObj;
@JsonKey(required: true, name: 'creation_date')
final DateTime? creationDate;
@JsonKey(required: true, name: 'exercise_base')
late int? baseId;
@JsonKey(required: true)
final String name;
@JsonKey(required: true)
final String description;
@JsonKey(ignore: true)
List<Comment> notes = [];
@JsonKey(ignore: true)
List<Alias> alias = [];
Exercise({
this.id,
this.uuid,
this.creationDate,
required this.name,
required this.description,
int? baseId,
language,
}) {
if (baseId != null) {
baseId = baseId;
}
if (language != null) {
languageObj = language;
languageId = language.id;
}
}
set base(ExerciseBase base) {
baseId = base.id;
}
set language(Language language) {
languageObj = language;
languageId = language.id;
}
// Boilerplate
factory Exercise.fromJson(Map<String, dynamic> json) => _$ExerciseFromJson(json);
Map<String, dynamic> toJson() => _$ExerciseToJson(this);
@override
List<Object?> get props => [
id,
baseId,
uuid,
languageId,
creationDate,
name,
description,
];
}