Refactored DI, serialization, added feedback to document download

This commit is contained in:
Anton Stubenbord
2022-12-06 00:39:18 +01:00
parent d79682a011
commit 75fa2f7713
51 changed files with 711 additions and 366 deletions

View File

@@ -1,7 +1,8 @@
import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:paperless_api/src/models/labels/matching_algorithm.dart';
abstract class Label with EquatableMixin implements Comparable {
abstract class Label extends Equatable implements Comparable {
static const idKey = "id";
static const nameKey = "name";
static const slugKey = "slug";
@@ -11,13 +12,19 @@ abstract class Label with EquatableMixin implements Comparable {
static const documentCountKey = "document_count";
String get queryEndpoint;
@JsonKey()
final int? id;
@JsonKey()
final String name;
@JsonKey()
final String? slug;
@JsonKey()
final String? match;
@JsonKey()
final MatchingAlgorithm? matchingAlgorithm;
@JsonKey()
final bool? isInsensitive;
@JsonKey()
final int? documentCount;
const Label({
@@ -30,31 +37,6 @@ abstract class Label with EquatableMixin implements Comparable {
this.slug,
});
Label.fromJson(Map<String, dynamic> json)
: id = json[idKey],
name = json[nameKey],
slug = json[slugKey],
match = json[matchKey],
matchingAlgorithm =
MatchingAlgorithm.fromInt(json[matchingAlgorithmKey]),
isInsensitive = json[isInsensitiveKey],
documentCount = json[documentCountKey];
Map<String, dynamic> toJson() {
Map<String, dynamic> json = {};
json.putIfAbsent(idKey, () => id);
json.putIfAbsent(nameKey, () => name);
json.putIfAbsent(slugKey, () => slug);
json.putIfAbsent(matchKey, () => match);
json.putIfAbsent(matchingAlgorithmKey, () => matchingAlgorithm?.value);
json.putIfAbsent(isInsensitiveKey, () => isInsensitive);
json.putIfAbsent(documentCountKey, () => documentCount);
addSpecificFieldsToJson(json);
return json;
}
void addSpecificFieldsToJson(Map<String, dynamic> json);
Label copyWith({
int? id,
String? name,
@@ -75,6 +57,5 @@ abstract class Label with EquatableMixin implements Comparable {
return toString().toLowerCase().compareTo(other.toString().toLowerCase());
}
@override
List<Object?> get props => [id];
Map<String, dynamic> toJson();
}