mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 17:26:35 +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:graphql/client.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.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/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/api_maps/graphql_maps/schema/get_api_version.graphql.dart';
|
||||||
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/json/api_token.dart';
|
||||||
|
|
||||||
class ServerApi extends ApiMap {
|
class ServerApi extends ApiMap {
|
||||||
ServerApi({
|
ServerApi({
|
||||||
|
@ -24,10 +26,9 @@ class ServerApi extends ApiMap {
|
||||||
|
|
||||||
Future<String?> getApiVersion() async {
|
Future<String?> getApiVersion() async {
|
||||||
QueryResult response;
|
QueryResult response;
|
||||||
|
|
||||||
final GraphQLClient client = await getClient();
|
|
||||||
String? apiVersion;
|
String? apiVersion;
|
||||||
|
|
||||||
|
final GraphQLClient client = await getClient();
|
||||||
try {
|
try {
|
||||||
response = await client.query$GetApiVersionQuery();
|
response = await client.query$GetApiVersionQuery();
|
||||||
apiVersion = response.data!['api']['version'];
|
apiVersion = response.data!['api']['version'];
|
||||||
|
@ -36,4 +37,21 @@ class ServerApi extends ApiMap {
|
||||||
}
|
}
|
||||||
return apiVersion;
|
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