Added FullPost, Search, and UserDetails #1

This commit is contained in:
shilangyu 2020-08-10 14:47:05 +00:00
parent e0a149f688
commit 51cc332f7c
3 changed files with 78 additions and 0 deletions

View File

@ -1,5 +1,8 @@
import 'package:json_annotation/json_annotation.dart';
import './comment.dart';
import './community.dart';
part 'post.g.dart';
/// based on https://github.com/LemmyNet/lemmy/blob/464ea862b10fa7b226b2550268e40d8e685a939c/server/lemmy_db/src/post_view.rs#L113
@ -134,3 +137,22 @@ class PostView {
factory PostView.fromJson(Map<String, dynamic> json) =>
_$PostViewFromJson(json);
}
/// based on https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-post
@JsonSerializable(createToJson: false)
class FullPost {
final PostView post;
final List<CommentView> comments;
final CommunityView community;
final List<CommunityModeratorView> moderators;
const FullPost({
this.post,
this.comments,
this.community,
this.moderators,
});
factory FullPost.fromJson(Map<String, dynamic> json) =>
_$FullPostFromJson(json);
}

View File

@ -0,0 +1,30 @@
import 'package:json_annotation/json_annotation.dart';
import './comment.dart';
import './post.dart';
import './community.dart';
import './user.dart';
part 'search.g.dart';
/// based on https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#search
@JsonSerializable(createToJson: false)
class Search {
final String type_;
final List<CommentView> comments;
final List<PostView> posts;
final List<CommunityView> communities;
final List<UserView> users;
const Search({
this.type_,
this.comments,
this.posts,
this.communities,
this.users,
});
factory Search.fromJson(Map<String, dynamic> json) =>
_$SearchFromJson(json);
}

View File

@ -1,5 +1,9 @@
import 'package:json_annotation/json_annotation.dart';
import './comment.dart';
import './post.dart';
import './community.dart';
part 'user.g.dart';
/// based on https://github.com/LemmyNet/lemmy/blob/464ea862b10fa7b226b2550268e40d8e685a939c/server/lemmy_db/src/user_view.rs#L58
@ -159,3 +163,25 @@ class UserMentionView {
factory UserMentionView.fromJson(Map<String, dynamic> json) =>
_$UserMentionViewFromJson(json);
}
/// based on https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-user-details
@JsonSerializable(createToJson: false)
class UserDetails {
final UserView user;
final List<CommunityFollowerView> follows;
final List<CommunityModeratorView> moderates;
final List<CommentView> comments;
final List<PostView> posts;
const UserDetails({
this.user,
this.follows,
this.moderates,
this.comments,
this.posts,
});
factory UserDetails.fromJson(Map<String, dynamic> json) =>
_$UserDetailsFromJson(json);
}