models cleanup
This commit is contained in:
parent
43ab1990d7
commit
b829b30593
|
@ -0,0 +1,94 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'comment.g.dart';
|
||||
|
||||
/// based on https://github.com/LemmyNet/lemmy/blob/464ea862b10fa7b226b2550268e40d8e685a939c/server/lemmy_db/src/comment_view.rs#L91
|
||||
@JsonSerializable(fieldRename: FieldRename.snake, createToJson: false)
|
||||
class CommentView {
|
||||
final int id;
|
||||
final int creatorId;
|
||||
final int postId;
|
||||
final String postName;
|
||||
/// can be null
|
||||
final int parentId;
|
||||
final String content;
|
||||
final bool removed;
|
||||
final bool read;
|
||||
final DateTime published;
|
||||
/// can be null
|
||||
@JsonKey(fromJson: DateTime.tryParse)
|
||||
final DateTime updated;
|
||||
final bool deleted;
|
||||
final String apId;
|
||||
final bool local;
|
||||
final int communityId;
|
||||
final String communityActorId;
|
||||
final bool communityLocal;
|
||||
final String communityName;
|
||||
/// can be null
|
||||
final String communityIcon;
|
||||
final bool banned;
|
||||
final bool bannedFromCommunity;
|
||||
final String creatorActorId;
|
||||
final bool creatorLocal;
|
||||
final String creatorName;
|
||||
/// can be null
|
||||
final String creatorPreferredUsername;
|
||||
final DateTime creatorPublished;
|
||||
/// can be null
|
||||
final String creatorAvatar;
|
||||
final int score;
|
||||
final int upvotes;
|
||||
final int downvotes;
|
||||
final int hotRank;
|
||||
final int hotRankActive;
|
||||
/// can be null
|
||||
final int userId;
|
||||
/// can be null
|
||||
final int myVote;
|
||||
/// can be null
|
||||
final bool subscribed;
|
||||
/// can be null
|
||||
final bool saved;
|
||||
|
||||
const CommentView({
|
||||
this.id,
|
||||
this.creatorId
|
||||
this.postId,
|
||||
this.postName,
|
||||
this.parentId,
|
||||
this.content
|
||||
this.removed
|
||||
this.read,
|
||||
this.published
|
||||
this.updated
|
||||
this.deleted
|
||||
this.apId,
|
||||
this.local
|
||||
this.communityId
|
||||
this.communityActorId,
|
||||
this.communityLocal,
|
||||
this.communityName
|
||||
this.communityIcon
|
||||
this.banned,
|
||||
this.bannedFromCommunity
|
||||
this.creatorActorId,
|
||||
this.creatorLocal,
|
||||
this.creatorName
|
||||
this.creatorPreferredUsername,
|
||||
this.creatorPublished,
|
||||
this.creatorAvatar
|
||||
this.score
|
||||
this.upvotes
|
||||
this.downvotes
|
||||
this.hotRank
|
||||
this.hotRankActive
|
||||
this.userId,
|
||||
this.myVote,
|
||||
this.subscribed,
|
||||
this.saved,
|
||||
});
|
||||
|
||||
factory CommentView.fromJson(Map<String, dynamic> json) =>
|
||||
_$CommentViewFromJson(json);
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'post.g.dart';
|
||||
|
||||
/// based on https://github.com/LemmyNet/lemmy/blob/464ea862b10fa7b226b2550268e40d8e685a939c/server/lemmy_db/src/post_view.rs#L113
|
||||
@JsonSerializable(fieldRename: FieldRename.snake, createToJson: false)
|
||||
class PostView {
|
||||
final int id;
|
||||
final String name;
|
||||
/// can be null
|
||||
final String url;
|
||||
/// can be null
|
||||
final String body;
|
||||
final int creatorId;
|
||||
final int communityId;
|
||||
final bool removed;
|
||||
final bool locked;
|
||||
final DateTime published;
|
||||
/// can be null
|
||||
@JsonKey(fromJson: DateTime.tryParse)
|
||||
final DateTime updated;
|
||||
final bool deleted;
|
||||
final bool nsfw;
|
||||
final bool stickied;
|
||||
/// can be null
|
||||
final String embedTitle;
|
||||
/// can be null
|
||||
final String embedDescription;
|
||||
/// can be null
|
||||
final String embedHtml;
|
||||
/// can be null
|
||||
final String thumbnailUrl;
|
||||
final String apId;
|
||||
final bool local;
|
||||
final String creatorActorId;
|
||||
final bool creatorLocal;
|
||||
final String creatorName;
|
||||
/// can be null
|
||||
final String creatorPreferredUsername;
|
||||
final DateTime creatorPublished;
|
||||
/// can be null
|
||||
final String creatorAvatar;
|
||||
final bool banned;
|
||||
final bool bannedFromCommunity;
|
||||
final String communityActorId;
|
||||
final bool communityLocal;
|
||||
final String communityName;
|
||||
/// can be null
|
||||
final String communityIcon;
|
||||
final bool communityRemoved;
|
||||
final bool communityDeleted;
|
||||
final bool communityNsfw;
|
||||
final int numberOfComments;
|
||||
final int score;
|
||||
final int upvotes;
|
||||
final int downvotes;
|
||||
final int hotRank;
|
||||
final int hotRankActive;
|
||||
final DateTime newestActivityTime;
|
||||
/// can be null
|
||||
final int userId;
|
||||
/// can be null
|
||||
final int myVote;
|
||||
/// can be null
|
||||
final bool subscribed;
|
||||
/// can be null
|
||||
final bool read;
|
||||
/// can be null
|
||||
final bool saved;
|
||||
|
||||
PostView({
|
||||
this.id,
|
||||
this.name,
|
||||
this.url,
|
||||
this.body,
|
||||
this.creatorId,
|
||||
this.communityId,
|
||||
this.removed,
|
||||
this.locked,
|
||||
this.published,
|
||||
this.updated,
|
||||
this.deleted,
|
||||
this.nsfw,
|
||||
this.stickied,
|
||||
this.embedTitle,
|
||||
this.embedDescription,
|
||||
this.embedHtml,
|
||||
this.thumbnailUrl,
|
||||
this.apId,
|
||||
this.local,
|
||||
this.creatorActorId,
|
||||
this.creatorLocal,
|
||||
this.creatorName,
|
||||
this.creatorPreferredUsername,
|
||||
this.creatorPublished,
|
||||
this.creatorAvatar,
|
||||
this.banned,
|
||||
this.bannedFromCommunity,
|
||||
this.communityActorId,
|
||||
this.communityLocal,
|
||||
this.communityName,
|
||||
this.communityIcon,
|
||||
this.communityRemoved,
|
||||
this.communityDeleted,
|
||||
this.communityNsfw,
|
||||
this.numberOfComments,
|
||||
this.score,
|
||||
this.upvotes,
|
||||
this.downvotes,
|
||||
this.hotRank,
|
||||
this.hotRankActive,
|
||||
this.newestActivityTime,
|
||||
this.userId,
|
||||
this.myVote,
|
||||
this.subscribed,
|
||||
this.read,
|
||||
this.saved,
|
||||
});
|
||||
|
||||
factory PostView.fromJson(Map<String, dynamic> json) =>
|
||||
_$PostViewFromJson(json);
|
||||
}
|
|
@ -1,164 +0,0 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:lemmur/mappingClasses/utility.dart';
|
||||
|
||||
part 'comment.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class CommentView {
|
||||
CommentView(
|
||||
this.id,
|
||||
this.creatorId,
|
||||
this.postId,
|
||||
this.postName,
|
||||
this.parentId,
|
||||
this.content,
|
||||
this.removed,
|
||||
bool read,
|
||||
this.published,
|
||||
this.updated,
|
||||
this.deleted,
|
||||
this.apId,
|
||||
this.local,
|
||||
this.communityId,
|
||||
this.communityActorId,
|
||||
this.communityLocal,
|
||||
this.communityName,
|
||||
this.banned,
|
||||
this.bannedFromCommunity,
|
||||
this.creatorActorId,
|
||||
this.creatorLocal,
|
||||
this.creatorName,
|
||||
this.creatorPublished,
|
||||
this.creatorAvatar,
|
||||
this.score,
|
||||
this.upvotes,
|
||||
this.downvotes,
|
||||
this.hotRank,
|
||||
int userId,
|
||||
int myVote,
|
||||
bool subscribed,
|
||||
bool saved,
|
||||
) {
|
||||
userId = userId;
|
||||
_myVote = myVote;
|
||||
_subscribed = subscribed;
|
||||
_read = read;
|
||||
_saved = saved;
|
||||
}
|
||||
|
||||
@JsonKey(name: "id")
|
||||
final int id;
|
||||
|
||||
@JsonKey(name: "creator_id")
|
||||
final int creatorId;
|
||||
|
||||
@JsonKey(name: "post_id")
|
||||
final int postId;
|
||||
|
||||
@JsonKey(name: "post_name")
|
||||
final String postName;
|
||||
|
||||
@JsonKey(name: "parent_id")
|
||||
final int parentId;
|
||||
|
||||
@JsonKey(name: "content")
|
||||
final String content;
|
||||
|
||||
@JsonKey(name: "removed")
|
||||
final bool removed;
|
||||
|
||||
bool get read => _read;
|
||||
|
||||
void set read(bool read) => _read = read;
|
||||
@JsonKey(name: "read")
|
||||
bool _read;
|
||||
|
||||
@JsonKey(name: "published", fromJson: UtilityClass.ParseDateFromJson)
|
||||
final DateTime published;
|
||||
|
||||
@JsonKey(name: "updated", fromJson: UtilityClass.ParseDateFromJson)
|
||||
final DateTime updated;
|
||||
|
||||
@JsonKey(name: "deleted")
|
||||
final bool deleted;
|
||||
|
||||
@JsonKey(name: "ap_id")
|
||||
final String apId;
|
||||
|
||||
@JsonKey(name: "local")
|
||||
final bool local;
|
||||
|
||||
@JsonKey(name: "community_id")
|
||||
final int communityId;
|
||||
|
||||
@JsonKey(name: "community_actor_id")
|
||||
final String communityActorId;
|
||||
|
||||
@JsonKey(name: "community_local")
|
||||
final bool communityLocal;
|
||||
|
||||
@JsonKey(name: "community_name")
|
||||
final String communityName;
|
||||
|
||||
@JsonKey(name: "banned")
|
||||
final bool banned;
|
||||
|
||||
@JsonKey(name: "banned_from_community")
|
||||
final bool bannedFromCommunity;
|
||||
|
||||
@JsonKey(name: "creator_actor_id")
|
||||
final String creatorActorId;
|
||||
|
||||
@JsonKey(name: "creator_local")
|
||||
final bool creatorLocal;
|
||||
|
||||
@JsonKey(name: "creator_name")
|
||||
final String creatorName;
|
||||
|
||||
@JsonKey(name: "creator_published", fromJson: UtilityClass.ParseDateFromJson)
|
||||
final DateTime creatorPublished;
|
||||
|
||||
@JsonKey(name: "creator_avatar")
|
||||
final String creatorAvatar;
|
||||
|
||||
@JsonKey(name: "score")
|
||||
int score;
|
||||
|
||||
@JsonKey(name: "upvotes")
|
||||
int upvotes;
|
||||
|
||||
@JsonKey(name: "downvotes")
|
||||
int downvotes;
|
||||
|
||||
@JsonKey(name: "hot_rank")
|
||||
final int hotRank;
|
||||
|
||||
int get userId => _userId;
|
||||
|
||||
void set userId(int userId) => _userId = userId;
|
||||
@JsonKey(name: "user_id")
|
||||
int _userId;
|
||||
|
||||
int get myVote => _myVote;
|
||||
|
||||
void set myVote(int myVote) => _myVote = myVote > 0 ? 1 : myVote < 0 ? -1 : 0;
|
||||
@JsonKey(name: "my_vote")
|
||||
int _myVote;
|
||||
|
||||
bool get subscribed => _subscribed;
|
||||
|
||||
void set subscribed(bool subscribed) => _subscribed = subscribed;
|
||||
@JsonKey(name: "subscribed")
|
||||
bool _subscribed;
|
||||
|
||||
bool get saved => _saved;
|
||||
|
||||
void set saved(bool saved) => _saved = saved;
|
||||
@JsonKey(name: "saved")
|
||||
bool _saved;
|
||||
|
||||
factory CommentView.fromJson(Map<String, dynamic> json) =>
|
||||
_$CommentViewFromJson(json);
|
||||
|
||||
Map<String, dynamic> commentViewToJson() => _$CommentViewToJson(this);
|
||||
}
|
|
@ -1,211 +0,0 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'utility.dart';
|
||||
|
||||
part 'post.g.dart';
|
||||
|
||||
//TODO: Add methods and fields for comments associated with post.
|
||||
@JsonSerializable()
|
||||
class PostView {
|
||||
PostView(
|
||||
this.id,
|
||||
this.postName,
|
||||
this.url,
|
||||
this.body,
|
||||
this.creatorId,
|
||||
this.communityId,
|
||||
this.removed,
|
||||
this.locked,
|
||||
this.published,
|
||||
this.updated,
|
||||
this.deleted,
|
||||
this.nsfw,
|
||||
this.stickied,
|
||||
this.embedTitle,
|
||||
this.embedDescription,
|
||||
this.embedHtml,
|
||||
this.thumbnailUrl,
|
||||
this.apId,
|
||||
this.local,
|
||||
this.creatorActorId,
|
||||
this.creatorLocal,
|
||||
this.creatorName,
|
||||
this.creatorPublished,
|
||||
this.creatorAvatar,
|
||||
this.banned,
|
||||
this.bannedFromCommunity,
|
||||
this.communityActorId,
|
||||
this.communityLocal,
|
||||
this.communityName,
|
||||
this.communityRemoved,
|
||||
this.communityDeleted,
|
||||
this.communityNsfw,
|
||||
this.numberOfComments,
|
||||
this.score,
|
||||
this.upvotes,
|
||||
this.downvotes,
|
||||
this.hotRank,
|
||||
this.newestActivityTime,
|
||||
int userId,
|
||||
int myVote,
|
||||
bool subscribed,
|
||||
bool read,
|
||||
bool saved,
|
||||
) {
|
||||
_userId = userId;
|
||||
_myVote = myVote;
|
||||
_subscribed = subscribed;
|
||||
_read = read;
|
||||
_saved = saved;
|
||||
}
|
||||
|
||||
@JsonKey(name: "id")
|
||||
final int id;
|
||||
|
||||
@JsonKey(name: "name")
|
||||
final String postName;
|
||||
|
||||
@JsonKey(name: "url")
|
||||
final String url;
|
||||
|
||||
@JsonKey(name: "body")
|
||||
final String body;
|
||||
|
||||
@JsonKey(name: "creator_id")
|
||||
final int creatorId;
|
||||
|
||||
@JsonKey(name: "community_id")
|
||||
final int communityId;
|
||||
|
||||
@JsonKey(name: "removed")
|
||||
final bool removed;
|
||||
|
||||
@JsonKey(name: "locked")
|
||||
final bool locked;
|
||||
|
||||
@JsonKey(name: "published", fromJson: UtilityClass.ParseDateFromJson)
|
||||
final DateTime published;
|
||||
|
||||
@JsonKey(name: "updated", fromJson: UtilityClass.ParseDateFromJson)
|
||||
final DateTime updated;
|
||||
|
||||
@JsonKey(name: "deleted")
|
||||
final bool deleted;
|
||||
|
||||
@JsonKey(name: "nsfw")
|
||||
final bool nsfw;
|
||||
|
||||
@JsonKey(name: "stickied")
|
||||
final bool stickied;
|
||||
|
||||
@JsonKey(name: "embed_title")
|
||||
final String embedTitle;
|
||||
|
||||
@JsonKey(name: "embed_description")
|
||||
final String embedDescription;
|
||||
|
||||
@JsonKey(name: "embed_html")
|
||||
final String embedHtml;
|
||||
|
||||
@JsonKey(name: "thumbnail_url")
|
||||
final String thumbnailUrl;
|
||||
|
||||
@JsonKey(name: "ap_id")
|
||||
final String apId;
|
||||
|
||||
@JsonKey(name: "local")
|
||||
final bool local;
|
||||
|
||||
@JsonKey(name: "creator_actor_id")
|
||||
final String creatorActorId;
|
||||
|
||||
@JsonKey(name: "creator_local")
|
||||
final bool creatorLocal;
|
||||
|
||||
@JsonKey(name: "creator_name")
|
||||
final String creatorName;
|
||||
|
||||
@JsonKey(name: "creator_published", fromJson: UtilityClass.ParseDateFromJson)
|
||||
final DateTime creatorPublished;
|
||||
|
||||
@JsonKey(name: "creator_avatar")
|
||||
final String creatorAvatar;
|
||||
|
||||
@JsonKey(name: "banned")
|
||||
final bool banned;
|
||||
|
||||
@JsonKey(name: "banned_from_community")
|
||||
final bool bannedFromCommunity;
|
||||
|
||||
@JsonKey(name: "community_actor_id")
|
||||
final String communityActorId;
|
||||
|
||||
@JsonKey(name: "community_local")
|
||||
final bool communityLocal;
|
||||
|
||||
@JsonKey(name: "community_name")
|
||||
final String communityName;
|
||||
|
||||
@JsonKey(name: "community_removed")
|
||||
final bool communityRemoved;
|
||||
|
||||
@JsonKey(name: "community_deleted")
|
||||
final bool communityDeleted;
|
||||
|
||||
@JsonKey(name: "community_nsfw")
|
||||
final bool communityNsfw;
|
||||
|
||||
@JsonKey(name: "number_of_comments")
|
||||
final int numberOfComments;
|
||||
|
||||
@JsonKey(name: "score")
|
||||
int score;
|
||||
|
||||
@JsonKey(name: "upvotes")
|
||||
int upvotes;
|
||||
|
||||
@JsonKey(name: "downvotes")
|
||||
int downvotes;
|
||||
|
||||
@JsonKey(name: "hot_rank")
|
||||
final int hotRank;
|
||||
|
||||
@JsonKey(
|
||||
name: "newest_activity_time", fromJson: UtilityClass.ParseDateFromJson)
|
||||
final DateTime newestActivityTime;
|
||||
|
||||
int get userId => _userId;
|
||||
|
||||
void set userId(int userId) => _userId = userId;
|
||||
@JsonKey(name: "user_id")
|
||||
int _userId;
|
||||
|
||||
int get myVote => _myVote;
|
||||
|
||||
void set myVote(int myVote) => _myVote = myVote > 0 ? 1 : myVote < 0 ? -1 : 0;
|
||||
@JsonKey(name: "my_vote")
|
||||
int _myVote;
|
||||
|
||||
bool get subscribed => _subscribed;
|
||||
|
||||
void set subscribed(bool subscribed) => _subscribed = subscribed;
|
||||
@JsonKey(name: "subscribed")
|
||||
bool _subscribed;
|
||||
|
||||
bool get read => _read;
|
||||
|
||||
void set read(bool read) => _read = read;
|
||||
@JsonKey(name: "read")
|
||||
bool _read;
|
||||
|
||||
bool get saved => _saved;
|
||||
|
||||
void set saved(bool saved) => _saved = saved;
|
||||
@JsonKey(name: "saved")
|
||||
bool _saved;
|
||||
|
||||
factory PostView.fromJson(Map<String, dynamic> json) =>
|
||||
_$PostViewFromJson(json);
|
||||
|
||||
Map<String, dynamic> postViewToJson() => _$PostViewToJson(this);
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
class UtilityClass {
|
||||
///Parses date from Json.
|
||||
///May return null on wrong argument
|
||||
static DateTime ParseDateFromJson(String t) {
|
||||
return DateTime.tryParse(t);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue