This commit is contained in:
Hillel Coren 2018-09-03 12:41:42 -07:00
parent 15a2ece833
commit 87e83aa461
13 changed files with 110 additions and 96 deletions

View File

@ -15,19 +15,20 @@ class CreditsRepository {
this.webClient = const WebClient(),
});
Future<BuiltList<CreditEntity>> loadList(CompanyEntity company, AuthState auth) async {
Future<BuiltList<CreditEntity>> loadList(
CompanyEntity company, AuthState auth) async {
final dynamic response =
await webClient.get(auth.url + '/credits?per_page=500', company.token);
final dynamic response = await webClient.get(
auth.url + '/credits?per_page=500', company.token);
final CreditListResponse creditResponse = serializers.deserializeWith(
CreditListResponse.serializer, response);
final CreditListResponse creditResponse =
serializers.deserializeWith(CreditListResponse.serializer, response);
return creditResponse.data;
}
Future saveData(CompanyEntity company, AuthState auth, CreditEntity credit, [EntityAction action]) async {
Future<CreditEntity> saveData(
CompanyEntity company, AuthState auth, CreditEntity credit,
[EntityAction action]) async {
final data = serializers.serializeWith(CreditEntity.serializer, credit);
dynamic response;
@ -42,9 +43,9 @@ class CreditsRepository {
response = await webClient.put(url, company.token, json.encode(data));
}
final CreditItemResponse creditResponse = serializers.deserializeWith(
CreditItemResponse.serializer, response);
final CreditItemResponse creditResponse =
serializers.deserializeWith(CreditItemResponse.serializer, response);
return creditResponse.data;
}
}
}

View File

@ -15,19 +15,20 @@ class ExpenseRepository {
this.webClient = const WebClient(),
});
Future<BuiltList<ExpenseEntity>> loadList(CompanyEntity company, AuthState auth) async {
Future<BuiltList<ExpenseEntity>> loadList(
CompanyEntity company, AuthState auth) async {
final dynamic response =
await webClient.get(auth.url + '/expenses?per_page=500', company.token);
final dynamic response = await webClient.get(
auth.url + '/expenses?per_page=500', company.token);
final ExpenseListResponse expenseResponse = serializers.deserializeWith(
ExpenseListResponse.serializer, response);
final ExpenseListResponse expenseResponse =
serializers.deserializeWith(ExpenseListResponse.serializer, response);
return expenseResponse.data;
}
Future saveData(CompanyEntity company, AuthState auth, ExpenseEntity expense, [EntityAction action]) async {
Future<ExpenseEntity> saveData(
CompanyEntity company, AuthState auth, ExpenseEntity expense,
[EntityAction action]) async {
final data = serializers.serializeWith(ExpenseEntity.serializer, expense);
dynamic response;
@ -42,9 +43,9 @@ class ExpenseRepository {
response = await webClient.put(url, company.token, json.encode(data));
}
final ExpenseItemResponse expenseResponse = serializers.deserializeWith(
ExpenseItemResponse.serializer, response);
final ExpenseItemResponse expenseResponse =
serializers.deserializeWith(ExpenseItemResponse.serializer, response);
return expenseResponse.data;
}
}
}

View File

@ -33,7 +33,7 @@ class PaymentRepository {
return paymentResponse.data;
}
Future saveData(CompanyEntity company, AuthState auth, PaymentEntity payment,
Future<PaymentEntity> saveData(CompanyEntity company, AuthState auth, PaymentEntity payment,
[EntityAction action]) async {
final data = serializers.serializeWith(PaymentEntity.serializer, payment);
dynamic response;

View File

@ -15,19 +15,20 @@ class ProjectsRepository {
this.webClient = const WebClient(),
});
Future<BuiltList<ProjectEntity>> loadList(CompanyEntity company, AuthState auth) async {
Future<BuiltList<ProjectEntity>> loadList(
CompanyEntity company, AuthState auth) async {
final dynamic response =
await webClient.get(auth.url + '/projects?per_page=500', company.token);
final dynamic response = await webClient.get(
auth.url + '/projects?per_page=500', company.token);
final ProjectListResponse projectResponse = serializers.deserializeWith(
ProjectListResponse.serializer, response);
final ProjectListResponse projectResponse =
serializers.deserializeWith(ProjectListResponse.serializer, response);
return projectResponse.data;
}
Future saveData(CompanyEntity company, AuthState auth, ProjectEntity project, [EntityAction action]) async {
Future<ProjectEntity> saveData(
CompanyEntity company, AuthState auth, ProjectEntity project,
[EntityAction action]) async {
final data = serializers.serializeWith(ProjectEntity.serializer, project);
dynamic response;
@ -42,9 +43,9 @@ class ProjectsRepository {
response = await webClient.put(url, company.token, json.encode(data));
}
final ProjectItemResponse projectResponse = serializers.deserializeWith(
ProjectItemResponse.serializer, response);
final ProjectItemResponse projectResponse =
serializers.deserializeWith(ProjectItemResponse.serializer, response);
return projectResponse.data;
}
}
}

View File

@ -15,19 +15,20 @@ class TasksRepository {
this.webClient = const WebClient(),
});
Future<BuiltList<TaskEntity>> loadList(CompanyEntity company, AuthState auth) async {
Future<BuiltList<TaskEntity>> loadList(
CompanyEntity company, AuthState auth) async {
final dynamic response =
await webClient.get(auth.url + '/tasks?per_page=500', company.token);
final dynamic response = await webClient.get(
auth.url + '/tasks?per_page=500', company.token);
final TaskListResponse taskResponse = serializers.deserializeWith(
TaskListResponse.serializer, response);
final TaskListResponse taskResponse =
serializers.deserializeWith(TaskListResponse.serializer, response);
return taskResponse.data;
}
Future saveData(CompanyEntity company, AuthState auth, TaskEntity task, [EntityAction action]) async {
Future<TaskEntity> saveData(
CompanyEntity company, AuthState auth, TaskEntity task,
[EntityAction action]) async {
final data = serializers.serializeWith(TaskEntity.serializer, task);
dynamic response;
@ -42,9 +43,9 @@ class TasksRepository {
response = await webClient.put(url, company.token, json.encode(data));
}
final TaskItemResponse taskResponse = serializers.deserializeWith(
TaskItemResponse.serializer, response);
final TaskItemResponse taskResponse =
serializers.deserializeWith(TaskItemResponse.serializer, response);
return taskResponse.data;
}
}
}

View File

@ -15,19 +15,20 @@ class VendorRepository {
this.webClient = const WebClient(),
});
Future<BuiltList<VendorEntity>> loadList(CompanyEntity company, AuthState auth) async {
Future<BuiltList<VendorEntity>> loadList(
CompanyEntity company, AuthState auth) async {
final dynamic response =
await webClient.get(auth.url + '/vendors?per_page=500', company.token);
final dynamic response = await webClient.get(
auth.url + '/vendors?per_page=500', company.token);
final VendorListResponse vendorResponse = serializers.deserializeWith(
VendorListResponse.serializer, response);
final VendorListResponse vendorResponse =
serializers.deserializeWith(VendorListResponse.serializer, response);
return vendorResponse.data;
}
Future saveData(CompanyEntity company, AuthState auth, VendorEntity vendor, [EntityAction action]) async {
Future<VendorEntity> saveData(
CompanyEntity company, AuthState auth, VendorEntity vendor,
[EntityAction action]) async {
final data = serializers.serializeWith(VendorEntity.serializer, vendor);
dynamic response;
@ -42,9 +43,9 @@ class VendorRepository {
response = await webClient.put(url, company.token, json.encode(data));
}
final VendorItemResponse vendorResponse = serializers.deserializeWith(
VendorItemResponse.serializer, response);
final VendorItemResponse vendorResponse =
serializers.deserializeWith(VendorItemResponse.serializer, response);
return vendorResponse.data;
}
}
}

View File

@ -82,7 +82,7 @@ Middleware<AppState> _archiveClient(ClientRepository repository) {
repository
.saveData(store.state.selectedCompany, store.state.authState,
origClient, EntityAction.archive)
.then((dynamic client) {
.then((ClientEntity client) {
store.dispatch(ArchiveClientSuccess(client));
if (action.completer != null) {
action.completer.complete(null);
@ -105,7 +105,7 @@ Middleware<AppState> _deleteClient(ClientRepository repository) {
repository
.saveData(store.state.selectedCompany, store.state.authState,
origClient, EntityAction.delete)
.then((dynamic client) {
.then((ClientEntity client) {
store.dispatch(DeleteClientSuccess(client));
if (action.completer != null) {
action.completer.complete(null);
@ -128,7 +128,7 @@ Middleware<AppState> _restoreClient(ClientRepository repository) {
repository
.saveData(store.state.selectedCompany, store.state.authState,
origClient, EntityAction.restore)
.then((dynamic client) {
.then((ClientEntity client) {
store.dispatch(RestoreClientSuccess(client));
if (action.completer != null) {
action.completer.complete(null);
@ -150,7 +150,7 @@ Middleware<AppState> _saveClient(ClientRepository repository) {
repository
.saveData(
store.state.selectedCompany, store.state.authState, action.client)
.then((dynamic client) {
.then((ClientEntity client) {
if (action.client.isNew) {
store.dispatch(AddClientSuccess(client));
} else {

View File

@ -95,7 +95,7 @@ Middleware<AppState> _archiveInvoice(InvoiceRepository repository) {
repository
.saveData(store.state.selectedCompany, store.state.authState,
origInvoice, EntityAction.archive)
.then((dynamic invoice) {
.then((InvoiceEntity invoice) {
store.dispatch(ArchiveInvoiceSuccess(invoice));
if (action.completer != null) {
action.completer.complete(null);
@ -166,7 +166,7 @@ Middleware<AppState> _markSentInvoice(InvoiceRepository repository) {
repository
.saveData(store.state.selectedCompany, store.state.authState,
origInvoice, EntityAction.markSent)
.then((dynamic invoice) {
.then((InvoiceEntity invoice) {
store.dispatch(MarkSentInvoiceSuccess(invoice));
store.dispatch(LoadClient(clientId: invoice.clientId));
if (action.completer != null) {
@ -213,7 +213,7 @@ Middleware<AppState> _saveInvoice(InvoiceRepository repository) {
repository
.saveData(
store.state.selectedCompany, store.state.authState, action.invoice)
.then((dynamic invoice) {
.then((InvoiceEntity invoice) {
if (action.invoice.isNew) {
store.dispatch(AddInvoiceSuccess(invoice));
} else {

View File

@ -80,7 +80,7 @@ Middleware<AppState> _archivePayment(PaymentRepository repository) {
repository
.saveData(store.state.selectedCompany, store.state.authState,
origPayment, EntityAction.archive)
.then((dynamic payment) {
.then((PaymentEntity payment) {
store.dispatch(ArchivePaymentSuccess(payment));
if (action.completer != null) {
action.completer.complete(null);
@ -103,10 +103,10 @@ Middleware<AppState> _deletePayment(PaymentRepository repository) {
repository
.saveData(store.state.selectedCompany, store.state.authState,
origPayment, EntityAction.delete)
.then((dynamic payment) {
.then((PaymentEntity payment) {
store.dispatch(DeletePaymentSuccess(payment));
store.dispatch(LoadClient(
clientId: paymentInvoiceSelector(payment, store.state).clientId));
clientId: paymentInvoiceSelector(payment.id, store.state).clientId));
if (action.completer != null) {
action.completer.complete(null);
}
@ -128,10 +128,10 @@ Middleware<AppState> _restorePayment(PaymentRepository repository) {
repository
.saveData(store.state.selectedCompany, store.state.authState,
origPayment, EntityAction.restore)
.then((dynamic payment) {
.then((PaymentEntity payment) {
store.dispatch(RestorePaymentSuccess(payment));
store.dispatch(LoadClient(
clientId: paymentInvoiceSelector(payment, store.state).clientId));
clientId: paymentInvoiceSelector(payment.id, store.state).clientId));
if (action.completer != null) {
action.completer.complete(null);
}
@ -152,14 +152,14 @@ Middleware<AppState> _savePayment(PaymentRepository repository) {
repository
.saveData(
store.state.selectedCompany, store.state.authState, action.payment)
.then((dynamic payment) {
.then((PaymentEntity payment) {
if (action.payment.isNew) {
store.dispatch(AddPaymentSuccess(payment));
} else {
store.dispatch(SavePaymentSuccess(payment));
}
store.dispatch(LoadClient(
clientId: paymentInvoiceSelector(payment, store.state).clientId));
clientId: paymentInvoiceSelector(payment.id, store.state).clientId));
action.completer.complete(null);
}).catchError((Object error) {
print(error);

View File

@ -39,7 +39,6 @@ PaymentEntity _updateEditing(PaymentEntity payment, dynamic action) {
return action.payment;
}
final paymentListReducer = combineReducers<ListUIState>([
TypedReducer<ListUIState, SortPayments>(_sortPayments),
TypedReducer<ListUIState, FilterPaymentsByState>(_filterPaymentsByState),
@ -77,13 +76,15 @@ ListUIState _filterPaymentsByCustom2(
ListUIState _filterPaymentsByState(
ListUIState paymentListState, FilterPaymentsByState action) {
if (paymentListState.stateFilters.contains(action.state)) {
return paymentListState.rebuild((b) => b..stateFilters.remove(action.state));
return paymentListState
.rebuild((b) => b..stateFilters.remove(action.state));
} else {
return paymentListState.rebuild((b) => b..stateFilters.add(action.state));
}
}
ListUIState _filterPayments(ListUIState paymentListState, FilterPayments action) {
ListUIState _filterPayments(
ListUIState paymentListState, FilterPayments action) {
return paymentListState.rebuild((b) => b..filter = action.filter);
}
@ -120,12 +121,14 @@ PaymentState _archivePaymentRequest(
PaymentState _archivePaymentSuccess(
PaymentState paymentState, ArchivePaymentSuccess action) {
return paymentState.rebuild((b) => b..map[action.payment.id] = action.payment);
return paymentState
.rebuild((b) => b..map[action.payment.id] = action.payment);
}
PaymentState _archivePaymentFailure(
PaymentState paymentState, ArchivePaymentFailure action) {
return paymentState.rebuild((b) => b..map[action.payment.id] = action.payment);
return paymentState
.rebuild((b) => b..map[action.payment.id] = action.payment);
}
PaymentState _deletePaymentRequest(
@ -139,12 +142,14 @@ PaymentState _deletePaymentRequest(
PaymentState _deletePaymentSuccess(
PaymentState paymentState, DeletePaymentSuccess action) {
return paymentState.rebuild((b) => b..map[action.payment.id] = action.payment);
return paymentState
.rebuild((b) => b..map[action.payment.id] = action.payment);
}
PaymentState _deletePaymentFailure(
PaymentState paymentState, DeletePaymentFailure action) {
return paymentState.rebuild((b) => b..map[action.payment.id] = action.payment);
return paymentState
.rebuild((b) => b..map[action.payment.id] = action.payment);
}
PaymentState _restorePaymentRequest(
@ -157,12 +162,14 @@ PaymentState _restorePaymentRequest(
PaymentState _restorePaymentSuccess(
PaymentState paymentState, RestorePaymentSuccess action) {
return paymentState.rebuild((b) => b..map[action.payment.id] = action.payment);
return paymentState
.rebuild((b) => b..map[action.payment.id] = action.payment);
}
PaymentState _restorePaymentFailure(
PaymentState paymentState, RestorePaymentFailure action) {
return paymentState.rebuild((b) => b..map[action.payment.id] = action.payment);
return paymentState
.rebuild((b) => b..map[action.payment.id] = action.payment);
}
PaymentState _addPayment(PaymentState paymentState, AddPaymentSuccess action) {
@ -171,18 +178,20 @@ PaymentState _addPayment(PaymentState paymentState, AddPaymentSuccess action) {
..list.add(action.payment.id));
}
PaymentState _updatePayment(PaymentState paymentState, SavePaymentSuccess action) {
return paymentState.rebuild((b) => b
..map[action.payment.id] = action.payment);
PaymentState _updatePayment(
PaymentState paymentState, SavePaymentSuccess action) {
return paymentState
.rebuild((b) => b..map[action.payment.id] = action.payment);
}
PaymentState _setLoadedPayment(
PaymentState paymentState, LoadPaymentSuccess action) {
return paymentState.rebuild((b) => b
..map[action.payment.id] = action.payment);
return paymentState
.rebuild((b) => b..map[action.payment.id] = action.payment);
}
PaymentState _setNoPayments(PaymentState paymentState, LoadPaymentsFailure action) {
PaymentState _setNoPayments(
PaymentState paymentState, LoadPaymentsFailure action) {
return paymentState;
}

View File

@ -56,7 +56,7 @@ Middleware<AppState> _archiveProduct(ProductRepository repository) {
repository
.saveData(store.state.selectedCompany, store.state.authState,
origProduct, EntityAction.archive)
.then((dynamic product) {
.then((ProductEntity product) {
store.dispatch(ArchiveProductSuccess(product));
if (action.completer != null) {
action.completer.complete(null);
@ -79,7 +79,7 @@ Middleware<AppState> _deleteProduct(ProductRepository repository) {
repository
.saveData(store.state.selectedCompany, store.state.authState,
origProduct, EntityAction.delete)
.then((dynamic product) {
.then((ProductEntity product) {
store.dispatch(DeleteProductSuccess(product));
if (action.completer != null) {
action.completer.complete(null);
@ -102,7 +102,7 @@ Middleware<AppState> _restoreProduct(ProductRepository repository) {
repository
.saveData(store.state.selectedCompany, store.state.authState,
origProduct, EntityAction.restore)
.then((dynamic product) {
.then((ProductEntity product) {
store.dispatch(RestoreProductSuccess(product));
if (action.completer != null) {
action.completer.complete(null);
@ -124,7 +124,7 @@ Middleware<AppState> _saveProduct(ProductRepository repository) {
repository
.saveData(
store.state.selectedCompany, store.state.authState, action.product)
.then((dynamic product) {
.then((ProductEntity product) {
if (action.product.isNew) {
store.dispatch(AddProductSuccess(product));
} else {

View File

@ -96,7 +96,7 @@ Middleware<AppState> _archiveQuote(QuoteRepository repository) {
repository
.saveData(store.state.selectedCompany, store.state.authState, origQuote,
EntityAction.archive)
.then((dynamic quote) {
.then((InvoiceEntity quote) {
store.dispatch(ArchiveQuoteSuccess(quote));
if (action.completer != null) {
action.completer.complete(null);
@ -167,7 +167,7 @@ Middleware<AppState> _markSentQuote(QuoteRepository repository) {
repository
.saveData(store.state.selectedCompany, store.state.authState, origQuote,
EntityAction.markSent)
.then((dynamic quote) {
.then((InvoiceEntity quote) {
store.dispatch(MarkSentQuoteSuccess(quote));
store.dispatch(LoadClient(clientId: quote.clientId));
if (action.completer != null) {
@ -214,7 +214,7 @@ Middleware<AppState> _saveQuote(QuoteRepository repository) {
repository
.saveData(
store.state.selectedCompany, store.state.authState, action.quote)
.then((dynamic quote) {
.then((InvoiceEntity quote) {
if (action.quote.isNew) {
store.dispatch(AddQuoteSuccess(quote));
} else {

View File

@ -75,7 +75,7 @@ Middleware<AppState> _archiveStub(StubRepository repository) {
repository
.saveData(store.state.selectedCompany, store.state.authState,
origStub, EntityAction.archive)
.then((dynamic stub) {
.then((StubEntity stub) {
store.dispatch(ArchiveStubSuccess(stub));
if (action.completer != null) {
action.completer.complete(null);
@ -98,7 +98,7 @@ Middleware<AppState> _deleteStub(StubRepository repository) {
repository
.saveData(store.state.selectedCompany, store.state.authState,
origStub, EntityAction.delete)
.then((dynamic stub) {
.then((StubEntity stub) {
store.dispatch(DeleteStubSuccess(stub));
if (action.completer != null) {
action.completer.complete(null);
@ -121,7 +121,7 @@ Middleware<AppState> _restoreStub(StubRepository repository) {
repository
.saveData(store.state.selectedCompany, store.state.authState,
origStub, EntityAction.restore)
.then((dynamic stub) {
.then((StubEntity stub) {
store.dispatch(RestoreStubSuccess(stub));
if (action.completer != null) {
action.completer.complete(null);
@ -143,7 +143,7 @@ Middleware<AppState> _saveStub(StubRepository repository) {
repository
.saveData(
store.state.selectedCompany, store.state.authState, action.stub)
.then((dynamic stub) {
.then((StubEntity stub) {
if (action.stub.isNew) {
store.dispatch(AddStubSuccess(stub));
} else {