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';
|
2021-02-22 03:36:25 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2021-02-21 17:31:03 +00:00
|
|
|
Stream<MediaItems$Query> mediaItems() {
|
|
|
|
return Stream.fromFuture(_apiProvider.mediaItems().then((QueryResult resp) {
|
|
|
|
final mediaItemsResponse = MediaItems$Query.fromJson(resp.data);
|
|
|
|
return mediaItemsResponse;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
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-02-22 03:36:25 +00:00
|
|
|
Future<CachedNetworkImage> getImage(String fileName, int derivedContentWidth) {
|
|
|
|
return _apiProvider.getImage(fileName, derivedContentWidth);
|
2021-02-21 17:31:03 +00:00
|
|
|
}
|
2021-02-11 20:47:42 +00:00
|
|
|
}
|