mirror of
https://github.com/koloideal/Casha.git
synced 2026-08-08 17:51:14 +03:00
step
This commit is contained in:
@@ -13,9 +13,9 @@ class FeatureLimitException implements Exception {
|
|||||||
|
|
||||||
class AccountRepository {
|
class AccountRepository {
|
||||||
final AppDatabase _db;
|
final AppDatabase _db;
|
||||||
final FeatureFlags _featureFlags;
|
final FeatureFlags Function() _getFeatureFlags;
|
||||||
|
|
||||||
AccountRepository(this._db, this._featureFlags);
|
AccountRepository(this._db, this._getFeatureFlags);
|
||||||
|
|
||||||
Stream<List<model.Account>> watchAll() {
|
Stream<List<model.Account>> watchAll() {
|
||||||
return (_db.select(_db.accounts)
|
return (_db.select(_db.accounts)
|
||||||
@@ -167,8 +167,9 @@ class AccountRepository {
|
|||||||
Future<int> add(model.Account account) async {
|
Future<int> add(model.Account account) async {
|
||||||
final existing = await getAll();
|
final existing = await getAll();
|
||||||
final nonMainCount = existing.where((a) => !a.isMain).length;
|
final nonMainCount = existing.where((a) => !a.isMain).length;
|
||||||
if (nonMainCount >= _featureFlags.maxAccounts) {
|
final flags = _getFeatureFlags();
|
||||||
throw FeatureLimitException('Account limit reached (${_featureFlags.maxAccounts})');
|
if (flags.maxAccounts != -1 && nonMainCount >= flags.maxAccounts) {
|
||||||
|
throw FeatureLimitException('Account limit reached (${flags.maxAccounts})');
|
||||||
}
|
}
|
||||||
return await _db.into(_db.accounts).insert(
|
return await _db.into(_db.accounts).insert(
|
||||||
AccountsCompanion.insert(
|
AccountsCompanion.insert(
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ final transactionRepositoryProvider = Provider<TransactionRepository>((ref) {
|
|||||||
|
|
||||||
final accountRepositoryProvider = Provider<AccountRepository>((ref) {
|
final accountRepositoryProvider = Provider<AccountRepository>((ref) {
|
||||||
final db = ref.watch(appDatabaseProvider);
|
final db = ref.watch(appDatabaseProvider);
|
||||||
final flags = ref.watch(featureFlagsProvider);
|
return AccountRepository(db, () => ref.read(featureFlagsProvider));
|
||||||
return AccountRepository(db, flags);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
final storageServiceProvider = Provider<StorageService>((ref) {
|
final storageServiceProvider = Provider<StorageService>((ref) {
|
||||||
|
|||||||
Reference in New Issue
Block a user