2023-04-30 09:43:59 -04:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2023-10-03 13:00:59 -04:00
|
|
|
import 'package:recon/clients/api_client.dart';
|
|
|
|
import 'package:recon/models/personal_profile.dart';
|
|
|
|
import 'package:recon/models/users/user.dart';
|
|
|
|
import 'package:recon/models/users/user_status.dart';
|
2023-04-30 09:43:59 -04:00
|
|
|
|
|
|
|
class UserApi {
|
|
|
|
static Future<Iterable<User>> searchUsers(ApiClient client, {required String needle}) async {
|
|
|
|
final response = await client.get("/users?name=$needle");
|
2023-05-25 09:50:38 -04:00
|
|
|
client.checkResponse(response);
|
2023-04-30 09:43:59 -04:00
|
|
|
final data = jsonDecode(response.body) as List;
|
|
|
|
return data.map((e) => User.fromMap(e));
|
|
|
|
}
|
2023-05-05 05:29:54 -04:00
|
|
|
|
|
|
|
static Future<User> getUser(ApiClient client, {required String userId}) async {
|
|
|
|
final response = await client.get("/users/$userId/");
|
2023-05-25 09:50:38 -04:00
|
|
|
client.checkResponse(response);
|
2023-05-05 05:29:54 -04:00
|
|
|
final data = jsonDecode(response.body);
|
|
|
|
return User.fromMap(data);
|
|
|
|
}
|
2023-05-04 14:57:16 -04:00
|
|
|
|
2023-05-05 10:39:40 -04:00
|
|
|
static Future<UserStatus> getUserStatus(ApiClient client, {required String userId}) async {
|
2023-09-29 03:51:46 -04:00
|
|
|
return UserStatus.empty();
|
2023-05-05 10:39:40 -04:00
|
|
|
final response = await client.get("/users/$userId/status");
|
2023-05-25 09:50:38 -04:00
|
|
|
client.checkResponse(response);
|
2023-05-05 10:39:40 -04:00
|
|
|
final data = jsonDecode(response.body);
|
|
|
|
return UserStatus.fromMap(data);
|
|
|
|
}
|
2023-05-06 12:34:14 -04:00
|
|
|
|
|
|
|
static Future<void> notifyOnlineInstance(ApiClient client) async {
|
2023-09-29 03:51:46 -04:00
|
|
|
final response = await client.post("/stats/instanceOnline/${client.authenticationData.secretMachineIdHash}");
|
2023-05-25 09:50:38 -04:00
|
|
|
client.checkResponse(response);
|
2023-05-06 12:34:14 -04:00
|
|
|
}
|
2023-05-05 10:39:40 -04:00
|
|
|
|
2023-05-05 09:05:06 -04:00
|
|
|
static Future<PersonalProfile> getPersonalProfile(ApiClient client) async {
|
|
|
|
final response = await client.get("/users/${client.userId}");
|
2023-05-25 09:50:38 -04:00
|
|
|
client.checkResponse(response);
|
2023-05-05 09:05:06 -04:00
|
|
|
final data = jsonDecode(response.body);
|
|
|
|
return PersonalProfile.fromMap(data);
|
|
|
|
}
|
2023-10-10 04:33:51 -04:00
|
|
|
|
|
|
|
static Future<StorageQuota> getStorageQuota(ApiClient client) async {
|
|
|
|
final response = await client.get("/users/${client.userId}/storage");
|
|
|
|
client.checkResponse(response);
|
|
|
|
final data = jsonDecode(response.body);
|
|
|
|
return StorageQuota.fromMap(data);
|
|
|
|
}
|
2023-04-30 09:43:59 -04:00
|
|
|
}
|