Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Home Repo Package #277

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions app/lib/app/presentation/view/app_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -79,15 +80,13 @@ class MyApp extends StatelessWidget {
),
BlocProvider(
create: (context) => HomeCubit(
GetHomeDataUseCase(
HomeRepositoryImpl(
isMockData
? const HomeLocalDataSourceMock()
: HomeLocalDataSourceImpl(context.read<PreferencesStorage>()),
isMockData
? const HomeRemoteDataSourceMock()
: HomeRemoteDataSourceImpl(context.read<MqRemoteClient>()),
),
MqHomeRepositoryImpl(
isMockData
? const MqHomeLocalDataSourceMock()
: MqHomeLocalDataSourceImpl(context.read<PreferencesStorage>()),
isMockData
? const MqHomeRemoteDataSourceMock()
: MqHomeRemoteDataSourceImpl(context.read<MqRemoteClient>()),
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion app/lib/constants/api/api_const.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
aidaiym marked this conversation as resolved.
Show resolved Hide resolved
String get joinToHatim => '$_getDomain/api/v1/hatim/join_to_hatim';
String getSocket(String token) => '$socketBase/?token=$token';

Expand Down
4 changes: 3 additions & 1 deletion app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ Future<void> main({AppConfig? appConfig}) async {
RepositoryProvider<MqRemoteConfig>(create: (context) => remoteConfig),
RepositoryProvider<MqRemoteClient>(
create: (context) => MqRemoteClient(
dio: Dio(),
dio: Dio(
BaseOptions(baseUrl: ApiConst.domain),
),
network: context.read<NetworkClient>(),
language: () => storage.readString(key: StorageKeys.localeKey),
token: () => storage.readString(key: StorageKeys.tokenKey),
Expand Down
8 changes: 0 additions & 8 deletions app/lib/modules/home/data/data.dart

This file was deleted.

7 changes: 0 additions & 7 deletions app/lib/modules/home/data/source/home_local_data_source.dart

This file was deleted.

5 changes: 0 additions & 5 deletions app/lib/modules/home/data/source/home_remote_data_source.dart

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions app/lib/modules/home/domain/domain.dart

This file was deleted.

5 changes: 0 additions & 5 deletions app/lib/modules/home/domain/repository/home_repository.dart

This file was deleted.

13 changes: 0 additions & 13 deletions app/lib/modules/home/domain/usecase/get_data_usecase.dart

This file was deleted.

2 changes: 0 additions & 2 deletions app/lib/modules/home/home.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export 'data/data.dart';
export 'domain/domain.dart';
export 'presentation/presentation.dart';
8 changes: 4 additions & 4 deletions app/lib/modules/home/presentation/cubit/home_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<HomeState> {
HomeCubit(this.getHomeDataUseCase) : super(const HomeState());
HomeCubit(this.homeRepository) : super(const HomeState());

final GetHomeDataUseCase getHomeDataUseCase;
final MqHomeRepository homeRepository;

Future<void> 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);
Expand Down
2 changes: 1 addition & 1 deletion app/lib/modules/home/presentation/cubit/home_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ final class HomeState extends Equatable {
this.homeModel,
});

final HomeEntity? homeModel;
final MqHomeEntity? homeModel;
final FetchStatus status;

@override
Expand Down
7 changes: 7 additions & 0 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion app/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions app/test/helpers/pump_app.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -17,7 +18,7 @@ extension PumpApp on WidgetTester {
GoogleSignInUseCase googleSignInUseCase,
AppleSignInUseCase appleSignInUseCase,
SerUserDataUseCase setUserDataUseCase,
HomeRepository homeRepo,
MqHomeRepository homeRepo,
PatchGenderUseCase patchGenderUseCase,
PatchLocaleCodeUseCase patchLocaleCodeUseCase,
LogoutUseCase logoutUseCase,
Expand Down Expand Up @@ -58,7 +59,7 @@ extension PumpApp on WidgetTester {
),
),
BlocProvider(
create: (context) => HomeCubit(GetHomeDataUseCase(homeRepo)),
create: (context) => HomeCubit(homeRepo),
),
BlocProvider(
create: (context) => RemoteConfigCubit(
Expand Down
8 changes: 4 additions & 4 deletions app/test/mocks/app_mocks.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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';

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 {}

Expand All @@ -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<HomeEntity> getData() async {
return const HomeEntity(allDoneHatims: 8, allDonePages: 5325, donePages: 634);
Future<MqHomeEntity> getData() async {
return const MqHomeEntity(allDoneHatims: 8, allDonePages: 5325, donePages: 634);
}
}

Expand Down
67 changes: 67 additions & 0 deletions packages/mq_home_repository/README.md
aidaiym marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions packages/mq_home_repository/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions packages/mq_home_repository/lib/mq_home_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// MQ Home Repository Package
library mq_home_repository;

export 'src/src.dart';
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Loading
Loading