mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-10 10:08:02 -06:00
fix: Add labels to each cubit using repositories and state properties, remove label cubits
This commit is contained in:
104
lib/features/labels/cubit/label_cubit_mixin.dart
Normal file
104
lib/features/labels/cubit/label_cubit_mixin.dart
Normal file
@@ -0,0 +1,104 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/repository/label_repository.dart';
|
||||
|
||||
mixin LabelCubitMixin<T> on BlocBase<T> {
|
||||
LabelRepository get labelRepository;
|
||||
|
||||
Map<int, Correspondent> get correspondents;
|
||||
Map<int, DocumentType> get documentTypes;
|
||||
Map<int, Tag> get tags;
|
||||
Map<int, StoragePath> get storagePaths;
|
||||
|
||||
Future<Correspondent> addCorrespondent(Correspondent item) async {
|
||||
assert(item.id == null);
|
||||
final addedItem = await labelRepository.createCorrespondent(item);
|
||||
return addedItem;
|
||||
}
|
||||
|
||||
Future<void> reloadCorrespondents() {
|
||||
return labelRepository.findAllCorrespondents();
|
||||
}
|
||||
|
||||
Future<Correspondent> replaceCorrespondent(Correspondent item) async {
|
||||
assert(item.id != null);
|
||||
final updatedItem = await labelRepository.updateCorrespondent(item);
|
||||
return updatedItem;
|
||||
}
|
||||
|
||||
Future<void> removeCorrespondent(Correspondent item) async {
|
||||
assert(item.id != null);
|
||||
if (correspondents.containsKey(item.id)) {
|
||||
await labelRepository.deleteCorrespondent(item);
|
||||
}
|
||||
}
|
||||
|
||||
Future<DocumentType> addDocumentType(DocumentType item) async {
|
||||
assert(item.id == null);
|
||||
final addedItem = await labelRepository.createDocumentType(item);
|
||||
return addedItem;
|
||||
}
|
||||
|
||||
Future<void> reloadDocumentTypes() {
|
||||
return labelRepository.findAllDocumentTypes();
|
||||
}
|
||||
|
||||
Future<DocumentType> replaceDocumentType(DocumentType item) async {
|
||||
assert(item.id != null);
|
||||
final updatedItem = await labelRepository.updateDocumentType(item);
|
||||
return updatedItem;
|
||||
}
|
||||
|
||||
Future<void> removeDocumentType(DocumentType item) async {
|
||||
assert(item.id != null);
|
||||
if (documentTypes.containsKey(item.id)) {
|
||||
await labelRepository.deleteDocumentType(item);
|
||||
}
|
||||
}
|
||||
|
||||
Future<StoragePath> addStoragePath(StoragePath item) async {
|
||||
assert(item.id == null);
|
||||
final addedItem = await labelRepository.createStoragePath(item);
|
||||
return addedItem;
|
||||
}
|
||||
|
||||
Future<void> reloadStoragePaths() {
|
||||
return labelRepository.findAllStoragePaths();
|
||||
}
|
||||
|
||||
Future<StoragePath> replaceStoragePath(StoragePath item) async {
|
||||
assert(item.id != null);
|
||||
final updatedItem = await labelRepository.updateStoragePath(item);
|
||||
return updatedItem;
|
||||
}
|
||||
|
||||
Future<void> removeStoragePath(StoragePath item) async {
|
||||
assert(item.id != null);
|
||||
if (storagePaths.containsKey(item.id)) {
|
||||
await labelRepository.deleteStoragePath(item);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Tag> addTag(Tag item) async {
|
||||
assert(item.id == null);
|
||||
final addedItem = await labelRepository.createTag(item);
|
||||
return addedItem;
|
||||
}
|
||||
|
||||
Future<void> reloadTags() {
|
||||
return labelRepository.findAllTags();
|
||||
}
|
||||
|
||||
Future<Tag> replaceTag(Tag item) async {
|
||||
assert(item.id != null);
|
||||
final updatedItem = await labelRepository.updateTag(item);
|
||||
return updatedItem;
|
||||
}
|
||||
|
||||
Future<void> removeTag(Tag item) async {
|
||||
assert(item.id != null);
|
||||
if (tags.containsKey(item.id)) {
|
||||
await labelRepository.deleteTag(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user