2024-05-18 10:17:16 +00:00
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:solian/services.dart';
|
|
|
|
|
2024-05-25 05:19:16 +00:00
|
|
|
class PostProvider extends GetConnect {
|
2024-05-18 10:17:16 +00:00
|
|
|
@override
|
|
|
|
void onInit() {
|
|
|
|
httpClient.baseUrl = ServiceFinder.services['interactive'];
|
|
|
|
}
|
|
|
|
|
2024-07-07 03:46:48 +00:00
|
|
|
Future<Response> listFeed(int page, {int? realm}) async {
|
2024-05-29 14:42:11 +00:00
|
|
|
final queries = [
|
|
|
|
'take=${10}',
|
|
|
|
'offset=$page',
|
|
|
|
if (realm != null) 'realmId=$realm',
|
|
|
|
];
|
|
|
|
final resp = await get('/api/feed?${queries.join('&')}');
|
2024-05-25 05:19:16 +00:00
|
|
|
if (resp.statusCode != 200) {
|
|
|
|
throw Exception(resp.body);
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp;
|
|
|
|
}
|
|
|
|
|
2024-07-07 03:46:48 +00:00
|
|
|
Future<Response> listPost(int page, {int? realm}) async {
|
|
|
|
final queries = [
|
|
|
|
'take=${10}',
|
|
|
|
'offset=$page',
|
|
|
|
if (realm != null) 'realmId=$realm',
|
|
|
|
];
|
|
|
|
final resp = await get('/api/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('/api/posts/$alias/replies?take=${10}&offset=$page');
|
|
|
|
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('/api/posts/$alias');
|
|
|
|
if (resp.statusCode != 200) {
|
|
|
|
throw Exception(resp.body);
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp;
|
|
|
|
}
|
2024-05-18 10:17:16 +00:00
|
|
|
}
|