OpenContacts/lib/apis/friend_api.dart

20 lines
728 B
Dart
Raw Normal View History

2023-04-29 15:26:12 -04:00
import 'dart:convert';
2023-05-01 13:13:40 -04:00
import 'package:contacts_plus_plus/api_client.dart';
import 'package:contacts_plus_plus/models/friend.dart';
import 'package:contacts_plus_plus/models/user.dart';
2023-04-29 15:26:12 -04:00
2023-04-30 07:39:09 -04:00
class FriendApi {
static Future<Iterable<Friend>> getFriendsList(ApiClient client) async {
final response = await client.get("/users/${client.userId}/friends");
2023-04-29 15:26:12 -04:00
ApiClient.checkResponse(response);
final data = jsonDecode(response.body) as List;
return data.map((e) => Friend.fromMap(e));
}
2023-04-30 17:14:29 -04:00
static Future<void> addFriend(ApiClient client, {required User user}) async {
final response = await client.put("/users/${client.userId}/friends/${user.id}", body: user.toMap());
ApiClient.checkResponse(response);
}
2023-04-29 15:26:12 -04:00
}