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-03-01 00:23:41 +00:00
|
|
|
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-03-01 00:23:41 +00:00
|
|
|
Future<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
|
|
|
}
|