feat: добавить репозитории Hive для тегов и транзакций
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import '../interfaces/itag_repository.dart';
|
||||
import '../../models/tag.dart';
|
||||
|
||||
class HiveTagRepository implements ITagRepository {
|
||||
final Box<Tag> _box;
|
||||
|
||||
HiveTagRepository(this._box);
|
||||
|
||||
@override
|
||||
Future<List<Tag>> getAll() async {
|
||||
return _box.values.toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Tag?> getById(String id) async {
|
||||
return _box.get(id);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> add(Tag tag) async {
|
||||
await _box.put(tag.id, tag);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> update(Tag tag) async {
|
||||
await add(tag);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> delete(String id) async {
|
||||
await _box.delete(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import '../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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user