2019-10-02 04:57:27 +00:00
|
|
|
//
|
|
|
|
// DataStoreProvider.swift
|
|
|
|
// Budget
|
|
|
|
//
|
|
|
|
// Created by Billy Brawner on 10/1/19.
|
|
|
|
// Copyright © 2019 William Brawner. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
/**
|
|
|
|
Wrapper for all types of data stores. Some are considered singletons, such as the UserDataStore, while others are created as needed
|
|
|
|
*/
|
|
|
|
class DataStoreProvider {
|
|
|
|
private let budgetRepository: BudgetRepository
|
|
|
|
private let categoryRepository: CategoryRepository
|
|
|
|
private let transactionRepository: TransactionRepository
|
|
|
|
|
|
|
|
private let _userDataStore: UserDataStore
|
|
|
|
|
|
|
|
func budgetsDataStore() -> BudgetsDataStore {
|
|
|
|
return BudgetsDataStore(budgetRepository)
|
|
|
|
}
|
|
|
|
|
2019-10-12 00:02:13 +00:00
|
|
|
func categoryDataStore() -> CategoryDataStore {
|
|
|
|
return CategoryDataStore(categoryRepository)
|
2019-10-02 04:57:27 +00:00
|
|
|
}
|
|
|
|
|
2019-10-11 02:30:43 +00:00
|
|
|
func transactionDataStore() -> TransactionDataStore {
|
|
|
|
return TransactionDataStore(transactionRepository)
|
2019-10-02 04:57:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func userDataStore() -> UserDataStore {
|
|
|
|
return self._userDataStore
|
|
|
|
}
|
|
|
|
|
2019-10-12 19:03:50 +00:00
|
|
|
init(
|
|
|
|
budgetRepository: BudgetRepository,
|
|
|
|
categoryRepository: CategoryRepository,
|
|
|
|
transactionRepository: TransactionRepository,
|
|
|
|
userRepository: UserRepository
|
|
|
|
) {
|
|
|
|
self.budgetRepository = budgetRepository
|
|
|
|
self.categoryRepository = categoryRepository
|
|
|
|
self.transactionRepository = transactionRepository
|
|
|
|
self._userDataStore = UserDataStore(userRepository)
|
|
|
|
}
|
|
|
|
}
|
2019-10-02 04:57:27 +00:00
|
|
|
|
2019-10-12 19:03:50 +00:00
|
|
|
#if DEBUG
|
|
|
|
|
|
|
|
class MockDataStoreProvider: DataStoreProvider {
|
|
|
|
init() {
|
|
|
|
super.init(
|
|
|
|
budgetRepository: MockBudgetRepository(),
|
|
|
|
categoryRepository: MockCategoryRepository(),
|
|
|
|
transactionRepository: MockTransactionRepository(),
|
|
|
|
userRepository: MockUserRepository()
|
|
|
|
)
|
2019-10-02 04:57:27 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-12 19:03:50 +00:00
|
|
|
|
|
|
|
#endif
|