diff --git a/web_native/build.yaml b/web_native/build.yaml index 6a6f1c5..13742b3 100644 --- a/web_native/build.yaml +++ b/web_native/build.yaml @@ -10,7 +10,7 @@ targets: schema_mapping: - schema: schema.graphqls queries_glob: graphql/*.graphql - output: lib/graphql/imgagini_graphql.dart + output: lib/graphql/imagini_graphql.dart scalar_mapping: - graphql_type: Upload custom_parser_import: 'package:imagini/helpers/upload_serializer.dart' diff --git a/web_native/lib/api/api_provider.dart b/web_native/lib/api/api_provider.dart index 8db8c68..1ae9972 100644 --- a/web_native/lib/api/api_provider.dart +++ b/web_native/lib/api/api_provider.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:convert'; // ignore: uri_does_not_exist import 'cookie_client_stub.dart' @@ -11,7 +10,7 @@ import 'cookie_client_stub.dart' import 'package:meta/meta.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; -import 'package:imagini/models/api/response/login_response.dart'; +import 'package:imagini/graphql/imagini_graphql.dart'; class APIProvider{ String _server, _accessToken, _refreshToken; @@ -50,7 +49,7 @@ class APIProvider{ // this._refreshToken = _refreshToken; // } - Future login([ + Future login([ String username, String password, ]) async { @@ -58,20 +57,10 @@ class APIProvider{ (username != null && password != null) || (_accessToken != null && _refreshToken != null) ); - String loginQuery = """ - query login(\$user: String!, \$password: String!, \$deviceID: ID) { - login(user: \$user, password: \$password, deviceID: \$deviceID) { - result, - device { - id - } - } - }"""; - QueryResult response = await _client.query( QueryOptions( - document: gql(loginQuery), + document: LoginQuery().document, variables: { "user": "admin", "password": "admin" @@ -79,7 +68,10 @@ class APIProvider{ ) ); - return LoginResponse.fromJson(jsonDecode("{}")); + final loginResponse = Login$Query.fromJson(response.data); + print(loginResponse); + + return loginResponse.login; } void logout() { diff --git a/web_native/lib/api/imagini_api_repository.dart b/web_native/lib/api/imagini_api_repository.dart index 93da23f..32bb3e8 100644 --- a/web_native/lib/api/imagini_api_repository.dart +++ b/web_native/lib/api/imagini_api_repository.dart @@ -1,12 +1,12 @@ import 'package:imagini/api/api_provider.dart'; -import 'package:imagini/models/api/response/login_response.dart'; +import 'package:imagini/graphql/imagini_graphql.dart'; class ImaginiAPIRepository { APIProvider _apiProvider; ImaginiAPIRepository(this._apiProvider); - Stream login(String user, password) { + Stream login(String user, password) { return Stream.fromFuture(_apiProvider.login(user, password)); } } diff --git a/web_native/lib/blocs/splash_bloc.dart b/web_native/lib/blocs/splash_bloc.dart index 739a0bc..27a546b 100644 --- a/web_native/lib/blocs/splash_bloc.dart +++ b/web_native/lib/blocs/splash_bloc.dart @@ -3,14 +3,14 @@ import 'dart:async'; import 'package:imagini/core/imagini_application.dart'; import 'package:imagini/api/imagini_api_repository.dart'; -import 'package:imagini/models/api/response/login_response.dart'; +import 'package:imagini/graphql/imagini_graphql.dart'; class SplashBloc{ final ImaginiApplication _application; - final _loginController = StreamController(); - Stream get loginResult => _loginController.stream; + final _loginController = StreamController(); + Stream get loginResult => _loginController.stream; SplashBloc(this._application){ _init(); diff --git a/web_native/lib/graphql/imgagini_graphql.dart b/web_native/lib/graphql/imagini_graphql.dart similarity index 51% rename from web_native/lib/graphql/imgagini_graphql.dart rename to web_native/lib/graphql/imagini_graphql.dart index 379ac10..d8c695b 100644 --- a/web_native/lib/graphql/imgagini_graphql.dart +++ b/web_native/lib/graphql/imagini_graphql.dart @@ -1,2 +1,2 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -export 'imgagini_graphql.graphql.dart'; +export 'imagini_graphql.graphql.dart'; diff --git a/web_native/lib/graphql/imgagini_graphql.graphql.dart b/web_native/lib/graphql/imagini_graphql.graphql.dart similarity index 99% rename from web_native/lib/graphql/imgagini_graphql.graphql.dart rename to web_native/lib/graphql/imagini_graphql.graphql.dart index 367b020..0c5c808 100644 --- a/web_native/lib/graphql/imgagini_graphql.graphql.dart +++ b/web_native/lib/graphql/imagini_graphql.graphql.dart @@ -7,7 +7,7 @@ import 'package:equatable/equatable.dart'; import 'package:gql/ast.dart'; import 'package:http/http.dart'; import 'package:imagini/helpers/upload_serializer.dart'; -part 'imgagini_graphql.graphql.g.dart'; +part 'imagini_graphql.graphql.g.dart'; @JsonSerializable(explicitToJson: true) class Login$Query$AuthResponse$Device with EquatableMixin { diff --git a/web_native/lib/graphql/imgagini_graphql.graphql.g.dart b/web_native/lib/graphql/imagini_graphql.graphql.g.dart similarity index 99% rename from web_native/lib/graphql/imgagini_graphql.graphql.g.dart rename to web_native/lib/graphql/imagini_graphql.graphql.g.dart index 219936f..6095870 100644 --- a/web_native/lib/graphql/imgagini_graphql.graphql.g.dart +++ b/web_native/lib/graphql/imagini_graphql.graphql.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'imgagini_graphql.graphql.dart'; +part of 'imagini_graphql.graphql.dart'; // ************************************************************************** // JsonSerializableGenerator diff --git a/web_native/lib/screens/login_screen.dart b/web_native/lib/screens/login_screen.dart index eb344c3..ab2a573 100644 --- a/web_native/lib/screens/login_screen.dart +++ b/web_native/lib/screens/login_screen.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; import 'package:fluro/fluro.dart'; import 'package:flutter_platform_widgets/flutter_platform_widgets.dart'; -import 'package:imagini/core/AppProvider.dart'; +import 'package:imagini/core/app_provider.dart'; class LoginScreen extends StatefulWidget { static const String PATH = '/Login'; diff --git a/web_native/lib/screens/splash_screen.dart b/web_native/lib/screens/splash_screen.dart index 1a3a36a..c756aa4 100644 --- a/web_native/lib/screens/splash_screen.dart +++ b/web_native/lib/screens/splash_screen.dart @@ -2,9 +2,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_platform_widgets/flutter_platform_widgets.dart'; import 'package:fluro/fluro.dart'; -import 'package:imagini/models/api/response/LoginResponse.dart'; -import 'package:imagini/core/AppProvider.dart'; -import 'package:imagini/blocs/SplashBloc.dart'; +import 'package:imagini/core/app_provider.dart'; +import 'package:imagini/blocs/splash_bloc.dart'; +import 'package:imagini/graphql/imagini_graphql.dart'; class SplashScreen extends StatefulWidget { static const String PATH = '/'; @@ -58,11 +58,11 @@ class _SplashScreenState extends State { void _init(){ if(null == bloc){ bloc = SplashBloc(AppProvider.getApplication(context)); - bloc.loginResult.listen((LoginResponse lr) { - if (lr.error != null) { - AppProvider.getRouter(context).navigateTo(context, "/Login", transition: TransitionType.fadeIn); - } else { + bloc.loginResult.listen((Login$Query$AuthResponse lr) { + if (lr.result != AuthResult.success) { AppProvider.getRouter(context).navigateTo(context, "/Home", transition: TransitionType.fadeIn); + } else { + AppProvider.getRouter(context).navigateTo(context, "/Login", transition: TransitionType.fadeIn); } }); }