Solian/lib/providers/friend.dart

44 lines
1.2 KiB
Dart
Raw Normal View History

2024-05-23 13:12:47 +00:00
import 'package:get/get.dart';
import 'package:solian/models/friendship.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/services.dart';
class FriendProvider extends GetConnect {
@override
void onInit() {
final AuthProvider auth = Get.find();
httpClient.baseUrl = ServiceFinder.buildUrl('auth', null);
httpClient.addAuthenticator(auth.requestAuthenticator);
2024-05-23 13:12:47 +00:00
}
Future<Response> listFriendship() => get('/users/me/friends');
2024-05-23 13:12:47 +00:00
2024-05-25 16:11:00 +00:00
Future<Response> listFriendshipWithStatus(int status) =>
get('/users/me/friends?status=$status');
2024-05-25 16:11:00 +00:00
2024-05-23 13:12:47 +00:00
Future<Response> createFriendship(String username) async {
final resp = await post('/users/me/friends?related=$username', {});
2024-05-23 13:12:47 +00:00
if (resp.statusCode != 200) {
throw Exception(resp.bodyString);
}
return resp;
}
Future<Response> updateFriendship(Friendship relationship, int status) async {
final AuthProvider auth = Get.find();
final prof = await auth.getProfile();
final otherside = relationship.getOtherside(prof.body['id']);
final resp = await put('/users/me/friends/${otherside.id}', {
2024-05-23 13:12:47 +00:00
'status': status,
});
if (resp.statusCode != 200) {
throw Exception(resp.bodyString);
}
return resp;
}
}