forked from eatvio/eatvio_app
refactor(diary): API connect attempt
This commit is contained in:
@@ -1,127 +1,21 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import './meal.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<Meal> meals}) = _DiaryModel;
|
||||
const factory DiaryModel({
|
||||
required int id,
|
||||
required DateTime date,
|
||||
required int closed,
|
||||
required List<Meal>? meals,
|
||||
String? comment,
|
||||
DateTime? wakeup,
|
||||
DateTime? retire,
|
||||
}) = _DiaryModel;
|
||||
|
||||
factory DiaryModel.fromJson(Map<String, Object?> json) =>
|
||||
_$DiaryModelFromJson(json);
|
||||
}
|
||||
|
||||
class Meal {
|
||||
late int id;
|
||||
late String time;
|
||||
late int type;
|
||||
late int satiety;
|
||||
late int mood;
|
||||
List<Portion>? portions;
|
||||
List<Photo>? photos;
|
||||
|
||||
Meal(
|
||||
{required this.id,
|
||||
required this.time,
|
||||
required this.type,
|
||||
required this.satiety,
|
||||
required this.mood,
|
||||
this.portions,
|
||||
this.photos});
|
||||
|
||||
Meal.fromJson(Map<String, dynamic> json) {
|
||||
List<Portion> portions = [];
|
||||
List<Photo> 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 Portion.fromJson(v));
|
||||
});
|
||||
}
|
||||
if (json['photos'] != null) {
|
||||
json['photos'].forEach((v) {
|
||||
photos.add(new Photo.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 Portion {
|
||||
late int id;
|
||||
late String productName;
|
||||
late int quantity;
|
||||
late String portion;
|
||||
|
||||
Portion(
|
||||
{required this.id,
|
||||
required this.productName,
|
||||
required this.quantity,
|
||||
required this.portion});
|
||||
|
||||
Portion.fromJson(v);
|
||||
|
||||
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 Photo {
|
||||
late int id;
|
||||
late String originalName;
|
||||
late String path;
|
||||
late int size;
|
||||
|
||||
Photo(
|
||||
{required this.id,
|
||||
required this.originalName,
|
||||
required this.path,
|
||||
required this.size});
|
||||
|
||||
Photo.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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user