Solian/lib/providers/content/feed.dart

86 lines
2.1 KiB
Dart
Raw Normal View History

2024-05-18 10:17:16 +00:00
import 'package:get/get.dart';
2024-07-09 14:39:44 +00:00
import 'package:solian/providers/auth.dart';
2024-05-18 10:17:16 +00:00
import 'package:solian/services.dart';
2024-07-09 14:39:44 +00:00
class FeedProvider extends GetConnect {
2024-05-18 10:17:16 +00:00
@override
void onInit() {
httpClient.baseUrl = ServiceFinder.buildUrl('interactive', null);
2024-05-18 10:17:16 +00:00
}
2024-07-07 06:22:53 +00:00
Future<Response> listFeed(int page,
{int? realm, String? tag, category}) async {
2024-05-29 14:42:11 +00:00
final queries = [
'take=${10}',
'offset=$page',
2024-07-07 06:22:53 +00:00
if (tag != null) 'tag=$tag',
if (category != null) 'category=$category',
2024-05-29 14:42:11 +00:00
if (realm != null) 'realmId=$realm',
];
final resp = await get('/feed?${queries.join('&')}');
2024-05-25 05:19:16 +00:00
if (resp.statusCode != 200) {
throw Exception(resp.body);
}
return resp;
}
2024-07-09 14:39:44 +00:00
Future<Response> listDraft(int page) async {
final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) throw Exception('unauthorized');
final queries = [
'take=${10}',
'offset=$page',
];
final client = auth.configureClient('interactive');
final resp = await client.get('/drafts?${queries.join('&')}');
2024-07-09 14:39:44 +00:00
if (resp.statusCode != 200) {
throw Exception(resp.body);
}
return resp;
}
Future<Response> listPost(int page, {int? realm}) async {
final queries = [
'take=${10}',
'offset=$page',
if (realm != null) 'realmId=$realm',
];
final resp = await get('/posts?${queries.join('&')}');
if (resp.statusCode != 200) {
throw Exception(resp.body);
}
return resp;
}
2024-05-25 09:21:27 +00:00
Future<Response> listPostReplies(String alias, int page) async {
final resp = await get('/posts/$alias/replies?take=${10}&offset=$page');
2024-05-25 09:21:27 +00:00
if (resp.statusCode != 200) {
throw Exception(resp.body);
}
return resp;
}
2024-05-25 05:19:16 +00:00
Future<Response> getPost(String alias) async {
final resp = await get('/posts/$alias');
2024-05-25 05:19:16 +00:00
if (resp.statusCode != 200) {
throw Exception(resp.body);
}
return resp;
}
2024-07-10 02:50:10 +00:00
Future<Response> getArticle(String alias) async {
final resp = await get('/articles/$alias');
2024-07-10 02:50:10 +00:00
if (resp.statusCode != 200) {
throw Exception(resp.body);
}
return resp;
}
2024-05-18 10:17:16 +00:00
}