Files
eatvio_app/lib/features/diary/models/diary_model.dart

117 lines
2.9 KiB
Dart

import 'package:freezed_annotation/freezed_annotation.dart';
part 'diary_model.freezed.dart';
part 'diary_model.g.dart';
@freezed
class DiaryModel with _$DiaryModel {
const factory DiaryModel(
{required int id,
required DateTime date,
required DateTime wakeup,
required DateTime retire,
required int closed,
required String comment,
required List<Meals> meals}) = _DiaryModel;
factory DiaryModel.fromJson(Map<String, Object?> json) => _$DiaryModelFromJson(json);
}
class Meals {
int? id;
String? time;
int? type;
int? satiety;
int? mood;
List<Portions>? portions;
List<Photos>? photos;
Meals({this.id, this.time, this.type, this.satiety, this.mood, this.portions, this.photos});
Meals.fromJson(Map<String, dynamic> json) {
List<Portions> portions = [];
List<Photos> photos = [];
id = json['id'];
time = json['time'];
type = json['type'];
satiety = json['satiety'];
mood = json['mood'];
if (json['portions'] != null) {
json['portions'].forEach((v) {
portions.add(new Portions.fromJson(v));
});
}
if (json['photos'] != null) {
json['photos'].forEach((v) {
photos.add(new Photos.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['time'] = this.time;
data['type'] = this.type;
data['satiety'] = this.satiety;
data['mood'] = this.mood;
if (this.portions != null) {
data['portions'] = this.portions?.map((v) => v.toJson()).toList();
}
if (this.photos != null) {
data['photos'] = this.photos?.map((v) => v.toJson()).toList();
}
return data;
}
}
class Portions {
int? id;
String? productName;
int? quantity;
String? portion;
Portions({this.id, this.productName, this.quantity, this.portion});
Portions.fromJson(Map<String, dynamic> json) {
id = json['id'];
productName = json['product_name'];
quantity = json['quantity'];
portion = json['portion'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['product_name'] = this.productName;
data['quantity'] = this.quantity;
data['portion'] = this.portion;
return data;
}
}
class Photos {
int? id;
String? originalName;
String? path;
int? size;
Photos({this.id, this.originalName, this.path, this.size});
Photos.fromJson(Map<String, dynamic> json) {
id = json['id'];
originalName = json['original_name'];
path = json['path'];
size = json['size'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['original_name'] = this.originalName;
data['path'] = this.path;
data['size'] = this.size;
return data;
}
}