79 lines
1.7 KiB
Dart
79 lines
1.7 KiB
Dart
class PostCreator {
|
|
final String id;
|
|
final String displayName;
|
|
|
|
PostCreator({
|
|
required this.id,
|
|
required this.displayName,
|
|
});
|
|
|
|
factory PostCreator.fromJson(Map<String, dynamic> json) {
|
|
return PostCreator(
|
|
id: json['id']?.toString() ?? '',
|
|
displayName: json['displayName'] ?? '',
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'displayName': displayName,
|
|
};
|
|
}
|
|
}
|
|
|
|
class Post {
|
|
final String id;
|
|
final String creatorId;
|
|
final PostCreator creator;
|
|
final String body;
|
|
final int likes;
|
|
final int comments;
|
|
final DateTime creationDate;
|
|
|
|
Post({
|
|
required this.id,
|
|
required this.creatorId,
|
|
required this.creator,
|
|
required this.body,
|
|
required this.likes,
|
|
required this.comments,
|
|
required this.creationDate,
|
|
});
|
|
|
|
factory Post.fromJson(Map<String, dynamic> json) {
|
|
return Post(
|
|
id: json['id']?.toString() ?? '',
|
|
creatorId: json['creatorId']?.toString() ?? '',
|
|
creator: PostCreator.fromJson(json['creator'] ?? {}),
|
|
body: json['body'] ?? '',
|
|
likes: int.tryParse(json['likes']?.toString() ?? '0') ?? 0,
|
|
comments: int.tryParse(json['comments']?.toString() ?? '0') ?? 0,
|
|
creationDate: DateTime.parse(json['creationDate'] ?? DateTime.now().toIso8601String()),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'creatorId': creatorId,
|
|
'creator': creator.toJson(),
|
|
'body': body,
|
|
'likes': likes,
|
|
'comments': comments,
|
|
'creationDate': creationDate.toIso8601String(),
|
|
};
|
|
}
|
|
}
|
|
|
|
class CreatePostRequest {
|
|
final String body;
|
|
|
|
CreatePostRequest({required this.body});
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'body': body,
|
|
};
|
|
}
|
|
} |