108 lines
3.1 KiB
Dart
108 lines
3.1 KiB
Dart
import 'package:didvan/models/content/content_item.dart';
|
|
import 'package:didvan/models/tag.dart';
|
|
|
|
class InfographyContent {
|
|
final List<Content> contents;
|
|
final int lastPage;
|
|
|
|
InfographyContent({required this.contents, required this.lastPage});
|
|
|
|
factory InfographyContent.fromJson(Map<String, dynamic> json) {
|
|
return InfographyContent(
|
|
contents:
|
|
List<Content>.from(json['contents'].map((x) => Content.fromJson(x))),
|
|
lastPage: json['lastPage'],
|
|
);
|
|
}
|
|
}
|
|
|
|
class Content {
|
|
final int id;
|
|
final String title;
|
|
final String image;
|
|
final String category;
|
|
final String createdAt;
|
|
bool marked;
|
|
bool liked;
|
|
int likes;
|
|
|
|
final List<Tag> tags;
|
|
|
|
/// زیردستهی محتوا که در پنل تعیین میشود (مثلا 'economic', 'political',
|
|
/// 'technology'). برای فیلتر کردن اینفوگرافی/بنر در صفحهی اپ.
|
|
final String metaCategory;
|
|
|
|
/// UUID محتوا در content-service جدید (در صورت وجود). برای ارسال
|
|
/// bookmark/like از طریق API جدید استفاده میشود.
|
|
final String? keycloakId;
|
|
|
|
/// لینک خارجی (مثلا منبع گرافیک). در صفحهی detail دکمهای برای باز کردنش.
|
|
final String? link;
|
|
|
|
/// تعداد کامنت — برای نمایش بج روی FloatingNavigationBar.
|
|
int comments;
|
|
|
|
Content(
|
|
{required this.id,
|
|
required this.marked,
|
|
required this.liked,
|
|
required this.likes,
|
|
required this.createdAt,
|
|
required this.title,
|
|
required this.image,
|
|
required this.category,
|
|
required this.tags,
|
|
this.metaCategory = '',
|
|
this.keycloakId,
|
|
this.link,
|
|
this.comments = 0});
|
|
|
|
factory Content.fromJson(Map<String, dynamic> json) {
|
|
return Content(
|
|
id: json['id'],
|
|
marked: json['marked'],
|
|
liked: json['liked'],
|
|
likes: json['likes'],
|
|
createdAt: json['createdAt'],
|
|
title: json['title'],
|
|
image: json['image'],
|
|
category: json['category'],
|
|
tags: List<Tag>.from(json['tags'].map((x) => Tag.fromJson(x))),
|
|
);
|
|
}
|
|
|
|
/// ساختن Content اینفوگرافی از یک ContentItem (content-service جدید).
|
|
/// id عددی از hashCode ساخته میشود (سازگاری با کدهای موجود)؛ tags فعلا
|
|
/// خالی است چون content-service tag جدا ندارد.
|
|
factory Content.fromContentItem(ContentItem item) {
|
|
return Content(
|
|
id: item.id.hashCode,
|
|
title: item.title,
|
|
image: item.coverImage ?? '',
|
|
category: item.category?.name ?? '',
|
|
createdAt: item.publishedAt?.toIso8601String() ?? '',
|
|
marked: item.isBookmarked,
|
|
liked: item.isLiked,
|
|
likes: item.likeCount,
|
|
tags: const <Tag>[],
|
|
metaCategory: item.metaCategory ?? '',
|
|
keycloakId: item.id,
|
|
link: item.metaLink,
|
|
);
|
|
}
|
|
}
|
|
|
|
// class Tag {
|
|
// final int id;
|
|
// final String label;
|
|
|
|
// Tag({required this.id, required this.label});
|
|
|
|
// factory Tag.fromJson(Map<String, dynamic> json) {
|
|
// return Tag(
|
|
// id: json['id'],
|
|
// label: json['label'],
|
|
// );
|
|
// }
|
|
// }
|