Files
BudgetApp/lib/data/repositories/hive_transaction_repository.dart
T
2025-06-09 16:27:01 +03:00

56 lines
1.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 {
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();
}
}