Skip to content

Commit

Permalink
clean architecture ♻️
Browse files Browse the repository at this point in the history
  • Loading branch information
olawills committed Sep 29, 2023
1 parent 6ff8dc8 commit 2810839
Show file tree
Hide file tree
Showing 95 changed files with 365 additions and 341 deletions.
4 changes: 2 additions & 2 deletions lib/app/common/utils/typedef.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:dartz/dartz.dart';
import 'package:dating_app/app/core/network_handler/failures.dart';
import 'package:dating_app/presentation/auth/data/models/user.dart';
import 'package:dating_app/app/core/network/failures.dart';
import 'package:dating_app/src/auth/data/models/user.dart';

typedef ResultFuture<T> = Future<Either<Failure, T>>;

Expand Down
37 changes: 20 additions & 17 deletions lib/app/core/core.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
// packages exports

export 'package:cached_network_image/cached_network_image.dart';
export 'package:dating_app/app/common/extensions/navigation_ext.dart';
export 'package:flutter/material.dart';
export 'package:flutter_bloc/flutter_bloc.dart';
export 'package:fluttertoast/fluttertoast.dart';
export 'package:go_router/go_router.dart';
export 'package:dating_app/app/common/extensions/navigation_ext.dart';

export '../../../../../app/core/services/auth_local_data_source.dart';
export '../../../presentation/auth/presentation/views/complete_verification/verification_barrels.dart';
export '../../../presentation/auth/presentation/views/forgot_password/forgot_password_barrels.dart';
export '../../../presentation/auth/presentation/views/info_view/barrels.dart';
export '../../../presentation/auth/presentation/views/interest_view/barrels.dart';
export '../../../presentation/auth/presentation/views/login/barrels.dart';
export '../../../presentation/auth/presentation/views/otp_verification/otp_barrels.dart';
export '../../../presentation/auth/presentation/views/signup/barrels.dart';
export '../../../presentation/features/presentation/cubit/internet_connection/internet_connection_cubit.dart';
export '../../../presentation/features/presentation/views/chats/chats_barrel.dart';
export '../../presentation/features/presentation/views/skeleton_controller.dart';
export '../../../presentation/features/presentation/views/home/home_barrel.dart';
export '../../../presentation/features/presentation/views/notification/notification_barrel.dart';
export '../../../presentation/features/presentation/views/profile/profile_barrel.dart';
export '../../../presentation/not_found/not_found_controller.dart';
export '../../../presentation/startup/presentation/views/onboarding/barrels.dart';
export '../../../presentation/startup/presentation/views/startup/startup_controller.dart';
export '../../../src/auth/presentation/views/complete_verification/verification_barrels.dart';
export '../../../src/auth/presentation/views/forgot_password/forgot_password_barrels.dart';
export '../../../src/auth/presentation/views/info_view/barrels.dart';
export '../../../src/auth/presentation/views/interest_view/barrels.dart';
export '../../../src/auth/presentation/views/login/barrels.dart';
export '../../../src/auth/presentation/views/otp_verification/otp_barrels.dart';
export '../../../src/auth/presentation/views/signup/barrels.dart';
export '../../../src/features/chats/presentation/chats_barrel.dart';
export '../../../src/features/home/presentation/home_barrel.dart';
export '../../../src/features/notification/presentation/notification_barrel.dart';
export '../../../src/features/profile/presentation/profile_barrel.dart';
export '../../../src/features/skeleton_controller.dart';
export '../../../src/not_found/not_found_controller.dart';
export '../../../src/startup/presentation/views/onboarding/barrels.dart';
export '../../../src/startup/presentation/views/startup/startup_controller.dart';

export '../../../src/features/cubit/bottom_navbar/bottom_navigation_cubit.dart';
export '../../../src/features/home/presentation/bloc/users_bloc.dart';
export '../../../src/features/cubit/internet_connection/internet_connection_cubit.dart';
11 changes: 4 additions & 7 deletions lib/app/core/domain/all_blocs.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'package:dating_app/app/core/core.dart';
import 'package:dating_app/injection_container.dart';
import 'package:dating_app/presentation/auth/presentation/bloc/auth_bloc/auth_bloc.dart';
import 'package:dating_app/src/auth/presentation/bloc/auth_bloc/auth_bloc.dart';

import '../../../presentation/auth/presentation/bloc/user_info_bloc/interest_bloc.dart';
import '../../../presentation/features/presentation/bloc/users_bloc.dart';
import '../../../presentation/features/presentation/cubit/bottom_navbar/bottom_navigation_cubit.dart';
import '../../../presentation/startup/presentation/bloc/onboarding_bloc.dart';
import '../../../src/auth/presentation/bloc/user_info_bloc/interest_bloc.dart';
import '../../../src/startup/presentation/bloc/onboarding_bloc.dart';

class AppBlocProviders {
static get allBlocProviders => [
Expand All @@ -32,7 +30,6 @@ class AppBlocProviders {

// Internet Connection Cubit
BlocProvider<InternetConnectionCubit>(
create: (context) =>
serviceLocator<InternetConnectionCubit>())
create: (context) => serviceLocator<InternetConnectionCubit>())
];
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:dating_app/app/core/network_handler/dio_interceptors.dart';
import 'package:dating_app/app/core/network/dio_interceptors.dart';
import 'package:dating_app/app/core/services/api_url.dart';
import 'package:dio/dio.dart' show Dio, ResponseType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import 'package:dating_app/app/common/common.dart';
import 'package:dio/dio.dart' show DioException, DioExceptionType;

class DioExceptions implements Exception {
static final DioExceptions dioExceptions = DioExceptions._();

factory DioExceptions() => dioExceptions;
DioExceptions._();

late String message;

DioExceptions.fromDioError(DioException dioException) {
Expand Down Expand Up @@ -67,3 +72,29 @@ class DioExceptions implements Exception {
@override
String toString() => message;
}

class DioErrorHandler {
static final DioErrorHandler _dioErrorHandler = DioErrorHandler._internal();
factory DioErrorHandler() => _dioErrorHandler;
DioErrorHandler._internal();

static dynamic handleDioError(DioException exception) {
switch (exception.message) {
case DioExceptionType.cancel:
return AppString.cancelRequest;
case DioExceptionType.connectionTimeout:
return AppString.connectionTimeout;
case DioExceptionType.sendTimeout:
return AppString.sendTimeOut;
case DioExceptionType.receiveTimeout:
return AppString.receiveTimeout;
case DioExceptionType.unknown:
if (exception is SocketException) {
return AppString.socketException;
}
return AppString.unexpectedError;
default:
return AppString.unknownError;
}
}
}
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions lib/app/core/network/failures.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:dio/dio.dart';
import 'package:equatable/equatable.dart';

import '../../common/constants/app_string.dart';

abstract class Failure extends Equatable {
final String message;
const Failure(this.message);

@override
List<Object?> get props => [message];
}

class ServerFailure extends Failure {
const ServerFailure(super.message);

factory ServerFailure.fromDioError(DioException error) {
switch (error.type) {
case DioExceptionType.connectionTimeout:
return const ServerFailure(AppString.connectionTimeout);
case DioExceptionType.sendTimeout:
return const ServerFailure(AppString.sendTimeOut);
case DioExceptionType.receiveTimeout:
return const ServerFailure(AppString.receiveTimeout);
case DioExceptionType.badResponse:
return ServerFailure(error.response!.data['message']);
case DioExceptionType.unknown:
if (error.message!.contains('SocketException')) {
return const ServerFailure(AppString.socketException);
}
return const ServerFailure(AppString.unexpectedError);
default:
return const ServerFailure(AppString.unknownError);
}
}
}
22 changes: 0 additions & 22 deletions lib/app/core/network_handler/exceptions.dart

This file was deleted.

29 changes: 0 additions & 29 deletions lib/app/core/network_handler/failures.dart

This file was deleted.

5 changes: 5 additions & 0 deletions lib/app/core/routes/app_router.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import 'package:dating_app/app/core/core.dart';

import '../../../src/features/chats/presentation/chats_barrel.dart';
import '../../../src/features/home/presentation/home_barrel.dart';
import '../../../src/features/notification/presentation/notification_barrel.dart';
import '../../../src/features/profile/presentation/profile_barrel.dart';
import '../../../src/features/skeleton_controller.dart';
import '../logger/app_logger.dart';

class AppRouter {
Expand Down
10 changes: 9 additions & 1 deletion lib/app/core/services/api_url.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import 'dart:io';

class ApiConfig {
static final ApiConfig _apiConfig = ApiConfig._internal();

// ** Singleton
factory ApiConfig() => _apiConfig;

ApiConfig._internal();
static const String baseUrl = 'https://spark-dating-api.onrender.com/api/v1';

static const Duration receiveTimeout = Duration(milliseconds: 15000);
static const Duration connectionTimeout = Duration(milliseconds: 15000);
static const header = {
'content-Type': 'application/json',
HttpHeaders.contentTypeHeader: 'application/json',
};
}
// https://meet.google.com/adw-kynw-kgh
13 changes: 12 additions & 1 deletion lib/app/core/services/auth_local_data_source.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:dating_app/app/common/common.dart';
import 'package:dating_app/presentation/auth/data/models/user.dart';
import 'package:dating_app/src/auth/data/models/user.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../../../src/auth/data/models/login_response.dart';
import 'app_tokens.dart';

class LocalDataStorage {
Expand Down Expand Up @@ -43,6 +44,16 @@ class LocalDataStorage {
await pref.setBool(_loggedIn, true);
}

Future<void> setLoginResponse(LoginResponse data) async {
final pref = await instance.prefs;
await pref.setString(_firstName, data.user.firstName);
await pref.setString(_lastName, data.user.lastName);
await pref.setString(_email, data.user.email);
await pref.setString(_token, data.token);
await pref.setString(_profilePicture, Assets.noAccountImage);
await pref.setBool(_loggedIn, true);
}

Future<void> setToken(String token) async {
final pref = await instance.prefs;
await pref.setString(_token, token);
Expand Down
8 changes: 6 additions & 2 deletions lib/app/core/services/push_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';

class FirebasePushNotificationServce {
FirebasePushNotificationServce._();
static final FirebasePushNotificationServce _firebasePushNotificationServce =
FirebasePushNotificationServce._internal();

factory FirebasePushNotificationServce() => _firebasePushNotificationServce;
FirebasePushNotificationServce._internal();
static FirebaseMessaging firebaseMessaging = FirebaseMessaging.instance;

static void getDeviceToken() {
Expand All @@ -32,7 +36,7 @@ class FirebasePushNotificationServce {

static Future<void> onMessageListen() async {
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
Log.info("....................................onMessage..........");
Log.info("..........................onMessage.....................");
Log.info(
"onMessage: ${message.notification?.title}/${message.notification?.body}");

Expand Down
27 changes: 13 additions & 14 deletions lib/injection_container.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:dating_app/app/core/core.dart';
import 'package:dating_app/presentation/auth/data/datasource/auth_info_remote_datasource.dart';
import 'package:dating_app/presentation/auth/data/datasource/auth_remote_data_source.dart';
import 'package:dating_app/presentation/auth/data/repository/auth_info_repository.dart';
import 'package:dating_app/presentation/auth/data/repository/auth_repository.dart';
import 'package:dating_app/presentation/features/data/datasources/user_remote_data_source.dart';
import 'package:dating_app/presentation/features/presentation/bloc/users_bloc.dart';
import 'package:dating_app/presentation/features/presentation/cubit/bottom_navbar/bottom_navigation_cubit.dart';
import 'package:dating_app/presentation/features/presentation/cubit/internet_connection/internet_connection_cubit.dart';
import 'package:dating_app/presentation/startup/presentation/bloc/onboarding_bloc.dart';
import 'package:dating_app/src/auth/data/datasource/auth_info_remote_datasource.dart';
import 'package:dating_app/src/auth/data/datasource/auth_remote_data_source.dart';
import 'package:dating_app/src/auth/data/repository/auth_info_repository.dart';
import 'package:dating_app/src/auth/data/repository/auth_repository.dart';
import 'package:dating_app/src/startup/presentation/bloc/onboarding_bloc.dart';
import 'package:dio/dio.dart';
import 'package:get_it/get_it.dart';

import 'app/core/network_handler/dio_client.dart';
import 'presentation/auth/presentation/bloc/auth_bloc/auth_bloc.dart';
import 'presentation/auth/presentation/bloc/user_info_bloc/interest_bloc.dart';
import 'presentation/features/data/repository/user_repository.dart';
import 'app/core/network/dio_client.dart';
import 'src/auth/presentation/bloc/auth_bloc/auth_bloc.dart';
import 'src/auth/presentation/bloc/user_info_bloc/interest_bloc.dart';
import 'src/features/cubit/bottom_navbar/bottom_navigation_cubit.dart';
import 'src/features/cubit/internet_connection/internet_connection_cubit.dart';
import 'src/features/home/data/datasources/user_remote_data_source.dart';
import 'src/features/home/data/repository/user_repository.dart';
import 'src/features/home/presentation/bloc/users_bloc.dart';

GetIt serviceLocator = GetIt.instance;

Expand Down
Loading

0 comments on commit 2810839

Please sign in to comment.