workouttest_util/lib/model/exercise_plan.dart
2023-02-12 22:42:51 +01:00

71 lines
1.9 KiB
Dart

import 'package:intl/intl.dart';
class ExercisePlan {
int? exercisePlanId;
late int customerId;
late String name;
String? description;
late bool private;
late DateTime? dateAdd;
late DateTime dateUpd;
String? type;
int? exercisePlanTemplateId;
ExercisePlan(String name, int customerId) {
customerId = customerId;
name = name;
dateUpd = DateTime.now();
}
ExercisePlan.fromJson(Map json) {
exercisePlanId = json['exercisePlanId'];
customerId = json['customerId'];
name = json['name'];
private = json['private'];
description = json['description'];
dateAdd = (json['dateAdd'] == null ? null : DateTime.parse(json['dateAdd']))!;
dateUpd = (json['dateUpd'] == null ? null : DateTime.parse(json['dateUpd']))!;
type = json['type'];
exercisePlanTemplateId = json['exercisePlanTemplateId'];
}
Map<String, dynamic> toJson() {
String? formattedDateAdd;
if (dateAdd != null) {
formattedDateAdd = DateFormat('yyyy-MM-dd HH:mm').format(dateAdd!);
}
String formattedDateUpd = DateFormat('yyyy-MM-dd HH:mm').format(dateUpd);
if (exercisePlanId == null) {
return {
"customerId": customerId,
"name": name,
"description": description,
"private": private,
"dateAdd": formattedDateAdd,
"dateUpd": formattedDateUpd,
"type": type,
"exercisePlanTemplateId": exercisePlanTemplateId
};
} else {
return {
"exercisePlanId": exercisePlanId,
"customerId": customerId,
"name": name,
"description": description,
"private": private,
"dateAdd": formattedDateAdd,
"dateUpd": formattedDateUpd,
"type": type,
"exercisePlanTemplateId": exercisePlanTemplateId
};
}
}
@override
String toString() {
Map<String, dynamic> json = toJson();
return json.toString();
}
}