forked from eatvio/eatvio_app
96 lines
3.7 KiB
Dart
96 lines
3.7 KiB
Dart
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
part 'post_feed_pagination_model.freezed.dart';
|
|
part 'post_feed_pagination_model.g.dart';
|
|
|
|
@freezed
|
|
abstract class PostFeedPaginationModel with _$PostFeedPaginationModel {
|
|
const factory PostFeedPaginationModel({
|
|
@JsonKey(name: 'data') required List<PostFeedItemModel> data,
|
|
required CursorLinks links,
|
|
required CursorMeta meta,
|
|
}) = _PostFeedPaginationModel;
|
|
|
|
factory PostFeedPaginationModel.fromJson(Map<String, Object?> json) => _$PostFeedPaginationModelFromJson(json);
|
|
}
|
|
|
|
@freezed
|
|
abstract class PostFeedItemModel with _$PostFeedItemModel {
|
|
const factory PostFeedItemModel({
|
|
required int id,
|
|
@JsonKey(name: 'post_id') required int postId,
|
|
@JsonKey(name: 'post_author_id') required int postAuthorId,
|
|
@JsonKey(name: 'post_author_name') required String postAuthorName,
|
|
@JsonKey(name: 'post_author_image_url') String? postAuthorImageUrl,
|
|
@JsonKey(name: 'post_author_profile_url') String? postAuthorProfileUrl,
|
|
@JsonKey(name: 'post_created_at', fromJson: parseDateTime) required DateTime postCreatedAt,
|
|
@JsonKey(name: 'post_title') required String postTitle,
|
|
@JsonKey(name: 'post_short_description') String? postShortDescription,
|
|
@JsonKey(name: 'post_text_md') String? postTextMd,
|
|
@JsonKey(name: 'post_image_url') String? postImageUrl,
|
|
@Default([]) List<FeedGalleryImage> images,
|
|
@JsonKey(name: 'video_embed_url') String? videoEmbedUrl,
|
|
@JsonKey(name: 'post_views_count') required int postViewsCount,
|
|
@JsonKey(name: 'post_likes_count') required int postLikesCount,
|
|
@JsonKey(name: 'post_comments_count') required int postCommentsCount,
|
|
@JsonKey(name: 'post_is_liked_by_user') required bool postIsLikedByUser,
|
|
@JsonKey(name: 'is_entity_subscribed_by_me') bool? isEntitySubscribedByMe,
|
|
@JsonKey(name: 'post_url') String? postUrl,
|
|
@JsonKey(name: 'post_state') required String postState,
|
|
@JsonKey(name: 'post_author_detailz') PostAuthorDetails? postAuthorDetails,
|
|
@JsonKey(name: "video_url_thumb") String? videoUrlThumb,
|
|
@JsonKey(name: 'created_at', fromJson: parseDateTime) required DateTime createdAt,
|
|
@JsonKey(name: 'updated_at', fromJson: parseDateTime) required DateTime updatedAt,
|
|
}) = _PostFeedItemModel;
|
|
|
|
factory PostFeedItemModel.fromJson(Map<String, Object?> json) => _$PostFeedItemModelFromJson(json);
|
|
}
|
|
|
|
@freezed
|
|
abstract class FeedGalleryImage with _$FeedGalleryImage {
|
|
const factory FeedGalleryImage({
|
|
required String url,
|
|
@Default('horizontal') String orientation,
|
|
int? id,
|
|
int? position,
|
|
}) = _FeedGalleryImage;
|
|
|
|
factory FeedGalleryImage.fromJson(Map<String, Object?> json) => _$FeedGalleryImageFromJson(json);
|
|
}
|
|
|
|
@freezed
|
|
abstract class PostAuthorDetails with _$PostAuthorDetails {
|
|
const factory PostAuthorDetails({
|
|
required String slug,
|
|
@JsonKey(name: 'is_consultant') required bool isConsultant,
|
|
}) = _PostAuthorDetails;
|
|
|
|
factory PostAuthorDetails.fromJson(Map<String, Object?> json) => _$PostAuthorDetailsFromJson(json);
|
|
}
|
|
|
|
@freezed
|
|
abstract class CursorLinks with _$CursorLinks {
|
|
const factory CursorLinks({
|
|
required String? first,
|
|
required String? last,
|
|
required String? prev,
|
|
required String? next,
|
|
}) = _CursorLinks;
|
|
|
|
factory CursorLinks.fromJson(Map<String, Object?> json) => _$CursorLinksFromJson(json);
|
|
}
|
|
|
|
@freezed
|
|
abstract class CursorMeta with _$CursorMeta {
|
|
const factory CursorMeta({
|
|
required String path,
|
|
@JsonKey(name: 'per_page') required int perPage,
|
|
@JsonKey(name: 'next_cursor') String? nextCursor,
|
|
@JsonKey(name: 'prev_cursor') String? prevCursor,
|
|
}) = _CursorMeta;
|
|
|
|
factory CursorMeta.fromJson(Map<String, Object?> json) => _$CursorMetaFromJson(json);
|
|
}
|
|
|
|
DateTime parseDateTime(String date) => DateTime.parse(date).toLocal();
|