Implement 3 endpoints and add 1 model
endpoints: * createPostLike * getSite * getFollowedCommunities model: * FullSiteView
This commit is contained in:
parent
eeac5af15e
commit
8720272ee5
|
@ -1,5 +1,7 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../models/user.dart';
|
||||
|
||||
part 'site.g.dart';
|
||||
|
||||
/// based on https://github.com/LemmyNet/lemmy/blob/464ea862b10fa7b226b2550268e40d8e685a939c/server/lemmy_db/src/site_view.rs#L31
|
||||
|
@ -60,3 +62,26 @@ class SiteView {
|
|||
factory SiteView.fromJson(Map<String, dynamic> json) =>
|
||||
_$SiteViewFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake, createToJson: false)
|
||||
class FullSiteView {
|
||||
/// can be null
|
||||
final SiteView site;
|
||||
final List<UserView> admins;
|
||||
final List<UserView> banned;
|
||||
final int online;
|
||||
final String version;
|
||||
final UserView myUser;
|
||||
|
||||
FullSiteView({
|
||||
this.site,
|
||||
this.admins,
|
||||
this.banned,
|
||||
this.online,
|
||||
this.version,
|
||||
this.myUser,
|
||||
});
|
||||
|
||||
factory FullSiteView.fromJson(Map<String, dynamic> json) =>
|
||||
_$FullSiteViewFromJson(json);
|
||||
}
|
||||
|
|
|
@ -32,3 +32,24 @@ SiteView _$SiteViewFromJson(Map<String, dynamic> json) {
|
|||
numberOfCommunities: json['number_of_communities'] as int,
|
||||
);
|
||||
}
|
||||
|
||||
FullSiteView _$FullSiteViewFromJson(Map<String, dynamic> json) {
|
||||
return FullSiteView(
|
||||
site: json['site'] == null
|
||||
? null
|
||||
: SiteView.fromJson(json['site'] as Map<String, dynamic>),
|
||||
admins: (json['admins'] as List)
|
||||
?.map((e) =>
|
||||
e == null ? null : UserView.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
banned: (json['banned'] as List)
|
||||
?.map((e) =>
|
||||
e == null ? null : UserView.fromJson(e as Map<String, dynamic>))
|
||||
?.toList(),
|
||||
online: json['online'] as int,
|
||||
version: json['version'] as String,
|
||||
myUser: json['my_user'] == null
|
||||
? null
|
||||
: UserView.fromJson(json['my_user'] as Map<String, dynamic>),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:flutter/foundation.dart' show required;
|
||||
import 'package:lemmur/client/models/community.dart';
|
||||
|
||||
import '../models/community.dart';
|
||||
import 'main.dart';
|
||||
|
||||
extension CommunityEndpoint on V1 {
|
||||
|
@ -57,4 +57,17 @@ extension CommunityEndpoint on V1 {
|
|||
|
||||
return CommunityView.fromJson(res['community']);
|
||||
}
|
||||
|
||||
/// GET /user/followed_communities
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-followed-communities
|
||||
Future<List<CommunityFollowerView>> getFollowedCommunities({
|
||||
@required String auth,
|
||||
}) async {
|
||||
final res = await get('/user/followed_communities', {
|
||||
'auth': auth,
|
||||
});
|
||||
final List<dynamic> communities = res['communities'];
|
||||
|
||||
return communities.map((e) => CommunityFollowerView.fromJson(e)).toList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import '../models/search.dart';
|
|||
export 'comment_endpoint.dart';
|
||||
export 'community_endpoint.dart';
|
||||
export 'post_endpoint.dart';
|
||||
export 'site_endpoint.dart';
|
||||
export 'user_endpoint.dart';
|
||||
|
||||
class V1 with HttpHelper {
|
||||
|
|
|
@ -70,12 +70,18 @@ extension PostEndpoint on V1 {
|
|||
@required int postId,
|
||||
@required Vote score,
|
||||
@required String auth,
|
||||
}) {
|
||||
}) async {
|
||||
assert(postId != null);
|
||||
assert(score != null);
|
||||
assert(auth != null);
|
||||
|
||||
throw UnimplementedError();
|
||||
var res = await post('/post/like', {
|
||||
'post_id': postId,
|
||||
'score': score.value,
|
||||
'auth': auth,
|
||||
});
|
||||
|
||||
return PostView.fromJson(res);
|
||||
}
|
||||
|
||||
/// PUT /post
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
import '../models/site.dart';
|
||||
import '../v1/main.dart';
|
||||
|
||||
extension SiteEndpoint on V1 {
|
||||
/// GET /site
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-site
|
||||
Future<FullSiteView> getSite({String auth}) async {
|
||||
var res = await get('/site', {
|
||||
if (auth != null) 'auth': auth,
|
||||
});
|
||||
|
||||
return FullSiteView.fromJson(res);
|
||||
}
|
||||
|
||||
/// GET /site/config
|
||||
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-site-config
|
||||
/// admin stuff
|
||||
Future<String> getSiteConfig() {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue