This commit refactors the data repositories to remove user-specific filtering. It simplifies the data access logic by retrieving all data from the Hive boxes and removing the need to filter by `userId` in the repository methods. This change makes the app function in single-user mode and removes the need to manage multiple user contexts within the data layer. Specifically: - Removes `userId` parameter from repository methods. - Updates the setting repository to use fixed keys. - Removes user ID filtering from queries. - Removes user ID parameters from Cubits and Blocs - Updates initial data creation
71 lines
2.4 KiB
Dart
71 lines
2.4 KiB
Dart
import 'package:hive_ce/hive.dart';
|
|
import '/data/repositories/interfaces/itransaction_repository.dart';
|
|
import '../../models/transaction_record.dart';
|
|
|
|
class HiveTransactionRepository implements ITransactionRepository {
|
|
final Box<TransactionRecord> _box;
|
|
|
|
HiveTransactionRepository(this._box);
|
|
|
|
@override
|
|
Future<List<TransactionRecord>> getAll() async {
|
|
// Этот метод может быть не нужен в многопользовательском приложении,
|
|
// так как обычно мы хотим видеть транзакции только текущего пользователя.
|
|
// Но оставляем его для полноты интерфейса.
|
|
return _box.values.toList();
|
|
}
|
|
|
|
@override
|
|
Future<TransactionRecord?> getById(String id) async {
|
|
return _box.get(id);
|
|
}
|
|
|
|
@override
|
|
Future<void> add(TransactionRecord transaction) async {
|
|
await _box.put(transaction.id, transaction);
|
|
}
|
|
|
|
@override
|
|
Future<void> update(TransactionRecord transaction) async {
|
|
// Обновление в Hive часто сводится к перезаписи по тому же ключу
|
|
await add(transaction);
|
|
}
|
|
|
|
@override
|
|
Future<void> delete(String id) async {
|
|
await _box.delete(id);
|
|
}
|
|
|
|
@override
|
|
Future<List<TransactionRecord>> getByDateRange(DateTime from, DateTime to) async {
|
|
// Этот метод также может быть изменен для фильтрации по пользователю
|
|
return _box.values
|
|
.where((t) => t.dateTime.isAfter(from) && t.dateTime.isBefore(to))
|
|
.toList();
|
|
}
|
|
|
|
@override
|
|
Future<List<TransactionRecord>> getByCategory(String categoryId) async {
|
|
// Этот метод также может быть изменен для фильтрации по пользователю
|
|
return _box.values
|
|
.where((t) => t.category.id == categoryId)
|
|
.toList();
|
|
}
|
|
|
|
@override
|
|
Future<List<TransactionRecord>> getByTag(String tagId) async {
|
|
// Этот метод также может быть изменен для фильтрации по пользователю
|
|
return _box.values
|
|
.where((t) => t.tag?.id == tagId)
|
|
.toList();
|
|
}
|
|
|
|
@override
|
|
Future<void> addAll(List<TransactionRecord> transactions) async {
|
|
final Map<String, TransactionRecord> transactionMap = {
|
|
for (var tr in transactions) tr.id: tr
|
|
};
|
|
await _box.putAll(transactionMap);
|
|
}
|
|
}
|