mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
Merge pull request #405 from MikeWallaceDev/put_business_logic_in_services2
Put business logic in services2
This commit is contained in:
commit
0e8ac4828b
@ -2,11 +2,11 @@ import 'dart:io';
|
||||
|
||||
import 'package:app_flowy/plugin/plugin.dart';
|
||||
import 'package:app_flowy/startup/tasks/prelude.dart';
|
||||
import 'package:app_flowy/startup/home_deps_resolver.dart';
|
||||
import 'package:app_flowy/startup/user_deps_resolver.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:app_flowy/startup/deps_resolver.dart';
|
||||
import 'package:app_flowy/user/infrastructure/deps_resolver.dart';
|
||||
import 'package:flowy_sdk/flowy_sdk.dart';
|
||||
|
||||
// [[diagram: flowy startup flow]]
|
||||
|
@ -1,5 +1,5 @@
|
||||
import 'package:app_flowy/startup/startup.dart';
|
||||
import 'package:app_flowy/user/infrastructure/repos/user_setting_repo.dart';
|
||||
import 'package:app_flowy/user/application/user_settings_service.dart';
|
||||
import 'package:app_flowy/workspace/application/appearance.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flowy_infra/theme.dart';
|
||||
@ -17,7 +17,7 @@ class InitAppWidgetTask extends LaunchTask {
|
||||
@override
|
||||
Future<void> initialize(LaunchContext context) async {
|
||||
final widget = context.getIt<EntryPoint>().create();
|
||||
final setting = await UserSettingReppsitory().getAppearanceSettings();
|
||||
final setting = await UserSettingsService().getAppearanceSettings();
|
||||
final settingModel = AppearanceSettingModel(setting);
|
||||
final app = ApplicationWidget(
|
||||
child: widget,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import 'package:app_flowy/user/infrastructure/network_monitor.dart';
|
||||
import 'package:app_flowy/core/network_monitor.dart';
|
||||
import '../startup.dart';
|
||||
|
||||
class InitPlatformServiceTask extends LaunchTask {
|
||||
|
@ -1,24 +1,24 @@
|
||||
import 'package:app_flowy/user/application/auth_service.dart';
|
||||
import 'package:app_flowy/user/application/sign_in_bloc.dart';
|
||||
import 'package:app_flowy/user/application/sign_up_bloc.dart';
|
||||
import 'package:app_flowy/user/application/splash_bloc.dart';
|
||||
import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart';
|
||||
import 'package:app_flowy/user/infrastructure/router.dart';
|
||||
import 'package:app_flowy/user/presentation/router.dart';
|
||||
import 'package:app_flowy/workspace/application/edit_pannel/edit_pannel_bloc.dart';
|
||||
import 'package:app_flowy/workspace/application/home/home_bloc.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
|
||||
import 'network_monitor.dart';
|
||||
import '../core/network_monitor.dart';
|
||||
|
||||
class UserDepsResolver {
|
||||
static Future<void> resolve(GetIt getIt) async {
|
||||
getIt.registerFactory<AuthRepository>(() => AuthRepository());
|
||||
getIt.registerFactory<AuthService>(() => AuthService());
|
||||
|
||||
//Interface implementation
|
||||
getIt.registerFactory<AuthRouter>(() => AuthRouter());
|
||||
|
||||
//Bloc
|
||||
getIt.registerFactory<SignInBloc>(() => SignInBloc(getIt<AuthRepository>()));
|
||||
getIt.registerFactory<SignUpBloc>(() => SignUpBloc(getIt<AuthRepository>()));
|
||||
getIt.registerFactory<SignInBloc>(() => SignInBloc(getIt<AuthService>()));
|
||||
getIt.registerFactory<SignUpBloc>(() => SignUpBloc(getIt<AuthService>()));
|
||||
|
||||
getIt.registerFactory<SplashRoute>(() => SplashRoute());
|
||||
getIt.registerFactory<HomeBloc>(() => HomeBloc());
|
@ -3,7 +3,7 @@ import 'package:flowy_sdk/dispatch/dispatch.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show SignInPayload, SignUpPayload, UserProfile;
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
|
||||
class AuthRepository {
|
||||
class AuthService {
|
||||
Future<Either<UserProfile, FlowyError>> signIn({required String? email, required String? password}) {
|
||||
//
|
||||
final request = SignInPayload.create()
|
@ -1,4 +1,4 @@
|
||||
import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart';
|
||||
import 'package:app_flowy/user/application/auth_service.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show UserProfile, ErrorCode;
|
||||
@ -8,8 +8,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
part 'sign_in_bloc.freezed.dart';
|
||||
|
||||
class SignInBloc extends Bloc<SignInEvent, SignInState> {
|
||||
final AuthRepository authRepo;
|
||||
SignInBloc(this.authRepo) : super(SignInState.initial()) {
|
||||
final AuthService authService;
|
||||
SignInBloc(this.authService) : super(SignInState.initial()) {
|
||||
on<SignInEvent>((event, emit) async {
|
||||
await event.map(
|
||||
signedInWithUserEmailAndPassword: (e) async {
|
||||
@ -31,7 +31,7 @@ class SignInBloc extends Bloc<SignInEvent, SignInState> {
|
||||
Future<void> _performActionOnSignIn(SignInState state, Emitter<SignInState> emit) async {
|
||||
emit(state.copyWith(isSubmitting: true, emailError: none(), passwordError: none(), successOrFail: none()));
|
||||
|
||||
final result = await authRepo.signIn(
|
||||
final result = await authService.signIn(
|
||||
email: state.email,
|
||||
password: state.password,
|
||||
);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart';
|
||||
import 'package:app_flowy/user/application/auth_service.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart' show UserProfile, ErrorCode;
|
||||
@ -10,8 +10,8 @@ import 'package:app_flowy/generated/locale_keys.g.dart';
|
||||
part 'sign_up_bloc.freezed.dart';
|
||||
|
||||
class SignUpBloc extends Bloc<SignUpEvent, SignUpState> {
|
||||
final AuthRepository autoRepo;
|
||||
SignUpBloc(this.autoRepo) : super(SignUpState.initial()) {
|
||||
final AuthService authService;
|
||||
SignUpBloc(this.authService) : super(SignUpState.initial()) {
|
||||
on<SignUpEvent>((event, emit) async {
|
||||
await event.map(signUpWithUserEmailAndPassword: (e) async {
|
||||
await _performActionOnSignUp(emit);
|
||||
@ -62,7 +62,7 @@ class SignUpBloc extends Bloc<SignUpEvent, SignUpState> {
|
||||
repeatPasswordError: none(),
|
||||
));
|
||||
|
||||
final result = await autoRepo.signUp(
|
||||
final result = await authService.signUp(
|
||||
name: state.email,
|
||||
password: state.password,
|
||||
email: state.email,
|
||||
|
@ -3,7 +3,7 @@ import 'package:dartz/dartz.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/workspace.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'dart:typed_data';
|
||||
import 'package:app_flowy/core/helper.dart';
|
||||
import 'package:app_flowy/core/notification_helper.dart';
|
||||
import 'package:flowy_infra/notifier.dart';
|
||||
import 'package:flowy_sdk/protobuf/dart-notify/protobuf.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart';
|
||||
|
@ -4,7 +4,7 @@ import 'package:flowy_sdk/flowy_sdk.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_setting.pb.dart';
|
||||
|
||||
class UserSettingReppsitory {
|
||||
class UserSettingsService {
|
||||
Future<AppearanceSettings> getAppearanceSettings() async {
|
||||
final result = await UserEventGetAppearanceSetting().send();
|
||||
|
@ -1,5 +1,5 @@
|
||||
import 'package:app_flowy/startup/startup.dart';
|
||||
import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart';
|
||||
import 'package:app_flowy/user/application/auth_service.dart';
|
||||
import 'package:app_flowy/user/presentation/sign_in_screen.dart';
|
||||
import 'package:app_flowy/user/presentation/sign_up_screen.dart';
|
||||
import 'package:app_flowy/user/presentation/skip_log_in_screen.dart';
|
||||
@ -69,7 +69,7 @@ class SplashRoute {
|
||||
PageRoutes.fade(
|
||||
() => SkipLogInScreen(
|
||||
router: getIt<AuthRouter>(),
|
||||
authRepo: getIt<AuthRepository>(),
|
||||
authService: getIt<AuthService>(),
|
||||
),
|
||||
RouteDurations.slow.inMilliseconds * .001),
|
||||
);
|
@ -1,6 +1,6 @@
|
||||
import 'package:app_flowy/startup/startup.dart';
|
||||
import 'package:app_flowy/user/application/sign_in_bloc.dart';
|
||||
import 'package:app_flowy/user/infrastructure/router.dart';
|
||||
import 'package:app_flowy/user/presentation/router.dart';
|
||||
import 'package:app_flowy/user/presentation/widgets/background.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flowy_infra/size.dart';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:app_flowy/startup/startup.dart';
|
||||
import 'package:app_flowy/user/application/sign_up_bloc.dart';
|
||||
import 'package:app_flowy/user/infrastructure/router.dart';
|
||||
import 'package:app_flowy/user/presentation/router.dart';
|
||||
import 'package:app_flowy/user/presentation/widgets/background.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flowy_infra/theme.dart';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:app_flowy/user/application/auth_service.dart';
|
||||
import 'package:app_flowy/user/application/user_listener.dart';
|
||||
import 'package:app_flowy/user/infrastructure/router.dart';
|
||||
import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart';
|
||||
import 'package:app_flowy/user/presentation/router.dart';
|
||||
import 'package:app_flowy/user/presentation/widgets/background.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flowy_infra/size.dart';
|
||||
@ -21,12 +21,12 @@ import 'package:app_flowy/generated/locale_keys.g.dart';
|
||||
|
||||
class SkipLogInScreen extends StatefulWidget {
|
||||
final AuthRouter router;
|
||||
final AuthRepository authRepo;
|
||||
final AuthService authService;
|
||||
|
||||
const SkipLogInScreen({
|
||||
Key? key,
|
||||
required this.router,
|
||||
required this.authRepo,
|
||||
required this.authService,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@ -99,7 +99,7 @@ class _SkipLogInScreenState extends State<SkipLogInScreen> {
|
||||
const password = "AppFlowy123@";
|
||||
final uid = uuid();
|
||||
final userEmail = "$uid@appflowy.io";
|
||||
final result = await widget.authRepo.signUp(
|
||||
final result = await widget.authService.signUp(
|
||||
name: LocaleKeys.defaultUsername.tr(),
|
||||
password: password,
|
||||
email: userEmail,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:app_flowy/startup/startup.dart';
|
||||
import 'package:app_flowy/user/application/splash_bloc.dart';
|
||||
import 'package:app_flowy/user/domain/auth_state.dart';
|
||||
import 'package:app_flowy/user/infrastructure/router.dart';
|
||||
import 'package:app_flowy/user/presentation/router.dart';
|
||||
import 'package:flowy_sdk/log.dart';
|
||||
import 'package:flowy_sdk/dispatch/dispatch.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/errors.pb.dart';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:app_flowy/core/helper.dart';
|
||||
import 'package:app_flowy/core/notification_helper.dart';
|
||||
import 'package:flowy_sdk/log.dart';
|
||||
import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import 'package:app_flowy/user/infrastructure/repos/user_setting_repo.dart';
|
||||
import 'package:app_flowy/user/application/user_settings_service.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flowy_infra/theme.dart';
|
||||
import 'package:flowy_sdk/log.dart';
|
||||
@ -24,7 +24,7 @@ class AppearanceSettingModel extends ChangeNotifier with EquatableMixin {
|
||||
_saveOperation?.cancel;
|
||||
_saveOperation = CancelableOperation.fromFuture(
|
||||
Future.delayed(const Duration(seconds: 1), () async {
|
||||
await UserSettingReppsitory().setAppearanceSettings(setting);
|
||||
await UserSettingsService().setAppearanceSettings(setting);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:app_flowy/core/helper.dart';
|
||||
import 'package:app_flowy/core/notification_helper.dart';
|
||||
import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder/dart_notification.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
import 'package:app_flowy/core/helper.dart';
|
||||
import 'package:app_flowy/core/notification_helper.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:app_flowy/core/helper.dart';
|
||||
import 'package:app_flowy/core/notification_helper.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flowy_sdk/log.dart';
|
||||
import 'package:flowy_sdk/protobuf/dart-notify/subject.pb.dart';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import 'package:app_flowy/startup/startup.dart';
|
||||
import 'package:app_flowy/user/infrastructure/repos/auth_repo.dart';
|
||||
import 'package:app_flowy/user/application/auth_service.dart';
|
||||
import 'package:flowy_infra/uuid.dart';
|
||||
import 'package:flowy_sdk/protobuf/flowy-user-data-model/protobuf.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -15,11 +15,11 @@ class FlowyTest {
|
||||
}
|
||||
|
||||
Future<UserProfile> signIn() async {
|
||||
final authRepo = getIt<AuthRepository>();
|
||||
final authService = getIt<AuthService>();
|
||||
const password = "AppFlowy123@";
|
||||
final uid = uuid();
|
||||
final userEmail = "$uid@appflowy.io";
|
||||
final result = await authRepo.signUp(
|
||||
final result = await authService.signUp(
|
||||
name: "FlowyTestUser",
|
||||
password: password,
|
||||
email: userEmail,
|
||||
|
Loading…
Reference in New Issue
Block a user