mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 09:16:54 +00:00
Implement getApiTokens for graphql API map
This commit is contained in:
parent
7ead9a29ea
commit
c56a0f5976
|
@ -1,8 +1,10 @@
|
|||
import 'package:graphql/client.dart';
|
||||
import 'package:selfprivacy/config/get_it_config.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/graphql_maps/api_map.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/graphql_maps/schema/get_api_tokens.graphql.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/graphql_maps/schema/get_api_version.graphql.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||
import 'package:selfprivacy/logic/models/json/api_token.dart';
|
||||
|
||||
class ServerApi extends ApiMap {
|
||||
ServerApi({
|
||||
|
@ -24,10 +26,9 @@ class ServerApi extends ApiMap {
|
|||
|
||||
Future<String?> getApiVersion() async {
|
||||
QueryResult response;
|
||||
|
||||
final GraphQLClient client = await getClient();
|
||||
String? apiVersion;
|
||||
|
||||
final GraphQLClient client = await getClient();
|
||||
try {
|
||||
response = await client.query$GetApiVersionQuery();
|
||||
apiVersion = response.data!['api']['version'];
|
||||
|
@ -36,4 +37,21 @@ class ServerApi extends ApiMap {
|
|||
}
|
||||
return apiVersion;
|
||||
}
|
||||
|
||||
Future<List<ApiToken>> getApiTokens() async {
|
||||
QueryResult response;
|
||||
List<ApiToken> tokens = [];
|
||||
|
||||
try {
|
||||
final GraphQLClient client = await getClient();
|
||||
response = await client.query$GetApiTokensQuery();
|
||||
tokens = response.data!['api']['devices']
|
||||
.map<ApiToken>((final e) => ApiToken.fromJson(e))
|
||||
.toList();
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
|
||||
return tokens;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue