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 all 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
1 change: 0 additions & 1 deletion app/lib/constants/api/api_const.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

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
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
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
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.

7 changes: 4 additions & 3 deletions app/lib/modules/home/home.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export 'data/data.dart';
export 'domain/domain.dart';
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';
4 changes: 0 additions & 4 deletions app/lib/modules/home/presentation/presentation.dart

This file was deleted.

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
1 change: 1 addition & 0 deletions packages/mq_home_repository/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Mq Home Repository Package
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
Original file line number Diff line number Diff line change
@@ -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<String, dynamic> json) => _$HomeModelResponseFromJson(json);
factory MqHomeModelResponse.fromJson(Map<String, dynamic> json) => _$HomeModelResponseFromJson(json);
Map<String, dynamic> toJson() => _$HomeModelResponseToJson(this);

final int allDoneHatims;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:mq_home_repository/mq_home_repository.dart';

abstract interface class MqHomeRepository {
Future<MqHomeEntity> getData();
}
Loading
Loading