mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-15 10:12:28 -06:00
feat: Add functionality to delete notes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_api/src/converters/local_date_time_json_converter.dart';
|
||||
@@ -95,6 +96,9 @@ class DocumentModel extends Equatable {
|
||||
String? archivedFileName,
|
||||
int? Function()? owner,
|
||||
bool? userCanChange,
|
||||
Iterable<NoteModel>? notes,
|
||||
Permissions? permissions,
|
||||
Iterable<CustomFieldModel>? customFields,
|
||||
}) {
|
||||
return DocumentModel(
|
||||
id: id,
|
||||
@@ -115,6 +119,9 @@ class DocumentModel extends Equatable {
|
||||
archivedFileName: archivedFileName ?? this.archivedFileName,
|
||||
owner: owner != null ? owner() : this.owner,
|
||||
userCanChange: userCanChange ?? this.userCanChange,
|
||||
customFields: customFields ?? this.customFields,
|
||||
notes: notes ?? this.notes,
|
||||
permissions: permissions ?? this.permissions,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -135,5 +142,8 @@ class DocumentModel extends Equatable {
|
||||
archivedFileName,
|
||||
owner,
|
||||
userCanChange,
|
||||
customFields,
|
||||
notes,
|
||||
permissions,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -28,3 +28,4 @@ export 'task/task.dart';
|
||||
export 'task/task_status.dart';
|
||||
export 'user_model.dart';
|
||||
export 'exception/exceptions.dart';
|
||||
export 'note_model.dart';
|
||||
|
||||
@@ -5,10 +5,10 @@ part 'note_model.g.dart';
|
||||
@freezed
|
||||
class NoteModel with _$NoteModel {
|
||||
const factory NoteModel({
|
||||
required int id,
|
||||
required String note,
|
||||
required DateTime created,
|
||||
required int document,
|
||||
required int? id,
|
||||
required String? note,
|
||||
required DateTime? created,
|
||||
required int? document,
|
||||
required int? user,
|
||||
}) = _NoteModel;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ abstract class PaperlessDocumentsApi {
|
||||
Future<DocumentModel> find(int id);
|
||||
Future<int> delete(DocumentModel doc);
|
||||
Future<DocumentMetaData> getMetaData(int id);
|
||||
Future<DocumentModel> deleteNote(DocumentModel document, int noteId);
|
||||
Future<Iterable<int>> bulkAction(BulkAction action);
|
||||
Future<Uint8List> getPreview(int docId);
|
||||
String getThumbnailUrl(int docId);
|
||||
|
||||
@@ -323,4 +323,22 @@ class PaperlessDocumentsApiImpl implements PaperlessDocumentsApi {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DocumentModel> deleteNote(DocumentModel document, int noteId) async {
|
||||
try {
|
||||
final response = await client.delete(
|
||||
"/api/documents/${document.id}/notes/?id=$noteId",
|
||||
options: Options(validateStatus: (status) => status == 200),
|
||||
);
|
||||
final notes =
|
||||
(response.data as List).map((e) => NoteModel.fromJson(e)).toList();
|
||||
|
||||
return document.copyWith(notes: notes);
|
||||
} on DioException catch (exception) {
|
||||
throw exception.unravel(
|
||||
orElse: const PaperlessApiException(ErrorCode.documentDeleteFailed),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user