Skip to content

Commit

Permalink
Merge pull request #3 from IliaKhuzhakhmetov/refator
Browse files Browse the repository at this point in the history
Refator
  • Loading branch information
IliaKhuzhakhmetov authored Oct 26, 2023
2 parents 3fc6031 + 5c2038b commit 8326289
Show file tree
Hide file tree
Showing 86 changed files with 2,019 additions and 1,205 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Install dependencies
run: flutter pub get

- name: Generate Freezed classes
- name: Generate classes
run: flutter pub run build_runner build --delete-conflicting-outputs

- name: Analyze project source
Expand Down
11 changes: 1 addition & 10 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ linter:
# Type check for Iterable<T>.contains(other) where other is! T
# otherwise contains will always report false. Those errors are usually very hard to catch.
# https://dart-lang.github.io/linter/lints/iterable_contains_unrelated_type.html
- iterable_contains_unrelated_type
- collection_methods_unrelated_type

# Hint to join return and assignment.
# pedantic: disabled
Expand Down Expand Up @@ -395,11 +395,6 @@ linter:
# https://dart-lang.github.io/linter/lints/lines_longer_than_80_chars.html
# - lines_longer_than_80_chars

# Type check for List<T>.remove(item) where item is! T
# The list can't contain item. Those errors are not directly obvious especially when refactoring.
# https://dart-lang.github.io/linter/lints/list_remove_unrelated_type.html
- list_remove_unrelated_type

# Good for libraries to prevent unnecessary code paths.
# False positives may occur for applications when boolean properties are generated by external programs
# producing auto-generated source code
Expand Down Expand Up @@ -543,10 +538,6 @@ linter:
# https://dart-lang.github.io/linter/lints/prefer_double_quotes.html
# - prefer_double_quotes

# Prevent confusion with call-side when using named parameters
# pedantic: enabled
# https://dart-lang.github.io/linter/lints/prefer_equal_for_default_values.html
- prefer_equal_for_default_values

# Single line methods + implementation makes it hard to write comments for that line.
# Dense code isn't necessarily better code.
Expand Down
3 changes: 2 additions & 1 deletion ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -222,6 +222,7 @@
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
101 changes: 0 additions & 101 deletions lib/core/base/injectable_state.dart

This file was deleted.

4 changes: 4 additions & 0 deletions lib/core/base/mapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
abstract class Mapper<E, M> {
E fromModel(M model);
M toModel(E entity);
}
3 changes: 0 additions & 3 deletions lib/core/base/state_mixins.dart

This file was deleted.

26 changes: 17 additions & 9 deletions lib/core/di/di.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
import 'package:e_shop_flutter/data/datasources/local_items.datasource.dart';
import 'package:e_shop_flutter/data/mappers/item_mapper.dart';
import 'package:e_shop_flutter/data/mappers/purchase_mapper.dart';
import 'package:e_shop_flutter/data/repositories/items.repository_impl.dart';
import 'package:e_shop_flutter/data/repositories/purchase.repository_impl.dart';
import 'package:e_shop_flutter/data/services/app_settings/app_settings.dart';
import 'package:e_shop_flutter/data/services/local_database/database.dart';
import 'package:e_shop_flutter/domain/repositories/items.repository.dart';
import 'package:e_shop_flutter/domain/repositories/purchases.repository.dart';
import 'package:e_shop_flutter/domain/usecases/add_new_purchase.usecase.dart';
import 'package:e_shop_flutter/domain/usecases/change_app_theme_brighness.usecase.dart';
import 'package:e_shop_flutter/domain/usecases/change_app_theme_brightness.usecase.dart';
import 'package:e_shop_flutter/domain/usecases/delete_purchase.usecase.dart';
import 'package:e_shop_flutter/domain/usecases/get_purchases.usecase.dart';
import 'package:e_shop_flutter/domain/usecases/get_saved_brighness.usecase.dart';
import 'package:e_shop_flutter/presentation/add_purchase/add_item_dialog/logic/add_item_dialog.cubit.dart';
import 'package:e_shop_flutter/presentation/add_purchase/logic/add_purchase.cubit.dart';
import 'package:e_shop_flutter/presentation/application/logic/application.cubit.dart';
import 'package:e_shop_flutter/presentation/purchase/logic/purchase.cubit.dart';
import 'package:e_shop_flutter/presentation/purchases/logic/purchases.cubit.dart';
import 'package:e_shop_flutter/domain/usecases/get_saved_brightness.usecase.dart';
import 'package:e_shop_flutter/presentation/cubits/add_purchase_cubit/add_purchase.cubit.dart';
import 'package:e_shop_flutter/presentation/cubits/application_cubit/application.cubit.dart';
import 'package:e_shop_flutter/presentation/cubits/delete_purchase_cubit/delete_purchase.cubit.dart';
import 'package:e_shop_flutter/presentation/cubits/get_all_purchases_cubit/get_all_purchases_cubit.dart';
import 'package:e_shop_flutter/presentation/cubits/get_items_by_purchase_cubit/get_Items_by_purchase.cubit.dart';
import 'package:e_shop_flutter/presentation/cubits/items_cubit/items_cubit.dart';
import 'package:e_shop_flutter/presentation/cubits/pick_date_cubit/pick_date_cubit.dart';
import 'package:e_shop_flutter/presentation/cubits/validation_cubit/validation_cubit.dart';
import 'package:get_it/get_it.dart';
import 'package:shared_preferences/shared_preferences.dart';

part 'src/cubits.dart';
part 'src/datasources.dart';
part 'src/mappers.dart';
part 'src/repositories.dart';
part 'src/usecases.dart';
part 'src/datasources.dart';

final GetIt locator = GetIt.instance;

Expand All @@ -30,7 +36,9 @@ void setUp() {
locator.registerLazySingleton(() => AppSettings(locator.get()));
locator.registerSingletonAsync(() => Future.value(LocalDatabase()));

_registerRespositories();
_registerMappers();
_registerDatasources();
_registerRepositories();
_registerUsecases();
_registerCubits();
}
26 changes: 17 additions & 9 deletions lib/core/di/src/cubits.dart
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
part of '../di.dart';

void _registerCubits() {
locator.registerFactory(() => AddItemDialogCubit());
locator.registerFactory(() => ItemsCubit());

locator.registerLazySingleton(
locator.registerFactory(() => PickDateCubit());

locator.registerFactory(() => ValidationCubit());

locator.registerFactory(
() => DeletePurchaseCubit(deletePurchaseUsecase: locator()),
);

locator.registerFactory(
() => ApplicationCubit(
changeAppThemeBrighnessUseCase: locator.get(),
getSavedBrightnessUseCase: locator.get(),
changeAppThemeBrightnessUseCase: locator(),
getSavedBrightnessUseCase: locator(),
),
);

// PurchaseCubit
locator.registerFactory(() => PurchaseCubit(itemsRepository: locator.get()));
locator.registerFactory(
() => GetItemsByPurchaseCubit(itemsRepository: locator()));

// PurchasesCubit
locator.registerFactory(
() => PurchasesCubit(
deletePurchaseUsecase: locator.get(),
getPurchasesUsecase: locator.get(),
() => GetAllPurchasesCubit(
getPurchasesUsecase: locator(),
),
);

// AddPurchaseCubit
locator.registerFactory(
() => AddPurchaseCubit(
addNewPurchaseUseCase: locator.get(),
addNewPurchaseUseCase: locator(),
),
);
}
2 changes: 1 addition & 1 deletion lib/core/di/src/datasources.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
part of '../di.dart';

void registerDatasources() {
void _registerDatasources() {
locator.registerLazySingleton<LocalItemsDatasource>(
() => LocalItemsDatasourceImpl(
itemDao: locator.get<LocalDatabase>().itemsDao,
Expand Down
6 changes: 6 additions & 0 deletions lib/core/di/src/mappers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
part of '../di.dart';

void _registerMappers() {
locator.registerLazySingleton(() => PurchaseMapper());
locator.registerLazySingleton(() => ItemMapper());
}
4 changes: 3 additions & 1 deletion lib/core/di/src/repositories.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
part of '../di.dart';

void _registerRespositories() {
void _registerRepositories() {
locator.registerLazySingleton<ItemsRepository>(
() => ItemsRepositoryImpl(
itemMapper: locator<ItemMapper>(),
itemDatasource: locator(),
),
);

locator.registerLazySingleton<PurchasesRepository>(
() => PurchasesRepositoryImpl(
purchaseMapper: locator<PurchaseMapper>(),
dao: locator.get<LocalDatabase>().purchaseDao,
),
);
Expand Down
15 changes: 9 additions & 6 deletions lib/core/di/src/usecases.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ part of '../di.dart';

void _registerUsecases() {
locator.registerFactory(
() => GetSavedBrightnessUseCase(appSettings: locator.get()));
() => GetSavedBrightnessUseCase(appSettings: locator()),
);

locator.registerFactory(
() => ChangeAppThemeBrighnessUseCase(appSettings: locator.get()));
() => ChangeAppThemeBrightnessUseCase(appSettings: locator()),
);

locator.registerFactory(
() => AddNewPurchaseUseCase(
purchasesRepository: locator.get(),
itemsRepository: locator.get(),
purchasesRepository: locator(),
itemsRepository: locator(),
),
);

locator.registerFactory(
() => DeletePurchaseUsecase(purchasesRepository: locator.get()),
() => DeletePurchaseUsecase(purchasesRepository: locator()),
);

locator.registerFactory(
() => GetPurchasesUsecase(purchasesRepository: locator.get()));
() => GetPurchasesUsecase(purchasesRepository: locator()),
);
}
6 changes: 6 additions & 0 deletions lib/core/extensions/date.extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:intl/intl.dart';

extension DateExtension on DateTime {
String formattedDate({String format = 'dd MMMM yyyy'}) =>
DateFormat(format).format(this);
}
13 changes: 13 additions & 0 deletions lib/core/validations/text_validations.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
abstract class TextValidations {
static String? isNotEmpty(String? value) {
return value?.isNotEmpty == true ? null : 'Can not be empty';
}

static String? isCorrectPrice(String? value) {
final parsed = double.tryParse(value?.replaceAll(',', '.') ?? '');

return value?.isNotEmpty == true && parsed != null && parsed > 0
? null
: 'Incorrect price';
}
}
8 changes: 4 additions & 4 deletions lib/data/datasources/local_items.datasource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:e_shop_flutter/data/services/local_database/dao/items_dao/items_
import 'package:e_shop_flutter/data/services/local_database/database.dart';

abstract class LocalItemsDatasource {
Future addItems(List<ItemData> itemsData);
Future<List<ItemData>> getItemsBypurchaseId(int purchaseId);
Future addItems(List<ItemTableData> itemsData);
Future<List<ItemTableData>> getItemsPurchaseId(int purchaseId);
}

// TODO: Refactor ItemData to ItemView
Expand All @@ -15,10 +15,10 @@ class LocalItemsDatasourceImpl extends LocalItemsDatasource {
}) : _dao = itemDao;

@override
Future<void> addItems(List<ItemData> itemsData) =>
Future<void> addItems(List<ItemTableData> itemsData) =>
_dao.insertValues(itemsData);

@override
Future<List<ItemData>> getItemsBypurchaseId(int purchaseId) =>
Future<List<ItemTableData>> getItemsPurchaseId(int purchaseId) =>
_dao.getItemsByPurchaseId(purchaseId);
}
Loading

0 comments on commit 8326289

Please sign in to comment.