Add presentation layer for get Session
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/repository/credential_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/usecases/delete_credential_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/session/data/datasource/session_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/session/data/datasource_impl/session_datasource_impl.dart';
|
||||
import 'package:tmail_ui_user/features/session/data/network/session_api.dart';
|
||||
import 'package:tmail_ui_user/features/session/data/repository/session_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/session/domain/repository/session_repository.dart';
|
||||
import 'package:tmail_ui_user/features/session/domain/usecases/get_session_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/session/presentation/session_controller.dart';
|
||||
|
||||
class SessionBindings extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut(() => SessionDataSourceImpl(Get.find<SessionAPI>()));
|
||||
Get.lazyPut<SessionDataSource>(() => Get.find<SessionDataSourceImpl>());
|
||||
Get.lazyPut(() => SessionRepositoryImpl(Get.find<SessionDataSource>()));
|
||||
Get.lazyPut<SessionRepository>(() => Get.find<SessionRepositoryImpl>());
|
||||
Get.lazyPut(() => GetSessionInteractor(Get.find<SessionRepository>()));
|
||||
Get.lazyPut(() => CredentialRepositoryImpl(Get.find<SharedPreferences>()));
|
||||
Get.lazyPut<CredentialRepository>(() => Get.find<CredentialRepositoryImpl>());
|
||||
Get.lazyPut(() => DeleteCredentialInteractor(Get.find<CredentialRepository>()));
|
||||
Get.lazyPut(() => SessionController(Get.find<GetSessionInteractor>(), Get.find<DeleteCredentialInteractor>()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/usecases/delete_credential_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/session/domain/state/get_session_state.dart';
|
||||
import 'package:tmail_ui_user/features/session/domain/usecases/get_session_interactor.dart';
|
||||
import 'package:tmail_ui_user/main/routes/app_routes.dart';
|
||||
|
||||
class SessionController extends GetxController {
|
||||
final GetSessionInteractor _getSessionInteractor;
|
||||
final DeleteCredentialInteractor _deleteCredentialInteractor;
|
||||
|
||||
SessionController(this._getSessionInteractor, this._deleteCredentialInteractor);
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
_getSession();
|
||||
}
|
||||
|
||||
void _getSession() async {
|
||||
await _getSessionInteractor.execute()
|
||||
.then((response) => response.fold(
|
||||
(failure) => _goToLogin(),
|
||||
(success) => success is GetSessionSuccess ? _goToMailboxDashBoard(success) : _goToLogin()));
|
||||
}
|
||||
|
||||
void _deleteCredential() async {
|
||||
await _deleteCredentialInteractor.execute();
|
||||
}
|
||||
|
||||
void _goToLogin() {
|
||||
_deleteCredential();
|
||||
Get.offNamed(AppRoutes.LOGIN);
|
||||
}
|
||||
|
||||
void _goToMailboxDashBoard(GetSessionSuccess getSessionSuccess) {
|
||||
Get.offNamed(AppRoutes.MAILBOX_DASHBOARD, arguments: getSessionSuccess.session);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tmail_ui_user/features/session/presentation/session_controller.dart';
|
||||
|
||||
class SessionView extends GetWidget<SessionController> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
color: AppColor.primaryColor,
|
||||
child: SizedBox(
|
||||
width: 100,
|
||||
height: 100,
|
||||
child: CupertinoActivityIndicator(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user