Skip to content

Commit

Permalink
Merge pull request #202 from Eldar2021/ai/change-quran-architecture
Browse files Browse the repository at this point in the history
changed quran module architecture
  • Loading branch information
Eldar2021 authored Mar 30, 2024
2 parents 7e9f69a + 171b93d commit 1d3cef0
Show file tree
Hide file tree
Showing 27 changed files with 264 additions and 60 deletions.
5 changes: 0 additions & 5 deletions app/lib/models/models.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
export 'hatim/hatim_juz.dart';
export 'hatim/hatim_page.dart';
export 'hatim/hatim_read_model.dart';
export 'juz/juz_data.dart';
export 'juz/juz_model.dart';
export 'juz/juz_surah_model.dart';
export 'surah/surah_data.dart';
export 'surah/surah_model.dart';
8 changes: 8 additions & 0 deletions app/lib/modules/quran/data/data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export 'model/juz_model.dart';
export 'model/juz_surah_model.dart';
export 'model/surah_model.dart';
export 'source/juz_data.dart';
export 'source/juz_local_data_source.dart';
export 'source/surah_data.dart';
export 'source/surah_local_data_source.dart';
export 'repository/quran_repository_impl.dart';
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import 'package:flutter/foundation.dart';
import 'package:json_annotation/json_annotation.dart';

import 'package:my_quran/models/models.dart';
import 'package:my_quran/modules/modules.dart';

part 'juz_model.g.dart';

@immutable
@JsonSerializable()
final class Juz {
const Juz({
final class JuzResponse {
const JuzResponse({
required this.id,
required this.name,
required this.pages,
required this.surahs,
});

factory Juz.fromJson(Map<String, dynamic> json) => _$JuzFromJson(json);
Map<String, dynamic> toJson() => _$JuzToJson(this);
factory JuzResponse.fromJson(Map<String, dynamic> json) => _$JuzResponseFromJson(json);
Map<String, dynamic> toJson() => _$JuzResponseToJson(this);

final int id;
final String name;
final List<int> pages;
final List<JuzSurah> surahs;
final List<JuzSurahResponse> surahs;
}

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
Expand Up @@ -5,15 +5,15 @@ part 'juz_surah_model.g.dart';

@immutable
@JsonSerializable()
final class JuzSurah {
const JuzSurah({
final class JuzSurahResponse {
const JuzSurahResponse({
required this.name,
required this.arName,
required this.pages,
});

factory JuzSurah.fromJson(Map<String, dynamic> json) => _$JuzSurahFromJson(json);
Map<String, dynamic> toJson() => _$JuzSurahToJson(this);
factory JuzSurahResponse.fromJson(Map<String, dynamic> json) => _$JuzSurahResponseFromJson(json);
Map<String, dynamic> toJson() => _$JuzSurahResponseToJson(this);

final String name;
final String arName;
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
Expand Up @@ -5,27 +5,21 @@ part 'surah_model.g.dart';

@immutable
@JsonSerializable()
final class Surah {
const Surah({
final class SurahResponse {
const SurahResponse({
required this.id,
required this.name,
required this.aya,
required this.pages,
required this.arabic,
});

factory Surah.fromJson(Map<String, dynamic> json) => _$SurahFromJson(json);
Map<String, dynamic> toJson() => _$SurahToJson(this);
factory SurahResponse.fromJson(Map<String, dynamic> json) => _$SurahResponseFromJson(json);
Map<String, dynamic> toJson() => _$SurahResponseToJson(this);

final int id;
final String name;
final int aya;
final List<int> pages;
final String arabic;

String get surahPath {
if (id < 10) return '00$id';
if (id < 100) return '0$id';
return '$id';
}
}

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

56 changes: 56 additions & 0 deletions app/lib/modules/quran/data/repository/quran_repository_impl.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'package:meta/meta.dart';
import 'package:my_quran/modules/modules.dart';

@immutable
final class QuranRepositoryImpl implements QuranRepository {
const QuranRepositoryImpl(
this.juzLocalDataSource,
this.surahLocalDataSource,
);

final JuzLocalDataSource juzLocalDataSource;
final SurahLocalDataSource surahLocalDataSource;

@override
List<JuzEntity> getJuzs() {
final juzResponses = juzLocalDataSource.getJuzsFromLocal();
final juzEntities = juzResponses.map(_convertJuzData).toList();
return juzEntities;
}

@override
List<SurahEntity> getSurahs() {
final surahResponses = surahLocalDataSource.getSurahsFromLocal();
final surahEntities = surahResponses.map(_convertSurahData).toList();
return surahEntities;
}

JuzEntity _convertJuzData(JuzResponse response) {
final convertedSurahs = response.surahs
.map(
(juzSurahResponse) => JuzSurahEntity(
name: juzSurahResponse.name,
arName: juzSurahResponse.arName,
pages: juzSurahResponse.pages,
),
)
.toList();

return JuzEntity(
id: response.id,
name: response.name,
pages: response.pages,
surahs: convertedSurahs,
);
}

SurahEntity _convertSurahData(SurahResponse response) {
return SurahEntity(
id: response.id,
name: response.name,
aya: response.aya,
pages: response.pages,
arabic: response.arabic,
);
}
}
File renamed without changes.
10 changes: 10 additions & 0 deletions app/lib/modules/quran/data/source/juz_local_data_source.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:meta/meta.dart';
import 'package:my_quran/modules/modules.dart';

@immutable
final class JuzLocalDataSource {
List<JuzResponse> getJuzsFromLocal() {
final juzs = juzData.map(JuzResponse.fromJson).toList();
return juzs;
}
}
File renamed without changes.
10 changes: 10 additions & 0 deletions app/lib/modules/quran/data/source/surah_local_data_source.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:meta/meta.dart';
import 'package:my_quran/modules/modules.dart';

@immutable
final class SurahLocalDataSource {
List<SurahResponse> getSurahsFromLocal() {
final surahs = surahData.map(SurahResponse.fromJson).toList();
return surahs;
}
}
6 changes: 6 additions & 0 deletions app/lib/modules/quran/domain/domain.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export 'entity/juz_entity.dart';
export 'entity/juz_surah_entity.dart';
export 'entity/surah_entity.dart';
export 'repository/quran_repository.dart';
export 'usecase/get_juzs.dart';
export 'usecase/get_surahs.dart';
17 changes: 17 additions & 0 deletions app/lib/modules/quran/domain/entity/juz_entity.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:meta/meta.dart';
import 'package:my_quran/modules/modules.dart';

@immutable
final class JuzEntity {
const JuzEntity({
required this.id,
required this.name,
required this.pages,
required this.surahs,
});

final int id;
final String name;
final List<int> pages;
final List<JuzSurahEntity> surahs;
}
14 changes: 14 additions & 0 deletions app/lib/modules/quran/domain/entity/juz_surah_entity.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:meta/meta.dart';

@immutable
final class JuzSurahEntity {
const JuzSurahEntity({
required this.name,
required this.arName,
required this.pages,
});

final String name;
final String arName;
final List<int> pages;
}
24 changes: 24 additions & 0 deletions app/lib/modules/quran/domain/entity/surah_entity.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:meta/meta.dart';

@immutable
final class SurahEntity {
const SurahEntity({
required this.id,
required this.name,
required this.aya,
required this.pages,
required this.arabic,
});

final int id;
final String name;
final int aya;
final List<int> pages;
final String arabic;

String get surahPath {
if (id < 10) return '00$id';
if (id < 100) return '0$id';
return '$id';
}
}
6 changes: 6 additions & 0 deletions app/lib/modules/quran/domain/repository/quran_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:my_quran/modules/modules.dart';

abstract class QuranRepository {
List<JuzEntity> getJuzs();
List<SurahEntity> getSurahs();
}
13 changes: 13 additions & 0 deletions app/lib/modules/quran/domain/usecase/get_juzs.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:meta/meta.dart';
import 'package:my_quran/modules/modules.dart';

@immutable
final class GetJuzUseCase {
const GetJuzUseCase(this.repository);

final QuranRepository repository;

List<JuzEntity> call() {
return repository.getJuzs();
}
}
13 changes: 13 additions & 0 deletions app/lib/modules/quran/domain/usecase/get_surahs.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:meta/meta.dart';
import 'package:my_quran/modules/modules.dart';

@immutable
final class GetSurahsUseCase {
const GetSurahsUseCase(this.repository);

final QuranRepository repository;

List<SurahEntity> call() {
return repository.getSurahs();
}
}
13 changes: 0 additions & 13 deletions app/lib/modules/quran/logic/quran_cubit.dart

This file was deleted.

22 changes: 22 additions & 0 deletions app/lib/modules/quran/presentation/cubit/quran_cubit.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:my_quran/modules/modules.dart';

class QuranCubit extends Cubit<int> {
QuranCubit({
required this.getJuzUseCase,
required this.getSurahsUseCase,
}) : super(0);

final GetJuzUseCase getJuzUseCase;
final GetSurahsUseCase getSurahsUseCase;

void change(int? val) => emit(val ?? 0);

List<JuzEntity> getJuz() {
return getJuzUseCase();
}

List<SurahEntity> getSurah() {
return getSurahsUseCase();
}
}
3 changes: 3 additions & 0 deletions app/lib/modules/quran/presentation/presentation.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export 'cubit/quran_cubit.dart';
export 'view/page_view_item.dart';
export 'view/quran_view.dart';
Loading

0 comments on commit 1d3cef0

Please sign in to comment.