Refactor
This commit is contained in:
parent
a6078af25a
commit
fe94e3886a
|
|
@ -1,3 +1,4 @@
|
||||||
const String kAppVersion = 'v0.0.1';
|
const String kAppVersion = 'v0.0.1';
|
||||||
|
|
||||||
|
const String kStateFilename = 'state';
|
||||||
const int kMillisecondsToRefreshData = 1000 * 60 * 10;
|
const int kMillisecondsToRefreshData = 1000 * 60 * 10;
|
||||||
|
|
@ -9,11 +9,9 @@ import 'package:invoiceninja/data/file_storage.dart';
|
||||||
import 'package:invoiceninja/data/web_client.dart';
|
import 'package:invoiceninja/data/web_client.dart';
|
||||||
|
|
||||||
class AuthRepository {
|
class AuthRepository {
|
||||||
final FileStorage fileStorage;
|
|
||||||
final WebClient webClient;
|
final WebClient webClient;
|
||||||
|
|
||||||
const AuthRepository({
|
const AuthRepository({
|
||||||
@required this.fileStorage,
|
|
||||||
this.webClient = const WebClient(),
|
this.webClient = const WebClient(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,9 @@ import 'package:invoiceninja/data/file_storage.dart';
|
||||||
import 'package:invoiceninja/data/web_client.dart';
|
import 'package:invoiceninja/data/web_client.dart';
|
||||||
|
|
||||||
class DashboardRepository {
|
class DashboardRepository {
|
||||||
final FileStorage fileStorage;
|
|
||||||
final WebClient webClient;
|
final WebClient webClient;
|
||||||
|
|
||||||
const DashboardRepository({
|
const DashboardRepository({
|
||||||
@required this.fileStorage,
|
|
||||||
this.webClient = const WebClient(),
|
this.webClient = const WebClient(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -21,24 +19,9 @@ class DashboardRepository {
|
||||||
final response = await webClient.get(
|
final response = await webClient.get(
|
||||||
auth.url + '/dashboard', company.token);
|
auth.url + '/dashboard', company.token);
|
||||||
|
|
||||||
//fileStorage.saveDashboard(products);
|
|
||||||
|
|
||||||
DashboardResponse dashboardResponse = serializers.deserializeWith(
|
DashboardResponse dashboardResponse = serializers.deserializeWith(
|
||||||
DashboardResponse.serializer, response);
|
DashboardResponse.serializer, response);
|
||||||
|
|
||||||
return dashboardResponse.data;
|
return dashboardResponse.data;
|
||||||
|
|
||||||
/*
|
|
||||||
try {
|
|
||||||
return await fileStorage.loadData();
|
|
||||||
} catch (exception) {
|
|
||||||
final products = await webClient.fetchData(
|
|
||||||
auth.url + '/products', auth.token);
|
|
||||||
|
|
||||||
//fileStorage.saveDashboard(products);
|
|
||||||
|
|
||||||
return products;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -11,11 +11,9 @@ import 'package:invoiceninja/data/file_storage.dart';
|
||||||
import 'package:invoiceninja/data/web_client.dart';
|
import 'package:invoiceninja/data/web_client.dart';
|
||||||
|
|
||||||
class ProductsRepository {
|
class ProductsRepository {
|
||||||
final FileStorage fileStorage;
|
|
||||||
final WebClient webClient;
|
final WebClient webClient;
|
||||||
|
|
||||||
const ProductsRepository({
|
const ProductsRepository({
|
||||||
@required this.fileStorage,
|
|
||||||
this.webClient = const WebClient(),
|
this.webClient = const WebClient(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:invoiceninja/constants.dart';
|
||||||
import 'package:invoiceninja/data/file_storage.dart';
|
import 'package:invoiceninja/data/file_storage.dart';
|
||||||
import 'package:invoiceninja/data/repositories/persistence_repository.dart';
|
import 'package:invoiceninja/data/repositories/persistence_repository.dart';
|
||||||
import 'package:invoiceninja/redux/app/app_state.dart';
|
import 'package:invoiceninja/redux/app/app_state.dart';
|
||||||
|
|
@ -12,7 +13,7 @@ import 'package:path_provider/path_provider.dart';
|
||||||
List<Middleware<AppState>> createStorePersistenceMiddleware([
|
List<Middleware<AppState>> createStorePersistenceMiddleware([
|
||||||
PersistenceRepository repository = const PersistenceRepository(
|
PersistenceRepository repository = const PersistenceRepository(
|
||||||
fileStorage: const FileStorage(
|
fileStorage: const FileStorage(
|
||||||
'state',
|
kStateFilename,
|
||||||
getApplicationDocumentsDirectory,
|
getApplicationDocumentsDirectory,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,7 @@ import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:invoiceninja/redux/company/company_actions.dart';
|
import 'package:invoiceninja/redux/company/company_actions.dart';
|
||||||
|
|
||||||
List<Middleware<AppState>> createStoreAuthMiddleware([
|
List<Middleware<AppState>> createStoreAuthMiddleware([
|
||||||
AuthRepository repository = const AuthRepository(
|
AuthRepository repository = const AuthRepository(),
|
||||||
fileStorage: const FileStorage(
|
|
||||||
'__invoiceninja__',
|
|
||||||
getApplicationDocumentsDirectory,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]) {
|
]) {
|
||||||
final loginInit = _createLoginInit();
|
final loginInit = _createLoginInit();
|
||||||
final loginRequest = _createLoginRequest(repository);
|
final loginRequest = _createLoginRequest(repository);
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,7 @@ import 'package:invoiceninja/data/repositories/dashboard_repository.dart';
|
||||||
import 'package:invoiceninja/data/file_storage.dart';
|
import 'package:invoiceninja/data/file_storage.dart';
|
||||||
|
|
||||||
List<Middleware<AppState>> createStoreDashboardMiddleware([
|
List<Middleware<AppState>> createStoreDashboardMiddleware([
|
||||||
DashboardRepository repository = const DashboardRepository(
|
DashboardRepository repository = const DashboardRepository(),
|
||||||
fileStorage: const FileStorage(
|
|
||||||
'__invoiceninja__',
|
|
||||||
getApplicationDocumentsDirectory,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]) {
|
]) {
|
||||||
final loadDashboard = _createLoadDashboard(repository);
|
final loadDashboard = _createLoadDashboard(repository);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,7 @@ import 'package:invoiceninja/data/repositories/product_repository.dart';
|
||||||
import 'package:invoiceninja/data/file_storage.dart';
|
import 'package:invoiceninja/data/file_storage.dart';
|
||||||
|
|
||||||
List<Middleware<AppState>> createStoreProductsMiddleware([
|
List<Middleware<AppState>> createStoreProductsMiddleware([
|
||||||
ProductsRepository repository = const ProductsRepository(
|
ProductsRepository repository = const ProductsRepository(),
|
||||||
fileStorage: const FileStorage(
|
|
||||||
'__invoiceninja__',
|
|
||||||
getApplicationDocumentsDirectory,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
]) {
|
]) {
|
||||||
final loadProducts = _loadProducts(repository);
|
final loadProducts = _loadProducts(repository);
|
||||||
final saveProduct = _saveProduct(repository);
|
final saveProduct = _saveProduct(repository);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue