From 083c6558be81f34e4d2b73cc17c764f8313e1591 Mon Sep 17 00:00:00 2001 From: aidaiym Date: Mon, 16 Dec 2024 19:20:56 +0600 Subject: [PATCH 1/3] Implement Home Repo Package --- app/lib/app/presentation/view/app_view.dart | 17 +++-- app/lib/constants/api/api_const.dart | 2 +- app/lib/main.dart | 4 +- app/lib/modules/home/data/data.dart | 8 --- .../data/source/home_local_data_source.dart | 7 -- .../data/source/home_remote_data_source.dart | 5 -- .../mock/home_local_data_source_mock.dart | 15 ----- .../mock/home_remote_data_source_mock.dart | 16 ----- .../remote/home_remote_data_source_impl.dart | 24 ------- app/lib/modules/home/domain/domain.dart | 3 - .../domain/repository/home_repository.dart | 5 -- .../home/domain/usecase/get_data_usecase.dart | 13 ---- app/lib/modules/home/home.dart | 2 - .../home/presentation/cubit/home_cubit.dart | 8 +-- .../home/presentation/cubit/home_state.dart | 2 +- app/pubspec.lock | 7 ++ app/pubspec.yaml | 2 + app/test/helpers/pump_app.dart | 5 +- app/test/mocks/app_mocks.dart | 8 +-- packages/mq_home_repository/README.md | 67 +++++++++++++++++++ .../mq_home_repository/analysis_options.yaml | 10 +++ .../lib/mq_home_repository.dart | 4 ++ .../lib/src/entity/mq_home_entity.dart | 4 +- .../lib/src/model/mq_home_model_response.dart | 8 +-- .../src/model/mq_home_model_response.g.dart | 6 +- .../src/repository/mq_home_repository.dart | 5 ++ .../repository/mq_home_repository_impl.dart | 16 ++--- .../local/mq_home_local_data_source_impl.dart | 14 ++-- .../mock/mq_home_local_data_source_mock.dart | 15 +++++ .../mock/mq_home_remote_data_source_mock.dart | 16 +++++ .../src/source/mq_home_local_data_source.dart | 7 ++ .../source/mq_home_remote_data_source.dart | 5 ++ .../mq_home_remote_data_source_impl.dart | 23 +++++++ packages/mq_home_repository/lib/src/src.dart | 14 ++++ packages/mq_home_repository/pubspec.yaml | 30 +++++++++ .../test/mq_home_repository_test.dart | 11 +++ 36 files changed, 264 insertions(+), 144 deletions(-) delete mode 100644 app/lib/modules/home/data/data.dart delete mode 100644 app/lib/modules/home/data/source/home_local_data_source.dart delete mode 100644 app/lib/modules/home/data/source/home_remote_data_source.dart delete mode 100644 app/lib/modules/home/data/source/mock/home_local_data_source_mock.dart delete mode 100644 app/lib/modules/home/data/source/mock/home_remote_data_source_mock.dart delete mode 100644 app/lib/modules/home/data/source/remote/home_remote_data_source_impl.dart delete mode 100644 app/lib/modules/home/domain/domain.dart delete mode 100644 app/lib/modules/home/domain/repository/home_repository.dart delete mode 100644 app/lib/modules/home/domain/usecase/get_data_usecase.dart create mode 100644 packages/mq_home_repository/README.md create mode 100644 packages/mq_home_repository/analysis_options.yaml create mode 100644 packages/mq_home_repository/lib/mq_home_repository.dart rename app/lib/modules/home/domain/entity/home_entity.dart => packages/mq_home_repository/lib/src/entity/mq_home_entity.dart (82%) rename app/lib/modules/home/data/model/home_model_response.dart => packages/mq_home_repository/lib/src/model/mq_home_model_response.dart (64%) rename app/lib/modules/home/data/model/home_model_response.g.dart => packages/mq_home_repository/lib/src/model/mq_home_model_response.g.dart (69%) create mode 100644 packages/mq_home_repository/lib/src/repository/mq_home_repository.dart rename app/lib/modules/home/data/repository/home_repository_impl.dart => packages/mq_home_repository/lib/src/repository/mq_home_repository_impl.dart (64%) rename app/lib/modules/home/data/source/local/home_local_data_source_impl.dart => packages/mq_home_repository/lib/src/source/local/mq_home_local_data_source_impl.dart (52%) create mode 100644 packages/mq_home_repository/lib/src/source/mock/mq_home_local_data_source_mock.dart create mode 100644 packages/mq_home_repository/lib/src/source/mock/mq_home_remote_data_source_mock.dart create mode 100644 packages/mq_home_repository/lib/src/source/mq_home_local_data_source.dart create mode 100644 packages/mq_home_repository/lib/src/source/mq_home_remote_data_source.dart create mode 100644 packages/mq_home_repository/lib/src/source/remote/mq_home_remote_data_source_impl.dart create mode 100644 packages/mq_home_repository/lib/src/src.dart create mode 100644 packages/mq_home_repository/pubspec.yaml create mode 100644 packages/mq_home_repository/test/mq_home_repository_test.dart diff --git a/app/lib/app/presentation/view/app_view.dart b/app/lib/app/presentation/view/app_view.dart index f85e697a..95e64729 100644 --- a/app/lib/app/presentation/view/app_view.dart +++ b/app/lib/app/presentation/view/app_view.dart @@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:go_router/go_router.dart'; import 'package:just_audio/just_audio.dart'; import 'package:loader_overlay/loader_overlay.dart'; +import 'package:mq_home_repository/mq_home_repository.dart'; import 'package:mq_remote_client/mq_remote_client.dart'; import 'package:mq_remote_config/mq_remote_config.dart'; import 'package:mq_storage/mq_storage.dart'; @@ -79,15 +80,13 @@ class MyApp extends StatelessWidget { ), BlocProvider( create: (context) => HomeCubit( - GetHomeDataUseCase( - HomeRepositoryImpl( - isMockData - ? const HomeLocalDataSourceMock() - : HomeLocalDataSourceImpl(context.read()), - isMockData - ? const HomeRemoteDataSourceMock() - : HomeRemoteDataSourceImpl(context.read()), - ), + MqHomeRepositoryImpl( + isMockData + ? const MqHomeLocalDataSourceMock() + : MqHomeLocalDataSourceImpl(context.read()), + isMockData + ? const MqHomeRemoteDataSourceMock() + : MqHomeRemoteDataSourceImpl(context.read()), ), ), ), diff --git a/app/lib/constants/api/api_const.dart b/app/lib/constants/api/api_const.dart index 67ef0ccc..f729adf8 100644 --- a/app/lib/constants/api/api_const.dart +++ b/app/lib/constants/api/api_const.dart @@ -16,7 +16,7 @@ class ApiConst { String get loginWithApple => '$_getDomain/api/v1/accounts/apple/'; String get deleteProfile => '$_getDomain/api/v1/accounts/profile/delete_my_account/'; String putProfile(String userId) => '$_getDomain/api/v1/accounts/profile/$userId/'; - String get hatimDashBoard => '$_getDomain/api/v1/hatim/dashboard'; + // String get hatimDashBoard => '$_getDomain/api/v1/hatim/dashboard'; String get joinToHatim => '$_getDomain/api/v1/hatim/join_to_hatim'; String getSocket(String token) => '$socketBase/?token=$token'; diff --git a/app/lib/main.dart b/app/lib/main.dart index 6a37dd2b..2ab69fda 100644 --- a/app/lib/main.dart +++ b/app/lib/main.dart @@ -75,7 +75,9 @@ Future main({AppConfig? appConfig}) async { RepositoryProvider(create: (context) => remoteConfig), RepositoryProvider( create: (context) => MqRemoteClient( - dio: Dio(), + dio: Dio( + BaseOptions(baseUrl: ApiConst.domain), + ), network: context.read(), language: () => storage.readString(key: StorageKeys.localeKey), token: () => storage.readString(key: StorageKeys.tokenKey), diff --git a/app/lib/modules/home/data/data.dart b/app/lib/modules/home/data/data.dart deleted file mode 100644 index c8238aa0..00000000 --- a/app/lib/modules/home/data/data.dart +++ /dev/null @@ -1,8 +0,0 @@ -export 'model/home_model_response.dart'; -export 'repository/home_repository_impl.dart'; -export 'source/local/home_local_data_source_impl.dart'; -export 'source/remote/home_remote_data_source_impl.dart'; -export 'source/mock/home_local_data_source_mock.dart'; -export 'source/mock/home_remote_data_source_mock.dart'; -export 'source/home_local_data_source.dart'; -export 'source/home_remote_data_source.dart'; diff --git a/app/lib/modules/home/data/source/home_local_data_source.dart b/app/lib/modules/home/data/source/home_local_data_source.dart deleted file mode 100644 index b3562d04..00000000 --- a/app/lib/modules/home/data/source/home_local_data_source.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:my_quran/modules/modules.dart'; - -abstract class HomeLocalDataSource { - HomeModelResponse getLocalData(); - - Future saveLocalData(HomeModelResponse data); -} diff --git a/app/lib/modules/home/data/source/home_remote_data_source.dart b/app/lib/modules/home/data/source/home_remote_data_source.dart deleted file mode 100644 index 1a774d5c..00000000 --- a/app/lib/modules/home/data/source/home_remote_data_source.dart +++ /dev/null @@ -1,5 +0,0 @@ -import 'package:my_quran/modules/modules.dart'; - -abstract class HomeRemoteDataSource { - Future getRemoteData(); -} diff --git a/app/lib/modules/home/data/source/mock/home_local_data_source_mock.dart b/app/lib/modules/home/data/source/mock/home_local_data_source_mock.dart deleted file mode 100644 index 4499a114..00000000 --- a/app/lib/modules/home/data/source/mock/home_local_data_source_mock.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:my_quran/modules/modules.dart'; - -@immutable -final class HomeLocalDataSourceMock implements HomeLocalDataSource { - const HomeLocalDataSourceMock(); - - @override - HomeModelResponse getLocalData() { - return const HomeModelResponse(allDoneHatims: 0, allDonePages: 0, donePages: 0); - } - - @override - Future saveLocalData(HomeModelResponse data) => Future.value(); -} diff --git a/app/lib/modules/home/data/source/mock/home_remote_data_source_mock.dart b/app/lib/modules/home/data/source/mock/home_remote_data_source_mock.dart deleted file mode 100644 index b271bb76..00000000 --- a/app/lib/modules/home/data/source/mock/home_remote_data_source_mock.dart +++ /dev/null @@ -1,16 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:my_quran/modules/modules.dart'; - -@immutable -final class HomeRemoteDataSourceMock implements HomeRemoteDataSource { - const HomeRemoteDataSourceMock(); - - @override - Future getRemoteData() async { - return const HomeModelResponse( - allDoneHatims: 0, - allDonePages: 0, - donePages: 0, - ); - } -} diff --git a/app/lib/modules/home/data/source/remote/home_remote_data_source_impl.dart b/app/lib/modules/home/data/source/remote/home_remote_data_source_impl.dart deleted file mode 100644 index 14bf39d1..00000000 --- a/app/lib/modules/home/data/source/remote/home_remote_data_source_impl.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:mq_remote_client/mq_remote_client.dart'; -import 'package:my_quran/config/config.dart'; -import 'package:my_quran/modules/modules.dart'; - -@immutable -final class HomeRemoteDataSourceImpl implements HomeRemoteDataSource { - const HomeRemoteDataSourceImpl(this.remoteClient); - - final MqRemoteClient remoteClient; - - @override - Future getRemoteData() async { - final remoteValue = await remoteClient.getType( - apiConst.hatimDashBoard, - fromJson: HomeModelResponse.fromJson, - ); - - return remoteValue.fold( - (left) => throw Exception('Failed to fetch remote data $left'), - (right) => right, - ); - } -} diff --git a/app/lib/modules/home/domain/domain.dart b/app/lib/modules/home/domain/domain.dart deleted file mode 100644 index 9ea3a746..00000000 --- a/app/lib/modules/home/domain/domain.dart +++ /dev/null @@ -1,3 +0,0 @@ -export 'entity/home_entity.dart'; -export 'repository/home_repository.dart'; -export 'usecase/get_data_usecase.dart'; diff --git a/app/lib/modules/home/domain/repository/home_repository.dart b/app/lib/modules/home/domain/repository/home_repository.dart deleted file mode 100644 index 637e50ac..00000000 --- a/app/lib/modules/home/domain/repository/home_repository.dart +++ /dev/null @@ -1,5 +0,0 @@ -import 'package:my_quran/modules/modules.dart'; - -abstract class HomeRepository { - Future getData(); -} diff --git a/app/lib/modules/home/domain/usecase/get_data_usecase.dart b/app/lib/modules/home/domain/usecase/get_data_usecase.dart deleted file mode 100644 index 64968e36..00000000 --- a/app/lib/modules/home/domain/usecase/get_data_usecase.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:my_quran/modules/modules.dart'; - -@immutable -final class GetHomeDataUseCase { - const GetHomeDataUseCase(this.repository); - - final HomeRepository repository; - - Future execute() { - return repository.getData(); - } -} diff --git a/app/lib/modules/home/home.dart b/app/lib/modules/home/home.dart index aeeb7088..29b200c9 100644 --- a/app/lib/modules/home/home.dart +++ b/app/lib/modules/home/home.dart @@ -1,3 +1 @@ -export 'data/data.dart'; -export 'domain/domain.dart'; export 'presentation/presentation.dart'; diff --git a/app/lib/modules/home/presentation/cubit/home_cubit.dart b/app/lib/modules/home/presentation/cubit/home_cubit.dart index 9c3b3c02..50e72c58 100644 --- a/app/lib/modules/home/presentation/cubit/home_cubit.dart +++ b/app/lib/modules/home/presentation/cubit/home_cubit.dart @@ -2,19 +2,19 @@ import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:mq_crashlytics/mq_crashlytics.dart'; +import 'package:mq_home_repository/mq_home_repository.dart'; import 'package:my_quran/core/core.dart'; -import 'package:my_quran/modules/modules.dart'; part 'home_state.dart'; class HomeCubit extends Cubit { - HomeCubit(this.getHomeDataUseCase) : super(const HomeState()); + HomeCubit(this.homeRepository) : super(const HomeState()); - final GetHomeDataUseCase getHomeDataUseCase; + final MqHomeRepository homeRepository; Future getData() async { try { - final homeModel = await getHomeDataUseCase.execute(); + final homeModel = await homeRepository.getData(); emit(HomeState(status: FetchStatus.success, homeModel: homeModel)); } catch (e, s) { MqCrashlytics.report(e, s); diff --git a/app/lib/modules/home/presentation/cubit/home_state.dart b/app/lib/modules/home/presentation/cubit/home_state.dart index 975cddf9..ce9d45ad 100644 --- a/app/lib/modules/home/presentation/cubit/home_state.dart +++ b/app/lib/modules/home/presentation/cubit/home_state.dart @@ -7,7 +7,7 @@ final class HomeState extends Equatable { this.homeModel, }); - final HomeEntity? homeModel; + final MqHomeEntity? homeModel; final FetchStatus status; @override diff --git a/app/pubspec.lock b/app/pubspec.lock index e73b4d55..15b0ae41 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -944,6 +944,13 @@ packages: relative: true source: path version: "0.1.0+1" + mq_home_repository: + dependency: "direct main" + description: + path: "../packages/mq_home_repository" + relative: true + source: path + version: "0.1.0+1" mq_remote_client: dependency: "direct main" description: diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 6f71301c..dfa757e5 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -77,6 +77,8 @@ dependencies: path: ../packages/mq_analytics mq_remote_config: path: ../packages/mq_remote_config + mq_home_repository: + path: ../packages/mq_home_repository dev_dependencies: flutter_test: diff --git a/app/test/helpers/pump_app.dart b/app/test/helpers/pump_app.dart index 6d7d34fa..87a00f6b 100644 --- a/app/test/helpers/pump_app.dart +++ b/app/test/helpers/pump_app.dart @@ -1,5 +1,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:mq_home_repository/mq_home_repository.dart'; import 'package:mq_remote_config/mq_remote_config.dart'; import 'package:my_quran/app/app.dart'; @@ -17,7 +18,7 @@ extension PumpApp on WidgetTester { GoogleSignInUseCase googleSignInUseCase, AppleSignInUseCase appleSignInUseCase, SerUserDataUseCase setUserDataUseCase, - HomeRepository homeRepo, + MqHomeRepository homeRepo, PatchGenderUseCase patchGenderUseCase, PatchLocaleCodeUseCase patchLocaleCodeUseCase, LogoutUseCase logoutUseCase, @@ -58,7 +59,7 @@ extension PumpApp on WidgetTester { ), ), BlocProvider( - create: (context) => HomeCubit(GetHomeDataUseCase(homeRepo)), + create: (context) => HomeCubit(homeRepo), ), BlocProvider( create: (context) => RemoteConfigCubit( diff --git a/app/test/mocks/app_mocks.dart b/app/test/mocks/app_mocks.dart index 4b491066..c39e1e28 100644 --- a/app/test/mocks/app_mocks.dart +++ b/app/test/mocks/app_mocks.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:mq_home_repository/mq_home_repository.dart'; import 'package:mq_remote_client/mq_remote_client.dart'; import 'package:mq_remote_config/mq_remote_config.dart'; import 'package:package_info_plus/package_info_plus.dart'; @@ -7,7 +8,6 @@ import 'package:package_info_plus/package_info_plus.dart'; import 'package:mocktail/mocktail.dart'; import 'package:mq_storage/mq_storage.dart'; import 'package:my_quran/core/core.dart'; -import 'package:my_quran/modules/modules.dart'; final class MockPreferencesStorage extends Mock implements PreferencesStorage {} @@ -23,10 +23,10 @@ final class MockPackageInfo extends Mock implements PackageInfo { String get buildNumber => '10'; } -final class MockHomeRepositoryImpl implements HomeRepository { +final class MockHomeRepositoryImpl implements MqHomeRepository { @override - Future getData() async { - return const HomeEntity(allDoneHatims: 8, allDonePages: 5325, donePages: 634); + Future getData() async { + return const MqHomeEntity(allDoneHatims: 8, allDonePages: 5325, donePages: 634); } } diff --git a/packages/mq_home_repository/README.md b/packages/mq_home_repository/README.md new file mode 100644 index 00000000..6b5e01c0 --- /dev/null +++ b/packages/mq_home_repository/README.md @@ -0,0 +1,67 @@ +# Mq Home Repository + +[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link] +[![Powered by Mason](https://img.shields.io/endpoint?url=https%3A%2F%2Ftinyurl.com%2Fmason-badge)](https://github.com/felangel/mason) +[![License: MIT][license_badge]][license_link] + +MQ Home Repository Package + +## Installation ๐Ÿ’ป + +**โ— In order to start using Mq Home Repository you must have the [Flutter SDK][flutter_install_link] installed on your machine.** + +Install via `flutter pub add`: + +```sh +dart pub add mq_home_repository +``` + +--- + +## Continuous Integration ๐Ÿค– + +Mq Home Repository comes with a built-in [GitHub Actions workflow][github_actions_link] powered by [Very Good Workflows][very_good_workflows_link] but you can also add your preferred CI/CD solution. + +Out of the box, on each pull request and push, the CI `formats`, `lints`, and `tests` the code. This ensures the code remains consistent and behaves correctly as you add functionality or make changes. The project uses [Very Good Analysis][very_good_analysis_link] for a strict set of analysis options used by our team. Code coverage is enforced using the [Very Good Workflows][very_good_coverage_link]. + +--- + +## Running Tests ๐Ÿงช + +For first time users, install the [very_good_cli][very_good_cli_link]: + +```sh +dart pub global activate very_good_cli +``` + +To run all unit tests: + +```sh +very_good test --coverage +``` + +To view the generated coverage report you can use [lcov](https://github.com/linux-test-project/lcov). + +```sh +# Generate Coverage Report +genhtml coverage/lcov.info -o coverage/ + +# Open Coverage Report +open coverage/index.html +``` + +[flutter_install_link]: https://docs.flutter.dev/get-started/install +[github_actions_link]: https://docs.github.com/en/actions/learn-github-actions +[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg +[license_link]: https://opensource.org/licenses/MIT +[logo_black]: https://raw.githubusercontent.com/VGVentures/very_good_brand/main/styles/README/vgv_logo_black.png#gh-light-mode-only +[logo_white]: https://raw.githubusercontent.com/VGVentures/very_good_brand/main/styles/README/vgv_logo_white.png#gh-dark-mode-only +[mason_link]: https://github.com/felangel/mason +[very_good_analysis_badge]: https://img.shields.io/badge/style-very_good_analysis-B22C89.svg +[very_good_analysis_link]: https://pub.dev/packages/very_good_analysis +[very_good_cli_link]: https://pub.dev/packages/very_good_cli +[very_good_coverage_link]: https://github.com/marketplace/actions/very-good-coverage +[very_good_ventures_link]: https://verygood.ventures +[very_good_ventures_link_light]: https://verygood.ventures#gh-light-mode-only +[very_good_ventures_link_dark]: https://verygood.ventures#gh-dark-mode-only +[very_good_workflows_link]: https://github.com/VeryGoodOpenSource/very_good_workflows diff --git a/packages/mq_home_repository/analysis_options.yaml b/packages/mq_home_repository/analysis_options.yaml new file mode 100644 index 00000000..5ea2ad9f --- /dev/null +++ b/packages/mq_home_repository/analysis_options.yaml @@ -0,0 +1,10 @@ +analyzer: + errors: + one_member_abstracts: ignore +include: package:very_good_analysis/analysis_options.6.0.0.yaml + +linter: + rules: + public_member_api_docs: false + lines_longer_than_80_chars: false + sort_pub_dependencies: false diff --git a/packages/mq_home_repository/lib/mq_home_repository.dart b/packages/mq_home_repository/lib/mq_home_repository.dart new file mode 100644 index 00000000..1c861903 --- /dev/null +++ b/packages/mq_home_repository/lib/mq_home_repository.dart @@ -0,0 +1,4 @@ +/// MQ Home Repository Package +library mq_home_repository; + +export 'src/src.dart'; diff --git a/app/lib/modules/home/domain/entity/home_entity.dart b/packages/mq_home_repository/lib/src/entity/mq_home_entity.dart similarity index 82% rename from app/lib/modules/home/domain/entity/home_entity.dart rename to packages/mq_home_repository/lib/src/entity/mq_home_entity.dart index f281db42..b4f89157 100644 --- a/app/lib/modules/home/domain/entity/home_entity.dart +++ b/packages/mq_home_repository/lib/src/entity/mq_home_entity.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; @immutable -final class HomeEntity { - const HomeEntity({ +final class MqHomeEntity { + const MqHomeEntity({ required this.allDoneHatims, required this.allDonePages, required this.donePages, diff --git a/app/lib/modules/home/data/model/home_model_response.dart b/packages/mq_home_repository/lib/src/model/mq_home_model_response.dart similarity index 64% rename from app/lib/modules/home/data/model/home_model_response.dart rename to packages/mq_home_repository/lib/src/model/mq_home_model_response.dart index 45d636bf..c80f8395 100644 --- a/app/lib/modules/home/data/model/home_model_response.dart +++ b/packages/mq_home_repository/lib/src/model/mq_home_model_response.dart @@ -1,18 +1,18 @@ import 'package:flutter/material.dart'; import 'package:json_annotation/json_annotation.dart'; -part 'home_model_response.g.dart'; +part 'mq_home_model_response.g.dart'; @JsonSerializable() @immutable -final class HomeModelResponse { - const HomeModelResponse({ +final class MqHomeModelResponse { + const MqHomeModelResponse({ required this.allDoneHatims, required this.allDonePages, required this.donePages, }); - factory HomeModelResponse.fromJson(Map json) => _$HomeModelResponseFromJson(json); + factory MqHomeModelResponse.fromJson(Map json) => _$HomeModelResponseFromJson(json); Map toJson() => _$HomeModelResponseToJson(this); final int allDoneHatims; diff --git a/app/lib/modules/home/data/model/home_model_response.g.dart b/packages/mq_home_repository/lib/src/model/mq_home_model_response.g.dart similarity index 69% rename from app/lib/modules/home/data/model/home_model_response.g.dart rename to packages/mq_home_repository/lib/src/model/mq_home_model_response.g.dart index b6251496..84179d0e 100644 --- a/app/lib/modules/home/data/model/home_model_response.g.dart +++ b/packages/mq_home_repository/lib/src/model/mq_home_model_response.g.dart @@ -1,18 +1,18 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'home_model_response.dart'; +part of 'mq_home_model_response.dart'; // ************************************************************************** // JsonSerializableGenerator // ************************************************************************** -HomeModelResponse _$HomeModelResponseFromJson(Map json) => HomeModelResponse( +MqHomeModelResponse _$HomeModelResponseFromJson(Map json) => MqHomeModelResponse( allDoneHatims: (json['allDoneHatims'] as num).toInt(), allDonePages: (json['allDonePages'] as num).toInt(), donePages: (json['donePages'] as num).toInt(), ); -Map _$HomeModelResponseToJson(HomeModelResponse instance) => { +Map _$HomeModelResponseToJson(MqHomeModelResponse instance) => { 'allDoneHatims': instance.allDoneHatims, 'allDonePages': instance.allDonePages, 'donePages': instance.donePages, diff --git a/packages/mq_home_repository/lib/src/repository/mq_home_repository.dart b/packages/mq_home_repository/lib/src/repository/mq_home_repository.dart new file mode 100644 index 00000000..5870f996 --- /dev/null +++ b/packages/mq_home_repository/lib/src/repository/mq_home_repository.dart @@ -0,0 +1,5 @@ +import 'package:mq_home_repository/mq_home_repository.dart'; + +abstract interface class MqHomeRepository { + Future getData(); +} diff --git a/app/lib/modules/home/data/repository/home_repository_impl.dart b/packages/mq_home_repository/lib/src/repository/mq_home_repository_impl.dart similarity index 64% rename from app/lib/modules/home/data/repository/home_repository_impl.dart rename to packages/mq_home_repository/lib/src/repository/mq_home_repository_impl.dart index 28525e63..9765b62e 100644 --- a/app/lib/modules/home/data/repository/home_repository_impl.dart +++ b/packages/mq_home_repository/lib/src/repository/mq_home_repository_impl.dart @@ -2,20 +2,20 @@ import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:mq_crashlytics/mq_crashlytics.dart'; -import 'package:my_quran/modules/modules.dart'; +import 'package:mq_home_repository/mq_home_repository.dart'; @immutable -final class HomeRepositoryImpl implements HomeRepository { - const HomeRepositoryImpl( +final class MqHomeRepositoryImpl implements MqHomeRepository { + const MqHomeRepositoryImpl( this.localDataSource, this.remoteDataSource, ); - final HomeLocalDataSource localDataSource; - final HomeRemoteDataSource remoteDataSource; + final MqHomeLocalDataSource localDataSource; + final MqHomeRemoteDataSource remoteDataSource; @override - Future getData() async { + Future getData() async { try { final remoteData = await remoteDataSource.getRemoteData(); await localDataSource.saveLocalData(remoteData); @@ -27,8 +27,8 @@ final class HomeRepositoryImpl implements HomeRepository { } } - HomeEntity _convertData(HomeModelResponse response) { - return HomeEntity( + MqHomeEntity _convertData(MqHomeModelResponse response) { + return MqHomeEntity( allDoneHatims: response.allDoneHatims, allDonePages: response.allDonePages, donePages: response.donePages, diff --git a/app/lib/modules/home/data/source/local/home_local_data_source_impl.dart b/packages/mq_home_repository/lib/src/source/local/mq_home_local_data_source_impl.dart similarity index 52% rename from app/lib/modules/home/data/source/local/home_local_data_source_impl.dart rename to packages/mq_home_repository/lib/src/source/local/mq_home_local_data_source_impl.dart index a5f1da1f..ac160481 100644 --- a/app/lib/modules/home/data/source/local/home_local_data_source_impl.dart +++ b/packages/mq_home_repository/lib/src/source/local/mq_home_local_data_source_impl.dart @@ -1,29 +1,29 @@ import 'dart:convert'; import 'package:flutter/material.dart'; +import 'package:mq_home_repository/mq_home_repository.dart'; import 'package:mq_storage/mq_storage.dart'; -import 'package:my_quran/modules/modules.dart'; @immutable -final class HomeLocalDataSourceImpl implements HomeLocalDataSource { - const HomeLocalDataSourceImpl(this.storage); +final class MqHomeLocalDataSourceImpl implements MqHomeLocalDataSource { + const MqHomeLocalDataSourceImpl(this.storage); final PreferencesStorage storage; static const _homeDataCacheKey = 'home-model'; @override - HomeModelResponse getLocalData() { + MqHomeModelResponse getLocalData() { final localValue = storage.readString(key: _homeDataCacheKey); if (localValue != null) { final data = jsonDecode(localValue); - return HomeModelResponse.fromJson(data as Map); + return MqHomeModelResponse.fromJson(data as Map); } else { - return const HomeModelResponse(allDoneHatims: 0, allDonePages: 0, donePages: 0); + return const MqHomeModelResponse(allDoneHatims: 0, allDonePages: 0, donePages: 0); } } @override - Future saveLocalData(HomeModelResponse data) async { + Future saveLocalData(MqHomeModelResponse data) async { await storage.writeString(key: _homeDataCacheKey, value: jsonEncode(data.toJson())); } } diff --git a/packages/mq_home_repository/lib/src/source/mock/mq_home_local_data_source_mock.dart b/packages/mq_home_repository/lib/src/source/mock/mq_home_local_data_source_mock.dart new file mode 100644 index 00000000..e4cb2f05 --- /dev/null +++ b/packages/mq_home_repository/lib/src/source/mock/mq_home_local_data_source_mock.dart @@ -0,0 +1,15 @@ +import 'package:flutter/material.dart'; +import 'package:mq_home_repository/mq_home_repository.dart'; + +@immutable +final class MqHomeLocalDataSourceMock implements MqHomeLocalDataSource { + const MqHomeLocalDataSourceMock(); + + @override + MqHomeModelResponse getLocalData() { + return const MqHomeModelResponse(allDoneHatims: 0, allDonePages: 0, donePages: 0); + } + + @override + Future saveLocalData(MqHomeModelResponse data) => Future.value(); +} diff --git a/packages/mq_home_repository/lib/src/source/mock/mq_home_remote_data_source_mock.dart b/packages/mq_home_repository/lib/src/source/mock/mq_home_remote_data_source_mock.dart new file mode 100644 index 00000000..2dfe164d --- /dev/null +++ b/packages/mq_home_repository/lib/src/source/mock/mq_home_remote_data_source_mock.dart @@ -0,0 +1,16 @@ +import 'package:flutter/material.dart'; +import 'package:mq_home_repository/mq_home_repository.dart'; + +@immutable +final class MqHomeRemoteDataSourceMock implements MqHomeRemoteDataSource { + const MqHomeRemoteDataSourceMock(); + + @override + Future getRemoteData() async { + return const MqHomeModelResponse( + allDoneHatims: 0, + allDonePages: 0, + donePages: 0, + ); + } +} diff --git a/packages/mq_home_repository/lib/src/source/mq_home_local_data_source.dart b/packages/mq_home_repository/lib/src/source/mq_home_local_data_source.dart new file mode 100644 index 00000000..f042faae --- /dev/null +++ b/packages/mq_home_repository/lib/src/source/mq_home_local_data_source.dart @@ -0,0 +1,7 @@ +import 'package:mq_home_repository/mq_home_repository.dart'; + +abstract class MqHomeLocalDataSource { + MqHomeModelResponse getLocalData(); + + Future saveLocalData(MqHomeModelResponse data); +} diff --git a/packages/mq_home_repository/lib/src/source/mq_home_remote_data_source.dart b/packages/mq_home_repository/lib/src/source/mq_home_remote_data_source.dart new file mode 100644 index 00000000..068d68d4 --- /dev/null +++ b/packages/mq_home_repository/lib/src/source/mq_home_remote_data_source.dart @@ -0,0 +1,5 @@ +import 'package:mq_home_repository/mq_home_repository.dart'; + +abstract class MqHomeRemoteDataSource { + Future getRemoteData(); +} diff --git a/packages/mq_home_repository/lib/src/source/remote/mq_home_remote_data_source_impl.dart b/packages/mq_home_repository/lib/src/source/remote/mq_home_remote_data_source_impl.dart new file mode 100644 index 00000000..30cc835e --- /dev/null +++ b/packages/mq_home_repository/lib/src/source/remote/mq_home_remote_data_source_impl.dart @@ -0,0 +1,23 @@ +import 'package:flutter/material.dart'; +import 'package:mq_home_repository/mq_home_repository.dart'; +import 'package:mq_remote_client/mq_remote_client.dart'; + +@immutable +final class MqHomeRemoteDataSourceImpl implements MqHomeRemoteDataSource { + const MqHomeRemoteDataSourceImpl(this.remoteClient); + + final MqRemoteClient remoteClient; + + @override + Future getRemoteData() async { + final remoteValue = await remoteClient.getType( + '/api/v1/hatim/dashboard', + fromJson: MqHomeModelResponse.fromJson, + ); + + return remoteValue.fold( + (left) => throw Exception('Failed to fetch remote data $left'), + (right) => right, + ); + } +} diff --git a/packages/mq_home_repository/lib/src/src.dart b/packages/mq_home_repository/lib/src/src.dart new file mode 100644 index 00000000..806ec419 --- /dev/null +++ b/packages/mq_home_repository/lib/src/src.dart @@ -0,0 +1,14 @@ +// entities +export 'entity/mq_home_entity.dart'; +// models +export 'model/mq_home_model_response.dart'; +// repositories +export 'repository/mq_home_repository.dart'; +export 'repository/mq_home_repository_impl.dart'; +// sources +export 'source/local/mq_home_local_data_source_impl.dart'; +export 'source/mock/mq_home_local_data_source_mock.dart'; +export 'source/mock/mq_home_remote_data_source_mock.dart'; +export 'source/mq_home_local_data_source.dart'; +export 'source/mq_home_remote_data_source.dart'; +export 'source/remote/mq_home_remote_data_source_impl.dart'; diff --git a/packages/mq_home_repository/pubspec.yaml b/packages/mq_home_repository/pubspec.yaml new file mode 100644 index 00000000..b5faa2c1 --- /dev/null +++ b/packages/mq_home_repository/pubspec.yaml @@ -0,0 +1,30 @@ +name: mq_home_repository +description: MQ Home Repository Package +version: 0.1.0+1 +publish_to: none + +environment: + sdk: ^3.5.0 + flutter: ^3.24.0 + +dependencies: + flutter: + sdk: flutter + + json_annotation: ^4.9.0 + + # Packages + mq_crashlytics: + path: ../mq_crashlytics + mq_remote_client: + path: ../mq_remote_client + mq_remote_config: + path: ../mq_remote_config + mq_storage: + path: ../mq_storage + +dev_dependencies: + flutter_test: + sdk: flutter + mocktail: ^1.0.4 + very_good_analysis: ^6.0.0 diff --git a/packages/mq_home_repository/test/mq_home_repository_test.dart b/packages/mq_home_repository/test/mq_home_repository_test.dart new file mode 100644 index 00000000..5c631af5 --- /dev/null +++ b/packages/mq_home_repository/test/mq_home_repository_test.dart @@ -0,0 +1,11 @@ +// ignore_for_file: prefer_const_constructors + +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('MqHomeRepository', () { + test('can be instantiated', () { + expect(1 + 1, 2); + }); + }); +} From 1d00e6889fb86a080b8be8fa46176d5feb969585 Mon Sep 17 00:00:00 2001 From: aidaiym Date: Mon, 16 Dec 2024 20:00:23 +0600 Subject: [PATCH 2/3] fix analytic problem --- app/pubspec_overrides.yaml | 4 +++- packages/mq_home_repository/pubspec_overrides.yaml | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 packages/mq_home_repository/pubspec_overrides.yaml diff --git a/app/pubspec_overrides.yaml b/app/pubspec_overrides.yaml index ed9564f1..4ad09b91 100644 --- a/app/pubspec_overrides.yaml +++ b/app/pubspec_overrides.yaml @@ -1,4 +1,4 @@ -# melos_managed_dependency_overrides: mq_ci_keys,mq_storage,mq_either,mq_analytics,mq_crashlytics,mq_remote_config +# melos_managed_dependency_overrides: mq_ci_keys,mq_storage,mq_either,mq_analytics,mq_crashlytics,mq_remote_config,mq_home_repository dependency_overrides: mq_analytics: path: ../packages/mq_analytics @@ -8,6 +8,8 @@ dependency_overrides: path: ../packages/mq_crashlytics mq_either: path: ../packages/mq_either + mq_home_repository: + path: ../packages/mq_home_repository mq_remote_client: path: ../packages/mq_remote_client mq_remote_config: diff --git a/packages/mq_home_repository/pubspec_overrides.yaml b/packages/mq_home_repository/pubspec_overrides.yaml new file mode 100644 index 00000000..5255f169 --- /dev/null +++ b/packages/mq_home_repository/pubspec_overrides.yaml @@ -0,0 +1,12 @@ +# melos_managed_dependency_overrides: mq_crashlytics,mq_either,mq_remote_client,mq_remote_config,mq_storage +dependency_overrides: + mq_crashlytics: + path: ../mq_crashlytics + mq_either: + path: ../mq_either + mq_remote_client: + path: ../mq_remote_client + mq_remote_config: + path: ../mq_remote_config + mq_storage: + path: ../mq_storage From a7b53cc35d7ad3fa98f2a6e7d10c35c0f465092c Mon Sep 17 00:00:00 2001 From: aidaiym Date: Mon, 16 Dec 2024 21:46:36 +0600 Subject: [PATCH 3/3] fix comments --- app/lib/constants/api/api_const.dart | 1 - .../{presentation => }/cubit/home_cubit.dart | 0 .../{presentation => }/cubit/home_state.dart | 0 .../cubit/location_cubit.dart | 0 .../cubit/location_state.dart | 0 app/lib/modules/home/home.dart | 5 +- .../home/presentation/presentation.dart | 4 -- .../{presentation => }/view/home_view.dart | 0 .../widgets/pray_time_widget.dart | 0 packages/mq_home_repository/README.md | 68 +------------------ 10 files changed, 5 insertions(+), 73 deletions(-) rename app/lib/modules/home/{presentation => }/cubit/home_cubit.dart (100%) rename app/lib/modules/home/{presentation => }/cubit/home_state.dart (100%) rename app/lib/modules/home/{presentation => }/cubit/location_cubit.dart (100%) rename app/lib/modules/home/{presentation => }/cubit/location_state.dart (100%) delete mode 100644 app/lib/modules/home/presentation/presentation.dart rename app/lib/modules/home/{presentation => }/view/home_view.dart (100%) rename app/lib/modules/home/{presentation => }/widgets/pray_time_widget.dart (100%) diff --git a/app/lib/constants/api/api_const.dart b/app/lib/constants/api/api_const.dart index f729adf8..610377e3 100644 --- a/app/lib/constants/api/api_const.dart +++ b/app/lib/constants/api/api_const.dart @@ -16,7 +16,6 @@ class ApiConst { String get loginWithApple => '$_getDomain/api/v1/accounts/apple/'; String get deleteProfile => '$_getDomain/api/v1/accounts/profile/delete_my_account/'; String putProfile(String userId) => '$_getDomain/api/v1/accounts/profile/$userId/'; - // String get hatimDashBoard => '$_getDomain/api/v1/hatim/dashboard'; String get joinToHatim => '$_getDomain/api/v1/hatim/join_to_hatim'; String getSocket(String token) => '$socketBase/?token=$token'; diff --git a/app/lib/modules/home/presentation/cubit/home_cubit.dart b/app/lib/modules/home/cubit/home_cubit.dart similarity index 100% rename from app/lib/modules/home/presentation/cubit/home_cubit.dart rename to app/lib/modules/home/cubit/home_cubit.dart diff --git a/app/lib/modules/home/presentation/cubit/home_state.dart b/app/lib/modules/home/cubit/home_state.dart similarity index 100% rename from app/lib/modules/home/presentation/cubit/home_state.dart rename to app/lib/modules/home/cubit/home_state.dart diff --git a/app/lib/modules/home/presentation/cubit/location_cubit.dart b/app/lib/modules/home/cubit/location_cubit.dart similarity index 100% rename from app/lib/modules/home/presentation/cubit/location_cubit.dart rename to app/lib/modules/home/cubit/location_cubit.dart diff --git a/app/lib/modules/home/presentation/cubit/location_state.dart b/app/lib/modules/home/cubit/location_state.dart similarity index 100% rename from app/lib/modules/home/presentation/cubit/location_state.dart rename to app/lib/modules/home/cubit/location_state.dart diff --git a/app/lib/modules/home/home.dart b/app/lib/modules/home/home.dart index 29b200c9..b1b8619e 100644 --- a/app/lib/modules/home/home.dart +++ b/app/lib/modules/home/home.dart @@ -1 +1,4 @@ -export 'presentation/presentation.dart'; +export 'cubit/home_cubit.dart'; +export 'cubit/location_cubit.dart'; +export 'view/home_view.dart'; +export 'widgets/pray_time_widget.dart'; diff --git a/app/lib/modules/home/presentation/presentation.dart b/app/lib/modules/home/presentation/presentation.dart deleted file mode 100644 index b1b8619e..00000000 --- a/app/lib/modules/home/presentation/presentation.dart +++ /dev/null @@ -1,4 +0,0 @@ -export 'cubit/home_cubit.dart'; -export 'cubit/location_cubit.dart'; -export 'view/home_view.dart'; -export 'widgets/pray_time_widget.dart'; diff --git a/app/lib/modules/home/presentation/view/home_view.dart b/app/lib/modules/home/view/home_view.dart similarity index 100% rename from app/lib/modules/home/presentation/view/home_view.dart rename to app/lib/modules/home/view/home_view.dart diff --git a/app/lib/modules/home/presentation/widgets/pray_time_widget.dart b/app/lib/modules/home/widgets/pray_time_widget.dart similarity index 100% rename from app/lib/modules/home/presentation/widgets/pray_time_widget.dart rename to app/lib/modules/home/widgets/pray_time_widget.dart diff --git a/packages/mq_home_repository/README.md b/packages/mq_home_repository/README.md index 6b5e01c0..41098740 100644 --- a/packages/mq_home_repository/README.md +++ b/packages/mq_home_repository/README.md @@ -1,67 +1 @@ -# Mq Home Repository - -[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link] -[![Powered by Mason](https://img.shields.io/endpoint?url=https%3A%2F%2Ftinyurl.com%2Fmason-badge)](https://github.com/felangel/mason) -[![License: MIT][license_badge]][license_link] - -MQ Home Repository Package - -## Installation ๐Ÿ’ป - -**โ— In order to start using Mq Home Repository you must have the [Flutter SDK][flutter_install_link] installed on your machine.** - -Install via `flutter pub add`: - -```sh -dart pub add mq_home_repository -``` - ---- - -## Continuous Integration ๐Ÿค– - -Mq Home Repository comes with a built-in [GitHub Actions workflow][github_actions_link] powered by [Very Good Workflows][very_good_workflows_link] but you can also add your preferred CI/CD solution. - -Out of the box, on each pull request and push, the CI `formats`, `lints`, and `tests` the code. This ensures the code remains consistent and behaves correctly as you add functionality or make changes. The project uses [Very Good Analysis][very_good_analysis_link] for a strict set of analysis options used by our team. Code coverage is enforced using the [Very Good Workflows][very_good_coverage_link]. - ---- - -## Running Tests ๐Ÿงช - -For first time users, install the [very_good_cli][very_good_cli_link]: - -```sh -dart pub global activate very_good_cli -``` - -To run all unit tests: - -```sh -very_good test --coverage -``` - -To view the generated coverage report you can use [lcov](https://github.com/linux-test-project/lcov). - -```sh -# Generate Coverage Report -genhtml coverage/lcov.info -o coverage/ - -# Open Coverage Report -open coverage/index.html -``` - -[flutter_install_link]: https://docs.flutter.dev/get-started/install -[github_actions_link]: https://docs.github.com/en/actions/learn-github-actions -[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg -[license_link]: https://opensource.org/licenses/MIT -[logo_black]: https://raw.githubusercontent.com/VGVentures/very_good_brand/main/styles/README/vgv_logo_black.png#gh-light-mode-only -[logo_white]: https://raw.githubusercontent.com/VGVentures/very_good_brand/main/styles/README/vgv_logo_white.png#gh-dark-mode-only -[mason_link]: https://github.com/felangel/mason -[very_good_analysis_badge]: https://img.shields.io/badge/style-very_good_analysis-B22C89.svg -[very_good_analysis_link]: https://pub.dev/packages/very_good_analysis -[very_good_cli_link]: https://pub.dev/packages/very_good_cli -[very_good_coverage_link]: https://github.com/marketplace/actions/very-good-coverage -[very_good_ventures_link]: https://verygood.ventures -[very_good_ventures_link_light]: https://verygood.ventures#gh-light-mode-only -[very_good_ventures_link_dark]: https://verygood.ventures#gh-dark-mode-only -[very_good_workflows_link]: https://github.com/VeryGoodOpenSource/very_good_workflows +# Mq Home Repository Package \ No newline at end of file