This repository has been archived on 2023-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
imagini/web_native/lib/api/imagini_api_repository.dart

46 lines
1.3 KiB
Dart
Raw Normal View History

2021-02-20 19:10:25 +00:00
import 'dart:async';
2021-02-11 20:47:42 +00:00
import 'package:imagini/api/api_provider.dart';
import 'package:imagini/graphql/imagini_graphql.dart';
2021-02-20 19:10:25 +00:00
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:cached_network_image/cached_network_image.dart';
2021-02-11 20:47:42 +00:00
class ImaginiAPIRepository {
APIProvider _apiProvider;
ImaginiAPIRepository(this._apiProvider);
2021-02-20 19:10:25 +00:00
Stream<bool> login(String user, password, server) {
return Stream.fromFuture(_apiProvider.login(user, password, server).then((QueryResult resp) {
if (resp.exception != null)
return false;
final loginResponse = Login$Query.fromJson(resp.data);
if (loginResponse.login.result == AuthResult.failure)
return false;
return true;
}));
}
Stream<QueryResult> me() {
return Stream.fromFuture(_apiProvider.me());
}
Future<MediaItems$Query> mediaItems(Page page) async {
QueryResult allItems = await _apiProvider.mediaItems(page);
return MediaItems$Query.fromJson(allItems.data);
2021-02-21 17:31:03 +00:00
}
2021-02-20 19:10:25 +00:00
Stream<bool> isAuthenticated() {
return Stream.fromFuture(_apiProvider.me().then((QueryResult resp) {
if (resp.exception != null)
return false;
return true;
}));
2021-02-11 20:47:42 +00:00
}
2021-02-21 17:31:03 +00:00
2021-04-06 00:40:23 +00:00
CachedNetworkImage getImage(String fileName, int width, int height) {
return _apiProvider.getImage(fileName, width, height);
2021-02-21 17:31:03 +00:00
}
2021-02-11 20:47:42 +00:00
}