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
|
|
|
|
|
|
|
|
/**
|
2019-10-16 02:59:04 +00:00
|
|
|
Wrapper for all types of data stores. Some are considered singletons, such as the AuthenticationDataStore, while others are created as needed
|
2019-10-02 04:57:27 +00:00
|
|
|
*/
|
|
|
|
class DataStoreProvider {
|
|
|
|
private let budgetRepository: BudgetRepository
|
|
|
|
private let categoryRepository: CategoryRepository
|
|
|
|
private let transactionRepository: TransactionRepository
|
2019-10-13 01:22:09 +00:00
|
|
|
private let userRepository: UserRepository
|
|
|
|
|
|
|
|
private let _authenticationDataStore: AuthenticationDataStore
|
2019-10-02 04:57:27 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-10-13 01:22:09 +00:00
|
|
|
func authenticationDataStore() -> AuthenticationDataStore {
|
|
|
|
return self._authenticationDataStore
|
|
|
|
}
|
|
|
|
|
2019-10-02 04:57:27 +00:00
|
|
|
func userDataStore() -> UserDataStore {
|
2019-10-13 01:22:09 +00:00
|
|
|
return UserDataStore(userRepository)
|
2019-10-02 04:57:27 +00:00
|
|
|
}
|
|
|
|
|
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
|
2019-10-13 01:22:09 +00:00
|
|
|
self.userRepository = userRepository
|
|
|
|
self._authenticationDataStore = AuthenticationDataStore(userRepository)
|
2019-10-12 19:03:50 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-02 04:57:27 +00:00
|
|
|
|
2019-10-12 19:03:50 +00:00
|
|
|
#if DEBUG
|
|
|
|
|
|
|
|
class MockDataStoreProvider: DataStoreProvider {
|
2019-10-19 22:18:06 +00:00
|
|
|
|
|
|
|
override func authenticationDataStore() -> AuthenticationDataStore {
|
|
|
|
return MockAuthenticationDataStore(MockUserRepository())
|
|
|
|
}
|
|
|
|
|
2019-10-12 19:03:50 +00:00
|
|
|
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
|