mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-10 20:07:55 -06:00
feat: Add hive type adapters to api models, migrate to freezed
This commit is contained in:
@@ -1,4 +1,49 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
|
||||
class PaperlessApiHiveTypeIds {
|
||||
PaperlessApiHiveTypeIds._();
|
||||
static const int documentFilter = 1000;
|
||||
static const int documentFilter = 100;
|
||||
static const int idQueryParameter = 101;
|
||||
static const int tagsQuery = 102;
|
||||
static const int anyAssignedTagsQuery = 103;
|
||||
static const int tagIdQuery = 104;
|
||||
static const int includeTagIdQuery = 105;
|
||||
static const int idsTagsQuery = 106;
|
||||
static const int excludeTagIdQuery = 107;
|
||||
static const int sortField = 108;
|
||||
static const int sortOrder = 109;
|
||||
static const int absoluteDateRangeQuery = 110;
|
||||
static const int relativeDateRangeQuery = 111;
|
||||
static const int dateRangeUnit = 112;
|
||||
static const int unsetDateRangeQuery = 113;
|
||||
static const int textQuery = 114;
|
||||
static const int queryType = 115;
|
||||
static const int unsetIdQueryParameter = 116;
|
||||
static const int notAssignedIdQueryParameter = 117;
|
||||
static const int anyAssignedIdQueryParameter = 118;
|
||||
static const int setIdQueryParameter = 119;
|
||||
static const int notAssignedTagsQuery = 120;
|
||||
}
|
||||
|
||||
void registerPaperlessApiHiveTypeAdapters() {
|
||||
Hive.registerAdapter(DocumentFilterAdapter());
|
||||
// TagsQuery
|
||||
Hive.registerAdapter(AnyAssignedTagsQueryAdapter());
|
||||
Hive.registerAdapter(NotAssignedTagsQueryAdapter());
|
||||
Hive.registerAdapter(IdsTagsQueryAdapter());
|
||||
|
||||
Hive.registerAdapter(SortFieldAdapter());
|
||||
Hive.registerAdapter(SortOrderAdapter());
|
||||
Hive.registerAdapter(AbsoluteDateRangeQueryAdapter());
|
||||
Hive.registerAdapter(RelativeDateRangeQueryAdapter());
|
||||
Hive.registerAdapter(DateRangeUnitAdapter());
|
||||
Hive.registerAdapter(UnsetDateRangeQueryAdapter());
|
||||
Hive.registerAdapter(TextQueryAdapter());
|
||||
Hive.registerAdapter(QueryTypeAdapter());
|
||||
// IdQueryParameter
|
||||
Hive.registerAdapter(SetIdQueryParameterAdapter());
|
||||
Hive.registerAdapter(UnsetIdQueryParameterAdapter());
|
||||
Hive.registerAdapter(AnyAssignedIdQueryParameterAdapter());
|
||||
Hive.registerAdapter(NotAssignedIdQueryParameterAdapter());
|
||||
}
|
||||
|
||||
@@ -3,3 +3,4 @@ library paperless_api;
|
||||
export 'src/models/models.dart';
|
||||
export 'src/modules/modules.dart';
|
||||
export 'src/converters/converters.dart';
|
||||
export 'config/hive/hive_type_ids.dart';
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:paperless_api/src/models/query_parameters/tags_query/any_assigned_tags_query.dart';
|
||||
import 'package:paperless_api/src/models/query_parameters/tags_query/ids_tags_query.dart';
|
||||
import 'package:paperless_api/src/models/query_parameters/tags_query/only_not_assigned_tags_query.dart';
|
||||
|
||||
import '../models/query_parameters/tags_query/tags_query.dart';
|
||||
|
||||
class TagsQueryJsonConverter
|
||||
extends JsonConverter<TagsQuery, Map<String, dynamic>> {
|
||||
const TagsQueryJsonConverter();
|
||||
@override
|
||||
TagsQuery fromJson(Map<String, dynamic> json) {
|
||||
final type = json['type'] as String;
|
||||
final data = json['data'] as Map<String, dynamic>;
|
||||
switch (type) {
|
||||
case 'OnlyNotAssignedTagsQuery':
|
||||
return const OnlyNotAssignedTagsQuery();
|
||||
case 'AnyAssignedTagsQuery':
|
||||
return AnyAssignedTagsQuery.fromJson(data);
|
||||
case 'IdsTagsQuery':
|
||||
return IdsTagsQuery.fromJson(data);
|
||||
default:
|
||||
throw Exception('Error parsing TagsQuery: Unknown type $type');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson(TagsQuery object) {
|
||||
return {
|
||||
'type': object.runtimeType.toString(),
|
||||
'data': object.toJson(),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,10 @@ import 'package:hive/hive.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:paperless_api/config/hive/hive_type_ids.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_api/src/converters/tags_query_json_converter.dart';
|
||||
import 'package:paperless_api/src/models/query_parameters/tags_query/tags_query.dart';
|
||||
|
||||
part 'document_filter.g.dart';
|
||||
|
||||
@TagsQueryJsonConverter()
|
||||
@DateRangeQueryJsonConverter()
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.documentFilter)
|
||||
@@ -48,8 +47,6 @@ class DocumentFilter extends Equatable {
|
||||
final DateRangeQuery modified;
|
||||
@HiveField(12)
|
||||
final TextQuery query;
|
||||
|
||||
/// Query documents similar to the document with this id.
|
||||
@HiveField(13)
|
||||
final int? moreLike;
|
||||
|
||||
@@ -58,7 +55,7 @@ class DocumentFilter extends Equatable {
|
||||
this.correspondent = const IdQueryParameter.unset(),
|
||||
this.storagePath = const IdQueryParameter.unset(),
|
||||
this.asnQuery = const IdQueryParameter.unset(),
|
||||
this.tags = const IdsTagsQuery(),
|
||||
this.tags = const TagsQuery.ids(),
|
||||
this.sortField = SortField.created,
|
||||
this.sortOrder = SortOrder.descending,
|
||||
this.page = 1,
|
||||
@@ -107,9 +104,7 @@ class DocumentFilter extends Equatable {
|
||||
final queryParams = groupBy(params, (e) => e.key).map(
|
||||
(key, entries) => MapEntry(
|
||||
key,
|
||||
entries.length == 1
|
||||
? entries.first.value
|
||||
: entries.map((e) => e.value).join(","),
|
||||
entries.length == 1 ? entries.first.value : entries.map((e) => e.value).join(","),
|
||||
),
|
||||
);
|
||||
return queryParams;
|
||||
@@ -150,8 +145,7 @@ class DocumentFilter extends Equatable {
|
||||
modified: modified ?? this.modified,
|
||||
moreLike: moreLike != null ? moreLike.call() : this.moreLike,
|
||||
);
|
||||
if (query?.queryType != QueryType.extended &&
|
||||
newFilter.forceExtendedQuery) {
|
||||
if (query?.queryType != QueryType.extended && newFilter.forceExtendedQuery) {
|
||||
//Prevents infinite recursion
|
||||
return newFilter.copyWith(
|
||||
query: newFilter.query.copyWith(queryType: QueryType.extended),
|
||||
@@ -207,8 +201,7 @@ class DocumentFilter extends Equatable {
|
||||
query,
|
||||
];
|
||||
|
||||
factory DocumentFilter.fromJson(Map<String, dynamic> json) =>
|
||||
_$DocumentFilterFromJson(json);
|
||||
factory DocumentFilter.fromJson(Map<String, dynamic> json) => _$DocumentFilterFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$DocumentFilterToJson(this);
|
||||
}
|
||||
|
||||
@@ -3,12 +3,7 @@ import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_api/src/constants.dart';
|
||||
import 'package:paperless_api/src/converters/local_date_time_json_converter.dart';
|
||||
|
||||
import 'query_parameters/tags_query/any_assigned_tags_query.dart';
|
||||
import 'query_parameters/tags_query/exclude_tag_id_query.dart';
|
||||
import 'query_parameters/tags_query/ids_tags_query.dart';
|
||||
import 'query_parameters/tags_query/include_tag_id_query.dart';
|
||||
import 'query_parameters/tags_query/only_not_assigned_tags_query.dart';
|
||||
import 'package:paperless_api/src/models/query_parameters/tags_query/tags_query.dart';
|
||||
|
||||
part 'filter_rule_model.g.dart';
|
||||
|
||||
@@ -77,21 +72,29 @@ class FilterRule with EquatableMixin {
|
||||
);
|
||||
case hasAnyTag:
|
||||
return filter.copyWith(
|
||||
tags: value == "true"
|
||||
? const AnyAssignedTagsQuery()
|
||||
: const OnlyNotAssignedTagsQuery(),
|
||||
tags: value == "true" ? const TagsQuery.anyAssigned() : const TagsQuery.notAssigned(),
|
||||
);
|
||||
case includeTagsRule:
|
||||
assert(filter.tags is IdsTagsQuery);
|
||||
return filter.copyWith(
|
||||
tags: (filter.tags as IdsTagsQuery)
|
||||
.withIdQueriesAdded([IncludeTagIdQuery(int.parse(value!))]),
|
||||
tags: filter.tags.maybeWhen(
|
||||
ids: (include, exclude) => TagsQuery.ids(
|
||||
include: [...include, int.parse(value!)],
|
||||
exclude: exclude,
|
||||
),
|
||||
orElse: () => filter.tags,
|
||||
),
|
||||
);
|
||||
case excludeTagsRule:
|
||||
assert(filter.tags is IdsTagsQuery);
|
||||
return filter.copyWith(
|
||||
tags: (filter.tags as IdsTagsQuery)
|
||||
.withIdQueriesAdded([ExcludeTagIdQuery(int.parse(value!))]),
|
||||
tags: filter.tags.maybeWhen(
|
||||
ids: (include, exclude) => TagsQuery.ids(
|
||||
include: include,
|
||||
exclude: [...exclude, int.parse(value!)],
|
||||
),
|
||||
orElse: () => filter.tags,
|
||||
),
|
||||
);
|
||||
case createdBeforeRule:
|
||||
if (filter.created is AbsoluteDateRangeQuery) {
|
||||
@@ -101,8 +104,7 @@ class FilterRule with EquatableMixin {
|
||||
);
|
||||
} else {
|
||||
return filter.copyWith(
|
||||
created: AbsoluteDateRangeQuery(
|
||||
before: _dateTimeConverter.fromJson(value!)),
|
||||
created: AbsoluteDateRangeQuery(before: _dateTimeConverter.fromJson(value!)),
|
||||
);
|
||||
}
|
||||
case createdAfterRule:
|
||||
@@ -113,8 +115,7 @@ class FilterRule with EquatableMixin {
|
||||
);
|
||||
} else {
|
||||
return filter.copyWith(
|
||||
created: AbsoluteDateRangeQuery(
|
||||
after: _dateTimeConverter.fromJson(value!)),
|
||||
created: AbsoluteDateRangeQuery(after: _dateTimeConverter.fromJson(value!)),
|
||||
);
|
||||
}
|
||||
case addedBeforeRule:
|
||||
@@ -125,8 +126,7 @@ class FilterRule with EquatableMixin {
|
||||
);
|
||||
} else {
|
||||
return filter.copyWith(
|
||||
added: AbsoluteDateRangeQuery(
|
||||
before: _dateTimeConverter.fromJson(value!)),
|
||||
added: AbsoluteDateRangeQuery(before: _dateTimeConverter.fromJson(value!)),
|
||||
);
|
||||
}
|
||||
case addedAfterRule:
|
||||
@@ -137,8 +137,7 @@ class FilterRule with EquatableMixin {
|
||||
);
|
||||
} else {
|
||||
return filter.copyWith(
|
||||
added: AbsoluteDateRangeQuery(
|
||||
after: _dateTimeConverter.fromJson(value!)),
|
||||
added: AbsoluteDateRangeQuery(after: _dateTimeConverter.fromJson(value!)),
|
||||
);
|
||||
}
|
||||
case modifiedBeforeRule:
|
||||
@@ -149,8 +148,7 @@ class FilterRule with EquatableMixin {
|
||||
);
|
||||
} else {
|
||||
return filter.copyWith(
|
||||
modified: AbsoluteDateRangeQuery(
|
||||
before: _dateTimeConverter.fromJson(value!)),
|
||||
modified: AbsoluteDateRangeQuery(before: _dateTimeConverter.fromJson(value!)),
|
||||
);
|
||||
}
|
||||
case modifiedAfterRule:
|
||||
@@ -161,8 +159,7 @@ class FilterRule with EquatableMixin {
|
||||
);
|
||||
} else {
|
||||
return filter.copyWith(
|
||||
added: AbsoluteDateRangeQuery(
|
||||
after: _dateTimeConverter.fromJson(value!)),
|
||||
added: AbsoluteDateRangeQuery(after: _dateTimeConverter.fromJson(value!)),
|
||||
);
|
||||
}
|
||||
case titleAndContentRule:
|
||||
@@ -236,49 +233,46 @@ class FilterRule with EquatableMixin {
|
||||
///
|
||||
static List<FilterRule> fromFilter(final DocumentFilter filter) {
|
||||
List<FilterRule> filterRules = [];
|
||||
if (filter.correspondent.onlyNotAssigned) {
|
||||
filterRules.add(FilterRule(correspondentRule, null));
|
||||
final corrRule = filter.correspondent.whenOrNull(
|
||||
notAssigned: () => FilterRule(correspondentRule, null),
|
||||
fromId: (id) => FilterRule(correspondentRule, id.toString()),
|
||||
);
|
||||
if (corrRule != null) {
|
||||
filterRules.add(corrRule);
|
||||
}
|
||||
if (filter.correspondent.isSet) {
|
||||
filterRules.add(
|
||||
FilterRule(correspondentRule, filter.correspondent.id!.toString()));
|
||||
|
||||
final docTypeRule = filter.documentType.whenOrNull(
|
||||
notAssigned: () => FilterRule(documentTypeRule, null),
|
||||
fromId: (id) => FilterRule(documentTypeRule, id.toString()),
|
||||
);
|
||||
if (docTypeRule != null) {
|
||||
filterRules.add(docTypeRule);
|
||||
}
|
||||
if (filter.documentType.onlyNotAssigned) {
|
||||
filterRules.add(FilterRule(documentTypeRule, null));
|
||||
}
|
||||
if (filter.documentType.isSet) {
|
||||
filterRules.add(
|
||||
FilterRule(documentTypeRule, filter.documentType.id!.toString()));
|
||||
}
|
||||
if (filter.storagePath.onlyNotAssigned) {
|
||||
filterRules.add(FilterRule(storagePathRule, null));
|
||||
}
|
||||
if (filter.storagePath.isSet) {
|
||||
filterRules
|
||||
.add(FilterRule(storagePathRule, filter.storagePath.id!.toString()));
|
||||
}
|
||||
if (filter.tags is OnlyNotAssignedTagsQuery) {
|
||||
filterRules.add(FilterRule(hasAnyTag, false.toString()));
|
||||
}
|
||||
if (filter.tags is AnyAssignedTagsQuery) {
|
||||
filterRules.add(FilterRule(hasAnyTag, true.toString()));
|
||||
}
|
||||
if (filter.tags is IdsTagsQuery) {
|
||||
filterRules.addAll((filter.tags as IdsTagsQuery)
|
||||
.includedIds
|
||||
.map((id) => FilterRule(includeTagsRule, id.toString())));
|
||||
filterRules.addAll((filter.tags as IdsTagsQuery)
|
||||
.excludedIds
|
||||
.map((id) => FilterRule(excludeTagsRule, id.toString())));
|
||||
|
||||
final sPathRule = filter.documentType.whenOrNull(
|
||||
notAssigned: () => FilterRule(storagePathRule, null),
|
||||
fromId: (id) => FilterRule(storagePathRule, id.toString()),
|
||||
);
|
||||
if (sPathRule != null) {
|
||||
filterRules.add(sPathRule);
|
||||
}
|
||||
final tagRules = filter.tags.when(
|
||||
notAssigned: () => [FilterRule(hasAnyTag, 'false')],
|
||||
anyAssigned: (_) => [FilterRule(hasAnyTag, 'true')],
|
||||
ids: (include, exclude) => [
|
||||
...include.map((id) => FilterRule(includeTagsRule, id.toString())),
|
||||
...exclude.map((id) => FilterRule(excludeTagsRule, id.toString())),
|
||||
],
|
||||
);
|
||||
filterRules.addAll(tagRules);
|
||||
|
||||
if (filter.query.queryText != null) {
|
||||
switch (filter.query.queryType) {
|
||||
case QueryType.title:
|
||||
filterRules.add(FilterRule(titleRule, filter.query.queryText!));
|
||||
break;
|
||||
case QueryType.titleAndContent:
|
||||
filterRules
|
||||
.add(FilterRule(titleAndContentRule, filter.query.queryText!));
|
||||
filterRules.add(FilterRule(titleAndContentRule, filter.query.queryText!));
|
||||
break;
|
||||
case QueryType.extended:
|
||||
filterRules.add(FilterRule(extendedRule, filter.query.queryText!));
|
||||
@@ -304,8 +298,8 @@ class FilterRule with EquatableMixin {
|
||||
}
|
||||
} else if (created is RelativeDateRangeQuery) {
|
||||
filterRules.add(
|
||||
FilterRule(extendedRule,
|
||||
created.toQueryParameter(DateRangeQueryField.created).values.first),
|
||||
FilterRule(
|
||||
extendedRule, created.toQueryParameter(DateRangeQueryField.created).values.first),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -324,8 +318,7 @@ class FilterRule with EquatableMixin {
|
||||
}
|
||||
} else if (added is RelativeDateRangeQuery) {
|
||||
filterRules.add(
|
||||
FilterRule(extendedRule,
|
||||
added.toQueryParameter(DateRangeQueryField.added).values.first),
|
||||
FilterRule(extendedRule, added.toQueryParameter(DateRangeQueryField.added).values.first),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -339,25 +332,19 @@ class FilterRule with EquatableMixin {
|
||||
}
|
||||
if (modified.before != null) {
|
||||
filterRules.add(
|
||||
FilterRule(
|
||||
modifiedBeforeRule, apiDateFormat.format(modified.before!)),
|
||||
FilterRule(modifiedBeforeRule, apiDateFormat.format(modified.before!)),
|
||||
);
|
||||
}
|
||||
} else if (modified is RelativeDateRangeQuery) {
|
||||
filterRules.add(
|
||||
FilterRule(
|
||||
extendedRule,
|
||||
modified
|
||||
.toQueryParameter(DateRangeQueryField.modified)
|
||||
.values
|
||||
.first),
|
||||
extendedRule, modified.toQueryParameter(DateRangeQueryField.modified).values.first),
|
||||
);
|
||||
}
|
||||
|
||||
//Join values of all extended filter rules if exist
|
||||
if (filterRules.isNotEmpty &&
|
||||
filterRules.where((e) => e.ruleType == FilterRule.extendedRule).length >
|
||||
1) {
|
||||
filterRules.where((e) => e.ruleType == FilterRule.extendedRule).length > 1) {
|
||||
final mergedExtendedRule = filterRules
|
||||
.where((r) => r.ruleType == FilterRule.extendedRule)
|
||||
.map((e) => e.value)
|
||||
@@ -381,6 +368,5 @@ class FilterRule with EquatableMixin {
|
||||
|
||||
Map<String, dynamic> toJson() => _$FilterRuleToJson(this);
|
||||
|
||||
factory FilterRule.fromJson(Map<String, dynamic> json) =>
|
||||
_$FilterRuleFromJson(json);
|
||||
factory FilterRule.fromJson(Map<String, dynamic> json) => _$FilterRuleFromJson(json);
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ export 'query_parameters/id_query_parameter.dart';
|
||||
export 'query_parameters/query_type.dart';
|
||||
export 'query_parameters/sort_field.dart';
|
||||
export 'query_parameters/sort_order.dart';
|
||||
export 'query_parameters/tags_query/tags_queries.dart';
|
||||
export 'query_parameters/date_range_queries/date_range_queries.dart';
|
||||
export 'query_parameters/tags_query/tags_query.dart';
|
||||
export 'query_parameters/text_query.dart';
|
||||
export 'bulk_edit_model.dart';
|
||||
export 'document_filter.dart';
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:paperless_api/config/hive/hive_type_ids.dart';
|
||||
import 'package:paperless_api/src/constants.dart';
|
||||
import 'package:paperless_api/src/converters/local_date_time_json_converter.dart';
|
||||
|
||||
@@ -8,11 +10,14 @@ import 'date_range_query_field.dart';
|
||||
part 'absolute_date_range_query.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.absoluteDateRangeQuery)
|
||||
class AbsoluteDateRangeQuery extends DateRangeQuery {
|
||||
@LocalDateTimeJsonConverter()
|
||||
@HiveField(0)
|
||||
final DateTime? after;
|
||||
|
||||
@LocalDateTimeJsonConverter()
|
||||
@HiveField(1)
|
||||
final DateTime? before;
|
||||
|
||||
const AbsoluteDateRangeQuery({this.after, this.before});
|
||||
@@ -47,8 +52,7 @@ class AbsoluteDateRangeQuery extends DateRangeQuery {
|
||||
);
|
||||
}
|
||||
|
||||
factory AbsoluteDateRangeQuery.fromJson(json) =>
|
||||
_$AbsoluteDateRangeQueryFromJson(json);
|
||||
factory AbsoluteDateRangeQuery.fromJson(json) => _$AbsoluteDateRangeQueryFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$AbsoluteDateRangeQueryToJson(this);
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'date_range_query_field.dart';
|
||||
|
||||
abstract class DateRangeQuery extends Equatable {
|
||||
const DateRangeQuery();
|
||||
|
||||
Map<String, String> toQueryParameter(DateRangeQueryField field);
|
||||
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:paperless_api/config/hive/hive_type_ids.dart';
|
||||
part 'date_range_unit.g.dart';
|
||||
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.dateRangeUnit)
|
||||
enum DateRangeUnit {
|
||||
@HiveField(0)
|
||||
day,
|
||||
@HiveField(1)
|
||||
week,
|
||||
@HiveField(2)
|
||||
month,
|
||||
@HiveField(3)
|
||||
year;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:jiffy/jiffy.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:paperless_api/config/hive/hive_type_ids.dart';
|
||||
|
||||
import 'date_range_query.dart';
|
||||
import 'date_range_query_field.dart';
|
||||
@@ -7,8 +9,11 @@ import 'date_range_unit.dart';
|
||||
part 'relative_date_range_query.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.relativeDateRangeQuery)
|
||||
class RelativeDateRangeQuery extends DateRangeQuery {
|
||||
@HiveField(0)
|
||||
final int offset;
|
||||
@HiveField(1)
|
||||
final DateRangeUnit unit;
|
||||
|
||||
const RelativeDateRangeQuery([
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:paperless_api/config/hive/hive_type_ids.dart';
|
||||
import 'package:paperless_api/src/models/query_parameters/date_range_queries/date_range_query_field.dart';
|
||||
|
||||
import 'date_range_query.dart';
|
||||
part 'unset_date_range_query.g.dart';
|
||||
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.unsetDateRangeQuery)
|
||||
class UnsetDateRangeQuery extends DateRangeQuery {
|
||||
const UnsetDateRangeQuery();
|
||||
@override
|
||||
@@ -11,9 +15,7 @@ class UnsetDateRangeQuery extends DateRangeQuery {
|
||||
Map<String, String> toQueryParameter(DateRangeQueryField field) => const {};
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return {};
|
||||
}
|
||||
Map<String, dynamic> toJson() => const {};
|
||||
|
||||
@override
|
||||
bool matches(DateTime dt) => true;
|
||||
|
||||
@@ -1,101 +1,113 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:paperless_api/config/hive/hive_type_ids.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
part 'id_query_parameter.freezed.dart';
|
||||
part 'id_query_parameter.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class IdQueryParameter extends Equatable {
|
||||
final int? assignmentStatus;
|
||||
final int? id;
|
||||
|
||||
@Deprecated("Use named constructors, this is only meant for code generation")
|
||||
const IdQueryParameter(this.assignmentStatus, this.id);
|
||||
|
||||
const IdQueryParameter.notAssigned()
|
||||
: assignmentStatus = 1,
|
||||
id = null;
|
||||
|
||||
const IdQueryParameter.anyAssigned()
|
||||
: assignmentStatus = 0,
|
||||
id = null;
|
||||
|
||||
const IdQueryParameter.fromId(this.id) : assignmentStatus = null;
|
||||
|
||||
const IdQueryParameter.unset() : this.fromId(null);
|
||||
|
||||
bool get isUnset => id == null && assignmentStatus == null;
|
||||
|
||||
bool get isSet => id != null && assignmentStatus == null;
|
||||
|
||||
bool get onlyNotAssigned => assignmentStatus == 1;
|
||||
|
||||
bool get onlyAssigned => assignmentStatus == 0;
|
||||
@freezed
|
||||
class IdQueryParameter with _$IdQueryParameter {
|
||||
const IdQueryParameter._();
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.unsetIdQueryParameter)
|
||||
const factory IdQueryParameter.unset() = UnsetIdQueryParameter;
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.notAssignedIdQueryParameter)
|
||||
const factory IdQueryParameter.notAssigned() = NotAssignedIdQueryParameter;
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.anyAssignedIdQueryParameter)
|
||||
const factory IdQueryParameter.anyAssigned() = AnyAssignedIdQueryParameter;
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.setIdQueryParameter)
|
||||
const factory IdQueryParameter.fromId(@HiveField(0) int? id) = SetIdQueryParameter;
|
||||
|
||||
Map<String, String> toQueryParameter(String field) {
|
||||
final Map<String, String> params = {};
|
||||
if (onlyNotAssigned || onlyAssigned) {
|
||||
params.putIfAbsent(
|
||||
'${field}__isnull', () => assignmentStatus!.toString());
|
||||
}
|
||||
if (isSet) {
|
||||
params.putIfAbsent("${field}__id", () => id!.toString());
|
||||
}
|
||||
return params;
|
||||
return when(
|
||||
unset: () => {},
|
||||
notAssigned: () => {
|
||||
'${field}__isnull': '1',
|
||||
},
|
||||
anyAssigned: () => {
|
||||
'${field}__isnull': '0',
|
||||
},
|
||||
fromId: (id) {
|
||||
if (id == null) {
|
||||
return {};
|
||||
}
|
||||
return {'${field}_id': '$id'};
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
bool isOnlyNotAssigned() => this is NotAssignedIdQueryParameter;
|
||||
|
||||
bool isOnlyAssigned() => this is AnyAssignedIdQueryParameter;
|
||||
|
||||
bool isSet() => this is SetIdQueryParameter;
|
||||
|
||||
bool isUnset() => this is UnsetIdQueryParameter;
|
||||
|
||||
bool matches(int? id) {
|
||||
return onlyAssigned && id != null ||
|
||||
onlyNotAssigned && id == null ||
|
||||
isSet && id == this.id ||
|
||||
isUnset;
|
||||
return when(
|
||||
unset: () => true,
|
||||
notAssigned: () => id == null,
|
||||
anyAssigned: () => id != null,
|
||||
fromId: (id_) => id == id_,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [assignmentStatus, id];
|
||||
|
||||
Map<String, dynamic> toJson() => _$IdQueryParameterToJson(this);
|
||||
|
||||
factory IdQueryParameter.fromJson(Map<String, dynamic> json) =>
|
||||
_$IdQueryParameterFromJson(json);
|
||||
factory IdQueryParameter.fromJson(Map<String, dynamic> json) => _$IdQueryParameterFromJson(json);
|
||||
}
|
||||
// @freezed
|
||||
// class IdQueryParameter with _$IdQueryParameter {
|
||||
// const IdQueryParameter._();
|
||||
// const factory IdQueryParameter.unset() = _UnsetIdQueryParameter;
|
||||
// const factory IdQueryParameter.notAssigned() = _NotAssignedIdQueryParameter;
|
||||
// const factory IdQueryParameter.anyAssigned() = _AnyAssignedIdQueryParameter;
|
||||
// const factory IdQueryParameter.id(int id) = _SetIdQueryParameter;
|
||||
|
||||
// @JsonSerializable()
|
||||
// @HiveType(typeId: PaperlessApiHiveTypeIds.idQueryParameter)
|
||||
// class IdQueryParameter extends Equatable {
|
||||
// @HiveField(0)
|
||||
// final int? assignmentStatus;
|
||||
// @HiveField(1)
|
||||
// final int? id;
|
||||
|
||||
// @Deprecated("Use named constructors, this is only meant for code generation")
|
||||
// const IdQueryParameter(this.assignmentStatus, this.id);
|
||||
|
||||
// const IdQueryParameter.notAssigned()
|
||||
// : assignmentStatus = 1,
|
||||
// id = null;
|
||||
|
||||
// const IdQueryParameter.anyAssigned()
|
||||
// : assignmentStatus = 0,
|
||||
// id = null;
|
||||
|
||||
// const IdQueryParameter.fromId(this.id) : assignmentStatus = null;
|
||||
|
||||
// const IdQueryParameter.unset() : this.fromId(null);
|
||||
|
||||
// bool get isUnset => id == null && assignmentStatus == null;
|
||||
|
||||
// bool get isSet => id != null && assignmentStatus == null;
|
||||
|
||||
// bool get onlyNotAssigned => assignmentStatus == 1;
|
||||
|
||||
// bool get onlyAssigned => assignmentStatus == 0;
|
||||
|
||||
// Map<String, String> toQueryParameter(String field) {
|
||||
// return when(
|
||||
// unset: () => {},
|
||||
// notAssigned: () => {
|
||||
// '${field}__isnull': '1',
|
||||
// },
|
||||
// anyAssigned: () => {
|
||||
// '${field}__isnull': '0',
|
||||
// },
|
||||
// id: (id) => {
|
||||
// '${field}_id': '$id',
|
||||
// },
|
||||
// );
|
||||
// final Map<String, String> params = {};
|
||||
// if (onlyNotAssigned || onlyAssigned) {
|
||||
// params.putIfAbsent('${field}__isnull', () => assignmentStatus!.toString());
|
||||
// }
|
||||
// if (isSet) {
|
||||
// params.putIfAbsent("${field}__id", () => id!.toString());
|
||||
// }
|
||||
// return params;
|
||||
// }
|
||||
|
||||
// bool get onlyNotAssigned => this is _NotAssignedIdQueryParameter;
|
||||
|
||||
// bool get onlyAssigned => this is _AnyAssignedIdQueryParameter;
|
||||
|
||||
// bool get isSet => this is _SetIdQueryParameter;
|
||||
|
||||
// bool get isUnset => this is _UnsetIdQueryParameter;
|
||||
// bool matches(int? id) {
|
||||
// return when(
|
||||
// unset: () => true,
|
||||
// notAssigned: () => id == null,
|
||||
// anyAssigned: () => id != null,
|
||||
// id: (id_) => id == id_,
|
||||
// );
|
||||
// return onlyAssigned && id != null ||
|
||||
// onlyNotAssigned && id == null ||
|
||||
// isSet && id == this.id ||
|
||||
// isUnset;
|
||||
// }
|
||||
|
||||
// factory IdQueryParameter.fromJson(Map<String, dynamic> json) =>
|
||||
// _$IdQueryParameterFromJson(json);
|
||||
// @override
|
||||
// List<Object?> get props => [assignmentStatus, id];
|
||||
|
||||
// Map<String, dynamic> toJson() => _$IdQueryParameterToJson(this);
|
||||
|
||||
// factory IdQueryParameter.fromJson(Map<String, dynamic> json) => _$IdQueryParameterFromJson(json);
|
||||
// }
|
||||
|
||||
|
||||
@@ -0,0 +1,686 @@
|
||||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'id_query_parameter.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
|
||||
|
||||
IdQueryParameter _$IdQueryParameterFromJson(Map<String, dynamic> json) {
|
||||
switch (json['runtimeType']) {
|
||||
case 'unset':
|
||||
return UnsetIdQueryParameter.fromJson(json);
|
||||
case 'notAssigned':
|
||||
return NotAssignedIdQueryParameter.fromJson(json);
|
||||
case 'anyAssigned':
|
||||
return AnyAssignedIdQueryParameter.fromJson(json);
|
||||
case 'fromId':
|
||||
return SetIdQueryParameter.fromJson(json);
|
||||
|
||||
default:
|
||||
throw CheckedFromJsonException(json, 'runtimeType', 'IdQueryParameter',
|
||||
'Invalid union type "${json['runtimeType']}"!');
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$IdQueryParameter {
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() unset,
|
||||
required TResult Function() notAssigned,
|
||||
required TResult Function() anyAssigned,
|
||||
required TResult Function(@HiveField(0) int? id) fromId,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? unset,
|
||||
TResult? Function()? notAssigned,
|
||||
TResult? Function()? anyAssigned,
|
||||
TResult? Function(@HiveField(0) int? id)? fromId,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? unset,
|
||||
TResult Function()? notAssigned,
|
||||
TResult Function()? anyAssigned,
|
||||
TResult Function(@HiveField(0) int? id)? fromId,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(UnsetIdQueryParameter value) unset,
|
||||
required TResult Function(NotAssignedIdQueryParameter value) notAssigned,
|
||||
required TResult Function(AnyAssignedIdQueryParameter value) anyAssigned,
|
||||
required TResult Function(SetIdQueryParameter value) fromId,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(UnsetIdQueryParameter value)? unset,
|
||||
TResult? Function(NotAssignedIdQueryParameter value)? notAssigned,
|
||||
TResult? Function(AnyAssignedIdQueryParameter value)? anyAssigned,
|
||||
TResult? Function(SetIdQueryParameter value)? fromId,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(UnsetIdQueryParameter value)? unset,
|
||||
TResult Function(NotAssignedIdQueryParameter value)? notAssigned,
|
||||
TResult Function(AnyAssignedIdQueryParameter value)? anyAssigned,
|
||||
TResult Function(SetIdQueryParameter value)? fromId,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $IdQueryParameterCopyWith<$Res> {
|
||||
factory $IdQueryParameterCopyWith(
|
||||
IdQueryParameter value, $Res Function(IdQueryParameter) then) =
|
||||
_$IdQueryParameterCopyWithImpl<$Res, IdQueryParameter>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$IdQueryParameterCopyWithImpl<$Res, $Val extends IdQueryParameter>
|
||||
implements $IdQueryParameterCopyWith<$Res> {
|
||||
_$IdQueryParameterCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$UnsetIdQueryParameterCopyWith<$Res> {
|
||||
factory _$$UnsetIdQueryParameterCopyWith(_$UnsetIdQueryParameter value,
|
||||
$Res Function(_$UnsetIdQueryParameter) then) =
|
||||
__$$UnsetIdQueryParameterCopyWithImpl<$Res>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$UnsetIdQueryParameterCopyWithImpl<$Res>
|
||||
extends _$IdQueryParameterCopyWithImpl<$Res, _$UnsetIdQueryParameter>
|
||||
implements _$$UnsetIdQueryParameterCopyWith<$Res> {
|
||||
__$$UnsetIdQueryParameterCopyWithImpl(_$UnsetIdQueryParameter _value,
|
||||
$Res Function(_$UnsetIdQueryParameter) _then)
|
||||
: super(_value, _then);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.unsetIdQueryParameter)
|
||||
class _$UnsetIdQueryParameter extends UnsetIdQueryParameter {
|
||||
const _$UnsetIdQueryParameter({final String? $type})
|
||||
: $type = $type ?? 'unset',
|
||||
super._();
|
||||
|
||||
factory _$UnsetIdQueryParameter.fromJson(Map<String, dynamic> json) =>
|
||||
_$$UnsetIdQueryParameterFromJson(json);
|
||||
|
||||
@JsonKey(name: 'runtimeType')
|
||||
final String $type;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'IdQueryParameter.unset()';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(dynamic other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType && other is _$UnsetIdQueryParameter);
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() unset,
|
||||
required TResult Function() notAssigned,
|
||||
required TResult Function() anyAssigned,
|
||||
required TResult Function(@HiveField(0) int? id) fromId,
|
||||
}) {
|
||||
return unset();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? unset,
|
||||
TResult? Function()? notAssigned,
|
||||
TResult? Function()? anyAssigned,
|
||||
TResult? Function(@HiveField(0) int? id)? fromId,
|
||||
}) {
|
||||
return unset?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? unset,
|
||||
TResult Function()? notAssigned,
|
||||
TResult Function()? anyAssigned,
|
||||
TResult Function(@HiveField(0) int? id)? fromId,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (unset != null) {
|
||||
return unset();
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(UnsetIdQueryParameter value) unset,
|
||||
required TResult Function(NotAssignedIdQueryParameter value) notAssigned,
|
||||
required TResult Function(AnyAssignedIdQueryParameter value) anyAssigned,
|
||||
required TResult Function(SetIdQueryParameter value) fromId,
|
||||
}) {
|
||||
return unset(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(UnsetIdQueryParameter value)? unset,
|
||||
TResult? Function(NotAssignedIdQueryParameter value)? notAssigned,
|
||||
TResult? Function(AnyAssignedIdQueryParameter value)? anyAssigned,
|
||||
TResult? Function(SetIdQueryParameter value)? fromId,
|
||||
}) {
|
||||
return unset?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(UnsetIdQueryParameter value)? unset,
|
||||
TResult Function(NotAssignedIdQueryParameter value)? notAssigned,
|
||||
TResult Function(AnyAssignedIdQueryParameter value)? anyAssigned,
|
||||
TResult Function(SetIdQueryParameter value)? fromId,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (unset != null) {
|
||||
return unset(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$UnsetIdQueryParameterToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class UnsetIdQueryParameter extends IdQueryParameter {
|
||||
const factory UnsetIdQueryParameter() = _$UnsetIdQueryParameter;
|
||||
const UnsetIdQueryParameter._() : super._();
|
||||
|
||||
factory UnsetIdQueryParameter.fromJson(Map<String, dynamic> json) =
|
||||
_$UnsetIdQueryParameter.fromJson;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$NotAssignedIdQueryParameterCopyWith<$Res> {
|
||||
factory _$$NotAssignedIdQueryParameterCopyWith(
|
||||
_$NotAssignedIdQueryParameter value,
|
||||
$Res Function(_$NotAssignedIdQueryParameter) then) =
|
||||
__$$NotAssignedIdQueryParameterCopyWithImpl<$Res>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$NotAssignedIdQueryParameterCopyWithImpl<$Res>
|
||||
extends _$IdQueryParameterCopyWithImpl<$Res, _$NotAssignedIdQueryParameter>
|
||||
implements _$$NotAssignedIdQueryParameterCopyWith<$Res> {
|
||||
__$$NotAssignedIdQueryParameterCopyWithImpl(
|
||||
_$NotAssignedIdQueryParameter _value,
|
||||
$Res Function(_$NotAssignedIdQueryParameter) _then)
|
||||
: super(_value, _then);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.notAssignedIdQueryParameter)
|
||||
class _$NotAssignedIdQueryParameter extends NotAssignedIdQueryParameter {
|
||||
const _$NotAssignedIdQueryParameter({final String? $type})
|
||||
: $type = $type ?? 'notAssigned',
|
||||
super._();
|
||||
|
||||
factory _$NotAssignedIdQueryParameter.fromJson(Map<String, dynamic> json) =>
|
||||
_$$NotAssignedIdQueryParameterFromJson(json);
|
||||
|
||||
@JsonKey(name: 'runtimeType')
|
||||
final String $type;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'IdQueryParameter.notAssigned()';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(dynamic other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$NotAssignedIdQueryParameter);
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() unset,
|
||||
required TResult Function() notAssigned,
|
||||
required TResult Function() anyAssigned,
|
||||
required TResult Function(@HiveField(0) int? id) fromId,
|
||||
}) {
|
||||
return notAssigned();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? unset,
|
||||
TResult? Function()? notAssigned,
|
||||
TResult? Function()? anyAssigned,
|
||||
TResult? Function(@HiveField(0) int? id)? fromId,
|
||||
}) {
|
||||
return notAssigned?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? unset,
|
||||
TResult Function()? notAssigned,
|
||||
TResult Function()? anyAssigned,
|
||||
TResult Function(@HiveField(0) int? id)? fromId,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (notAssigned != null) {
|
||||
return notAssigned();
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(UnsetIdQueryParameter value) unset,
|
||||
required TResult Function(NotAssignedIdQueryParameter value) notAssigned,
|
||||
required TResult Function(AnyAssignedIdQueryParameter value) anyAssigned,
|
||||
required TResult Function(SetIdQueryParameter value) fromId,
|
||||
}) {
|
||||
return notAssigned(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(UnsetIdQueryParameter value)? unset,
|
||||
TResult? Function(NotAssignedIdQueryParameter value)? notAssigned,
|
||||
TResult? Function(AnyAssignedIdQueryParameter value)? anyAssigned,
|
||||
TResult? Function(SetIdQueryParameter value)? fromId,
|
||||
}) {
|
||||
return notAssigned?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(UnsetIdQueryParameter value)? unset,
|
||||
TResult Function(NotAssignedIdQueryParameter value)? notAssigned,
|
||||
TResult Function(AnyAssignedIdQueryParameter value)? anyAssigned,
|
||||
TResult Function(SetIdQueryParameter value)? fromId,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (notAssigned != null) {
|
||||
return notAssigned(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$NotAssignedIdQueryParameterToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class NotAssignedIdQueryParameter extends IdQueryParameter {
|
||||
const factory NotAssignedIdQueryParameter() = _$NotAssignedIdQueryParameter;
|
||||
const NotAssignedIdQueryParameter._() : super._();
|
||||
|
||||
factory NotAssignedIdQueryParameter.fromJson(Map<String, dynamic> json) =
|
||||
_$NotAssignedIdQueryParameter.fromJson;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$AnyAssignedIdQueryParameterCopyWith<$Res> {
|
||||
factory _$$AnyAssignedIdQueryParameterCopyWith(
|
||||
_$AnyAssignedIdQueryParameter value,
|
||||
$Res Function(_$AnyAssignedIdQueryParameter) then) =
|
||||
__$$AnyAssignedIdQueryParameterCopyWithImpl<$Res>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$AnyAssignedIdQueryParameterCopyWithImpl<$Res>
|
||||
extends _$IdQueryParameterCopyWithImpl<$Res, _$AnyAssignedIdQueryParameter>
|
||||
implements _$$AnyAssignedIdQueryParameterCopyWith<$Res> {
|
||||
__$$AnyAssignedIdQueryParameterCopyWithImpl(
|
||||
_$AnyAssignedIdQueryParameter _value,
|
||||
$Res Function(_$AnyAssignedIdQueryParameter) _then)
|
||||
: super(_value, _then);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.anyAssignedIdQueryParameter)
|
||||
class _$AnyAssignedIdQueryParameter extends AnyAssignedIdQueryParameter {
|
||||
const _$AnyAssignedIdQueryParameter({final String? $type})
|
||||
: $type = $type ?? 'anyAssigned',
|
||||
super._();
|
||||
|
||||
factory _$AnyAssignedIdQueryParameter.fromJson(Map<String, dynamic> json) =>
|
||||
_$$AnyAssignedIdQueryParameterFromJson(json);
|
||||
|
||||
@JsonKey(name: 'runtimeType')
|
||||
final String $type;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'IdQueryParameter.anyAssigned()';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(dynamic other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$AnyAssignedIdQueryParameter);
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() unset,
|
||||
required TResult Function() notAssigned,
|
||||
required TResult Function() anyAssigned,
|
||||
required TResult Function(@HiveField(0) int? id) fromId,
|
||||
}) {
|
||||
return anyAssigned();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? unset,
|
||||
TResult? Function()? notAssigned,
|
||||
TResult? Function()? anyAssigned,
|
||||
TResult? Function(@HiveField(0) int? id)? fromId,
|
||||
}) {
|
||||
return anyAssigned?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? unset,
|
||||
TResult Function()? notAssigned,
|
||||
TResult Function()? anyAssigned,
|
||||
TResult Function(@HiveField(0) int? id)? fromId,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (anyAssigned != null) {
|
||||
return anyAssigned();
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(UnsetIdQueryParameter value) unset,
|
||||
required TResult Function(NotAssignedIdQueryParameter value) notAssigned,
|
||||
required TResult Function(AnyAssignedIdQueryParameter value) anyAssigned,
|
||||
required TResult Function(SetIdQueryParameter value) fromId,
|
||||
}) {
|
||||
return anyAssigned(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(UnsetIdQueryParameter value)? unset,
|
||||
TResult? Function(NotAssignedIdQueryParameter value)? notAssigned,
|
||||
TResult? Function(AnyAssignedIdQueryParameter value)? anyAssigned,
|
||||
TResult? Function(SetIdQueryParameter value)? fromId,
|
||||
}) {
|
||||
return anyAssigned?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(UnsetIdQueryParameter value)? unset,
|
||||
TResult Function(NotAssignedIdQueryParameter value)? notAssigned,
|
||||
TResult Function(AnyAssignedIdQueryParameter value)? anyAssigned,
|
||||
TResult Function(SetIdQueryParameter value)? fromId,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (anyAssigned != null) {
|
||||
return anyAssigned(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$AnyAssignedIdQueryParameterToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AnyAssignedIdQueryParameter extends IdQueryParameter {
|
||||
const factory AnyAssignedIdQueryParameter() = _$AnyAssignedIdQueryParameter;
|
||||
const AnyAssignedIdQueryParameter._() : super._();
|
||||
|
||||
factory AnyAssignedIdQueryParameter.fromJson(Map<String, dynamic> json) =
|
||||
_$AnyAssignedIdQueryParameter.fromJson;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$SetIdQueryParameterCopyWith<$Res> {
|
||||
factory _$$SetIdQueryParameterCopyWith(_$SetIdQueryParameter value,
|
||||
$Res Function(_$SetIdQueryParameter) then) =
|
||||
__$$SetIdQueryParameterCopyWithImpl<$Res>;
|
||||
@useResult
|
||||
$Res call({@HiveField(0) int? id});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$SetIdQueryParameterCopyWithImpl<$Res>
|
||||
extends _$IdQueryParameterCopyWithImpl<$Res, _$SetIdQueryParameter>
|
||||
implements _$$SetIdQueryParameterCopyWith<$Res> {
|
||||
__$$SetIdQueryParameterCopyWithImpl(
|
||||
_$SetIdQueryParameter _value, $Res Function(_$SetIdQueryParameter) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = freezed,
|
||||
}) {
|
||||
return _then(_$SetIdQueryParameter(
|
||||
freezed == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.setIdQueryParameter)
|
||||
class _$SetIdQueryParameter extends SetIdQueryParameter {
|
||||
const _$SetIdQueryParameter(@HiveField(0) this.id, {final String? $type})
|
||||
: $type = $type ?? 'fromId',
|
||||
super._();
|
||||
|
||||
factory _$SetIdQueryParameter.fromJson(Map<String, dynamic> json) =>
|
||||
_$$SetIdQueryParameterFromJson(json);
|
||||
|
||||
@override
|
||||
@HiveField(0)
|
||||
final int? id;
|
||||
|
||||
@JsonKey(name: 'runtimeType')
|
||||
final String $type;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'IdQueryParameter.fromId(id: $id)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(dynamic other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$SetIdQueryParameter &&
|
||||
(identical(other.id, id) || other.id == id));
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, id);
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$SetIdQueryParameterCopyWith<_$SetIdQueryParameter> get copyWith =>
|
||||
__$$SetIdQueryParameterCopyWithImpl<_$SetIdQueryParameter>(
|
||||
this, _$identity);
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() unset,
|
||||
required TResult Function() notAssigned,
|
||||
required TResult Function() anyAssigned,
|
||||
required TResult Function(@HiveField(0) int? id) fromId,
|
||||
}) {
|
||||
return fromId(id);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? unset,
|
||||
TResult? Function()? notAssigned,
|
||||
TResult? Function()? anyAssigned,
|
||||
TResult? Function(@HiveField(0) int? id)? fromId,
|
||||
}) {
|
||||
return fromId?.call(id);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? unset,
|
||||
TResult Function()? notAssigned,
|
||||
TResult Function()? anyAssigned,
|
||||
TResult Function(@HiveField(0) int? id)? fromId,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (fromId != null) {
|
||||
return fromId(id);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(UnsetIdQueryParameter value) unset,
|
||||
required TResult Function(NotAssignedIdQueryParameter value) notAssigned,
|
||||
required TResult Function(AnyAssignedIdQueryParameter value) anyAssigned,
|
||||
required TResult Function(SetIdQueryParameter value) fromId,
|
||||
}) {
|
||||
return fromId(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(UnsetIdQueryParameter value)? unset,
|
||||
TResult? Function(NotAssignedIdQueryParameter value)? notAssigned,
|
||||
TResult? Function(AnyAssignedIdQueryParameter value)? anyAssigned,
|
||||
TResult? Function(SetIdQueryParameter value)? fromId,
|
||||
}) {
|
||||
return fromId?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(UnsetIdQueryParameter value)? unset,
|
||||
TResult Function(NotAssignedIdQueryParameter value)? notAssigned,
|
||||
TResult Function(AnyAssignedIdQueryParameter value)? anyAssigned,
|
||||
TResult Function(SetIdQueryParameter value)? fromId,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (fromId != null) {
|
||||
return fromId(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$SetIdQueryParameterToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class SetIdQueryParameter extends IdQueryParameter {
|
||||
const factory SetIdQueryParameter(@HiveField(0) final int? id) =
|
||||
_$SetIdQueryParameter;
|
||||
const SetIdQueryParameter._() : super._();
|
||||
|
||||
factory SetIdQueryParameter.fromJson(Map<String, dynamic> json) =
|
||||
_$SetIdQueryParameter.fromJson;
|
||||
|
||||
@HiveField(0)
|
||||
int? get id;
|
||||
@JsonKey(ignore: true)
|
||||
_$$SetIdQueryParameterCopyWith<_$SetIdQueryParameter> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
@JsonEnum()
|
||||
enum TagsQueryType {
|
||||
notAssigned,
|
||||
anyAssigned,
|
||||
ids,
|
||||
id,
|
||||
include,
|
||||
exclude;
|
||||
}
|
||||
@@ -1,7 +1,17 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:paperless_api/config/hive/hive_type_ids.dart';
|
||||
|
||||
part 'query_type.g.dart';
|
||||
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.queryType)
|
||||
enum QueryType {
|
||||
@HiveField(0)
|
||||
title('title__icontains'),
|
||||
@HiveField(1)
|
||||
titleAndContent('title_content'),
|
||||
@HiveField(2)
|
||||
extended('query'),
|
||||
@HiveField(3)
|
||||
asn('asn');
|
||||
|
||||
final String queryParam;
|
||||
|
||||
@@ -1,14 +1,27 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:paperless_api/config/hive/hive_type_ids.dart';
|
||||
|
||||
part 'sort_field.g.dart';
|
||||
|
||||
@JsonEnum(valueField: 'queryString')
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.sortField)
|
||||
enum SortField {
|
||||
@HiveField(0)
|
||||
archiveSerialNumber("archive_serial_number"),
|
||||
@HiveField(1)
|
||||
correspondentName("correspondent__name"),
|
||||
@HiveField(2)
|
||||
title("title"),
|
||||
@HiveField(3)
|
||||
documentType("document_type__name"),
|
||||
@HiveField(4)
|
||||
created("created"),
|
||||
@HiveField(5)
|
||||
added("added"),
|
||||
@HiveField(6)
|
||||
modified("modified"),
|
||||
@HiveField(7)
|
||||
score("score");
|
||||
|
||||
final String queryString;
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:paperless_api/config/hive/hive_type_ids.dart';
|
||||
|
||||
part 'sort_order.g.dart';
|
||||
|
||||
@JsonEnum()
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.sortOrder)
|
||||
enum SortOrder {
|
||||
@HiveField(0)
|
||||
ascending(""),
|
||||
@HiveField(1)
|
||||
descending("-");
|
||||
|
||||
final String queryString;
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'tags_query.dart';
|
||||
part 'any_assigned_tags_query.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class AnyAssignedTagsQuery extends TagsQuery {
|
||||
final Iterable<int> tagIds;
|
||||
|
||||
const AnyAssignedTagsQuery({
|
||||
this.tagIds = const [],
|
||||
});
|
||||
|
||||
@override
|
||||
Map<String, String> toQueryParameter() {
|
||||
if (tagIds.isEmpty) {
|
||||
return {'is_tagged': '1'};
|
||||
}
|
||||
return {'tags__id__in': tagIds.join(',')};
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [tagIds];
|
||||
|
||||
AnyAssignedTagsQuery withRemoved(Iterable<int> ids) {
|
||||
return AnyAssignedTagsQuery(
|
||||
tagIds: tagIds.toSet().difference(ids.toSet()).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
AnyAssignedTagsQuery withAdded(Iterable<int> ids) {
|
||||
return AnyAssignedTagsQuery(tagIds: [...tagIds, ...ids]);
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$AnyAssignedTagsQueryToJson(this);
|
||||
|
||||
factory AnyAssignedTagsQuery.fromJson(Map<String, dynamic> json) =>
|
||||
_$AnyAssignedTagsQueryFromJson(json);
|
||||
|
||||
@override
|
||||
bool matches(Iterable<int> ids) {
|
||||
return ids.isNotEmpty;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import 'package:paperless_api/src/models/query_parameters/tags_query/tag_id_query.dart';
|
||||
|
||||
import 'include_tag_id_query.dart';
|
||||
|
||||
class ExcludeTagIdQuery extends TagIdQuery {
|
||||
const ExcludeTagIdQuery(super.id);
|
||||
|
||||
@override
|
||||
String get methodName => 'exclude';
|
||||
|
||||
@override
|
||||
TagIdQuery toggle() {
|
||||
return IncludeTagIdQuery(id);
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'exclude_tag_id_query.dart';
|
||||
import 'include_tag_id_query.dart';
|
||||
import 'tag_id_query.dart';
|
||||
import 'tags_query.dart';
|
||||
|
||||
class IdsTagsQuery extends TagsQuery {
|
||||
final Iterable<TagIdQuery> _idQueries;
|
||||
|
||||
const IdsTagsQuery([this._idQueries = const []]);
|
||||
|
||||
IdsTagsQuery.included(Iterable<int> ids)
|
||||
: _idQueries = ids.map((id) => IncludeTagIdQuery(id));
|
||||
|
||||
IdsTagsQuery.fromIds(Iterable<int> ids) : this.included(ids);
|
||||
|
||||
IdsTagsQuery.excluded(Iterable<int> ids)
|
||||
: _idQueries = ids.map((id) => ExcludeTagIdQuery(id));
|
||||
|
||||
IdsTagsQuery withIdQueriesAdded(Iterable<TagIdQuery> idQueries) {
|
||||
final intersection = idQueries
|
||||
.map((idQ) => idQ.id)
|
||||
.toSet()
|
||||
.intersection(_idQueries.map((idQ) => idQ.id).toSet());
|
||||
final res = IdsTagsQuery(
|
||||
[...withIdsRemoved(intersection).queries, ...idQueries],
|
||||
);
|
||||
return res;
|
||||
}
|
||||
|
||||
IdsTagsQuery withIdsRemoved(Iterable<int> ids) {
|
||||
return IdsTagsQuery(
|
||||
_idQueries.where((idQuery) => !ids.contains(idQuery.id)),
|
||||
);
|
||||
}
|
||||
|
||||
Iterable<TagIdQuery> get queries => _idQueries;
|
||||
|
||||
Iterable<int> get includedIds {
|
||||
return _idQueries.whereType<IncludeTagIdQuery>().map((e) => e.id);
|
||||
}
|
||||
|
||||
Iterable<int> get excludedIds {
|
||||
return _idQueries.whereType<ExcludeTagIdQuery>().map((e) => e.id);
|
||||
}
|
||||
|
||||
///
|
||||
/// Returns a new instance with the type of the given [id] toggled.
|
||||
/// E.g. if the provided [id] is currently registered as a [IncludeTagIdQuery],
|
||||
/// then the new isntance will contain a [ExcludeTagIdQuery] with given id.
|
||||
///
|
||||
IdsTagsQuery withIdQueryToggled(int id) {
|
||||
return IdsTagsQuery(
|
||||
_idQueries.map((idQ) => idQ.id == id ? idQ.toggle() : idQ),
|
||||
);
|
||||
}
|
||||
|
||||
Iterable<int> get ids => [...includedIds, ...excludedIds];
|
||||
|
||||
@override
|
||||
Map<String, String> toQueryParameter() {
|
||||
final Map<String, String> params = {};
|
||||
if (includedIds.isNotEmpty) {
|
||||
params.putIfAbsent('tags__id__all', () => includedIds.join(','));
|
||||
}
|
||||
if (excludedIds.isNotEmpty) {
|
||||
params.putIfAbsent('tags__id__none', () => excludedIds.join(','));
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [_idQueries];
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'queries': _idQueries.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
}
|
||||
|
||||
factory IdsTagsQuery.fromJson(Map<String, dynamic> json) {
|
||||
return IdsTagsQuery(
|
||||
(json['queries'] as List).map((e) => TagIdQuery.fromJson(e)),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool matches(Iterable<int> ids) {
|
||||
return includedIds.toSet().difference(ids.toSet()).isEmpty &&
|
||||
excludedIds.toSet().intersection(ids.toSet()).isEmpty;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import 'package:paperless_api/src/models/query_parameters/tags_query/tag_id_query.dart';
|
||||
|
||||
import 'exclude_tag_id_query.dart';
|
||||
|
||||
class IncludeTagIdQuery extends TagIdQuery {
|
||||
const IncludeTagIdQuery(super.id);
|
||||
|
||||
@override
|
||||
String get methodName => 'include';
|
||||
|
||||
@override
|
||||
TagIdQuery toggle() {
|
||||
return ExcludeTagIdQuery(id);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
import 'tags_query.dart';
|
||||
|
||||
class OnlyNotAssignedTagsQuery extends TagsQuery {
|
||||
const OnlyNotAssignedTagsQuery();
|
||||
@override
|
||||
Map<String, String> toQueryParameter() {
|
||||
return {'is_tagged': '0'};
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return {};
|
||||
}
|
||||
|
||||
@override
|
||||
bool matches(Iterable<int> ids) {
|
||||
return ids.isEmpty;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
|
||||
abstract class TagIdQuery extends Equatable {
|
||||
final int id;
|
||||
|
||||
const TagIdQuery(this.id);
|
||||
|
||||
String get methodName;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, methodName];
|
||||
|
||||
TagIdQuery toggle();
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'type': methodName,
|
||||
'id': id,
|
||||
};
|
||||
}
|
||||
|
||||
factory TagIdQuery.fromJson(Map<String, dynamic> json) {
|
||||
final type = json['type'] as String;
|
||||
var id = json['id'];
|
||||
switch (type) {
|
||||
case 'include':
|
||||
return IncludeTagIdQuery(id);
|
||||
case 'exclude':
|
||||
return ExcludeTagIdQuery(id);
|
||||
default:
|
||||
throw Exception('Error parsing TagIdQuery: Unknown type $type');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
export 'any_assigned_tags_query.dart';
|
||||
export 'ids_tags_query.dart';
|
||||
export 'tags_query.dart';
|
||||
export 'exclude_tag_id_query.dart';
|
||||
export 'include_tag_id_query.dart';
|
||||
export 'only_not_assigned_tags_query.dart';
|
||||
export 'tag_id_query.dart';
|
||||
@@ -1,9 +1,64 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:paperless_api/config/hive/hive_type_ids.dart';
|
||||
part 'tags_query.freezed.dart';
|
||||
part 'tags_query.g.dart';
|
||||
|
||||
abstract class TagsQuery extends Equatable {
|
||||
const TagsQuery();
|
||||
Map<String, String> toQueryParameter();
|
||||
Map<String, dynamic> toJson();
|
||||
@freezed
|
||||
class TagsQuery with _$TagsQuery {
|
||||
const TagsQuery._();
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.notAssignedTagsQuery)
|
||||
const factory TagsQuery.notAssigned() = NotAssignedTagsQuery;
|
||||
|
||||
bool matches(Iterable<int> ids);
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.anyAssignedTagsQuery)
|
||||
const factory TagsQuery.anyAssigned({
|
||||
@Default([]) Iterable<int> tagIds,
|
||||
}) = AnyAssignedTagsQuery;
|
||||
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.idsTagsQuery)
|
||||
const factory TagsQuery.ids({
|
||||
@Default([]) Iterable<int> include,
|
||||
@Default([]) Iterable<int> exclude,
|
||||
}) = IdsTagsQuery;
|
||||
|
||||
Map<String, String> toQueryParameter() {
|
||||
return when(
|
||||
anyAssigned: (tagIds) {
|
||||
if (tagIds.isEmpty) {
|
||||
return {'is_tagged': '1'};
|
||||
}
|
||||
return {'tags__id__in': tagIds.join(',')};
|
||||
},
|
||||
ids: (include, exclude) {
|
||||
final Map<String, String> params = {};
|
||||
if (include.isNotEmpty) {
|
||||
params.putIfAbsent('tags__id__all', () => include.join(','));
|
||||
}
|
||||
if (exclude.isNotEmpty) {
|
||||
params.putIfAbsent('tags__id__none', () => exclude.join(','));
|
||||
}
|
||||
return params;
|
||||
},
|
||||
notAssigned: () {
|
||||
return {'is_tagged': '0'};
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {};
|
||||
}
|
||||
|
||||
bool matches(Iterable<int> ids) {
|
||||
return when(
|
||||
anyAssigned: (_) => ids.isNotEmpty,
|
||||
ids: (include, exclude) =>
|
||||
include.toSet().difference(ids.toSet()).isEmpty &&
|
||||
exclude.toSet().intersection(ids.toSet()).isEmpty,
|
||||
notAssigned: () => ids.isEmpty,
|
||||
);
|
||||
}
|
||||
|
||||
factory TagsQuery.fromJson(Map<String, dynamic> json) => _$TagsQueryFromJson(json);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,566 @@
|
||||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'tags_query.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
|
||||
|
||||
TagsQuery _$TagsQueryFromJson(Map<String, dynamic> json) {
|
||||
switch (json['runtimeType']) {
|
||||
case 'notAssigned':
|
||||
return NotAssignedTagsQuery.fromJson(json);
|
||||
case 'anyAssigned':
|
||||
return AnyAssignedTagsQuery.fromJson(json);
|
||||
case 'ids':
|
||||
return IdsTagsQuery.fromJson(json);
|
||||
|
||||
default:
|
||||
throw CheckedFromJsonException(json, 'runtimeType', 'TagsQuery',
|
||||
'Invalid union type "${json['runtimeType']}"!');
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$TagsQuery {
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() notAssigned,
|
||||
required TResult Function(Iterable<int> tagIds) anyAssigned,
|
||||
required TResult Function(Iterable<int> include, Iterable<int> exclude) ids,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? notAssigned,
|
||||
TResult? Function(Iterable<int> tagIds)? anyAssigned,
|
||||
TResult? Function(Iterable<int> include, Iterable<int> exclude)? ids,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? notAssigned,
|
||||
TResult Function(Iterable<int> tagIds)? anyAssigned,
|
||||
TResult Function(Iterable<int> include, Iterable<int> exclude)? ids,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(NotAssignedTagsQuery value) notAssigned,
|
||||
required TResult Function(AnyAssignedTagsQuery value) anyAssigned,
|
||||
required TResult Function(IdsTagsQuery value) ids,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(NotAssignedTagsQuery value)? notAssigned,
|
||||
TResult? Function(AnyAssignedTagsQuery value)? anyAssigned,
|
||||
TResult? Function(IdsTagsQuery value)? ids,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(NotAssignedTagsQuery value)? notAssigned,
|
||||
TResult Function(AnyAssignedTagsQuery value)? anyAssigned,
|
||||
TResult Function(IdsTagsQuery value)? ids,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $TagsQueryCopyWith<$Res> {
|
||||
factory $TagsQueryCopyWith(TagsQuery value, $Res Function(TagsQuery) then) =
|
||||
_$TagsQueryCopyWithImpl<$Res, TagsQuery>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$TagsQueryCopyWithImpl<$Res, $Val extends TagsQuery>
|
||||
implements $TagsQueryCopyWith<$Res> {
|
||||
_$TagsQueryCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$NotAssignedTagsQueryCopyWith<$Res> {
|
||||
factory _$$NotAssignedTagsQueryCopyWith(_$NotAssignedTagsQuery value,
|
||||
$Res Function(_$NotAssignedTagsQuery) then) =
|
||||
__$$NotAssignedTagsQueryCopyWithImpl<$Res>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$NotAssignedTagsQueryCopyWithImpl<$Res>
|
||||
extends _$TagsQueryCopyWithImpl<$Res, _$NotAssignedTagsQuery>
|
||||
implements _$$NotAssignedTagsQueryCopyWith<$Res> {
|
||||
__$$NotAssignedTagsQueryCopyWithImpl(_$NotAssignedTagsQuery _value,
|
||||
$Res Function(_$NotAssignedTagsQuery) _then)
|
||||
: super(_value, _then);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.notAssignedTagsQuery)
|
||||
class _$NotAssignedTagsQuery extends NotAssignedTagsQuery {
|
||||
const _$NotAssignedTagsQuery({final String? $type})
|
||||
: $type = $type ?? 'notAssigned',
|
||||
super._();
|
||||
|
||||
factory _$NotAssignedTagsQuery.fromJson(Map<String, dynamic> json) =>
|
||||
_$$NotAssignedTagsQueryFromJson(json);
|
||||
|
||||
@JsonKey(name: 'runtimeType')
|
||||
final String $type;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'TagsQuery.notAssigned()';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(dynamic other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType && other is _$NotAssignedTagsQuery);
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() notAssigned,
|
||||
required TResult Function(Iterable<int> tagIds) anyAssigned,
|
||||
required TResult Function(Iterable<int> include, Iterable<int> exclude) ids,
|
||||
}) {
|
||||
return notAssigned();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? notAssigned,
|
||||
TResult? Function(Iterable<int> tagIds)? anyAssigned,
|
||||
TResult? Function(Iterable<int> include, Iterable<int> exclude)? ids,
|
||||
}) {
|
||||
return notAssigned?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? notAssigned,
|
||||
TResult Function(Iterable<int> tagIds)? anyAssigned,
|
||||
TResult Function(Iterable<int> include, Iterable<int> exclude)? ids,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (notAssigned != null) {
|
||||
return notAssigned();
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(NotAssignedTagsQuery value) notAssigned,
|
||||
required TResult Function(AnyAssignedTagsQuery value) anyAssigned,
|
||||
required TResult Function(IdsTagsQuery value) ids,
|
||||
}) {
|
||||
return notAssigned(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(NotAssignedTagsQuery value)? notAssigned,
|
||||
TResult? Function(AnyAssignedTagsQuery value)? anyAssigned,
|
||||
TResult? Function(IdsTagsQuery value)? ids,
|
||||
}) {
|
||||
return notAssigned?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(NotAssignedTagsQuery value)? notAssigned,
|
||||
TResult Function(AnyAssignedTagsQuery value)? anyAssigned,
|
||||
TResult Function(IdsTagsQuery value)? ids,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (notAssigned != null) {
|
||||
return notAssigned(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$NotAssignedTagsQueryToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class NotAssignedTagsQuery extends TagsQuery {
|
||||
const factory NotAssignedTagsQuery() = _$NotAssignedTagsQuery;
|
||||
const NotAssignedTagsQuery._() : super._();
|
||||
|
||||
factory NotAssignedTagsQuery.fromJson(Map<String, dynamic> json) =
|
||||
_$NotAssignedTagsQuery.fromJson;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$AnyAssignedTagsQueryCopyWith<$Res> {
|
||||
factory _$$AnyAssignedTagsQueryCopyWith(_$AnyAssignedTagsQuery value,
|
||||
$Res Function(_$AnyAssignedTagsQuery) then) =
|
||||
__$$AnyAssignedTagsQueryCopyWithImpl<$Res>;
|
||||
@useResult
|
||||
$Res call({Iterable<int> tagIds});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$AnyAssignedTagsQueryCopyWithImpl<$Res>
|
||||
extends _$TagsQueryCopyWithImpl<$Res, _$AnyAssignedTagsQuery>
|
||||
implements _$$AnyAssignedTagsQueryCopyWith<$Res> {
|
||||
__$$AnyAssignedTagsQueryCopyWithImpl(_$AnyAssignedTagsQuery _value,
|
||||
$Res Function(_$AnyAssignedTagsQuery) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? tagIds = null,
|
||||
}) {
|
||||
return _then(_$AnyAssignedTagsQuery(
|
||||
tagIds: null == tagIds
|
||||
? _value.tagIds
|
||||
: tagIds // ignore: cast_nullable_to_non_nullable
|
||||
as Iterable<int>,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.anyAssignedTagsQuery)
|
||||
class _$AnyAssignedTagsQuery extends AnyAssignedTagsQuery {
|
||||
const _$AnyAssignedTagsQuery({this.tagIds = const [], final String? $type})
|
||||
: $type = $type ?? 'anyAssigned',
|
||||
super._();
|
||||
|
||||
factory _$AnyAssignedTagsQuery.fromJson(Map<String, dynamic> json) =>
|
||||
_$$AnyAssignedTagsQueryFromJson(json);
|
||||
|
||||
@override
|
||||
@JsonKey()
|
||||
final Iterable<int> tagIds;
|
||||
|
||||
@JsonKey(name: 'runtimeType')
|
||||
final String $type;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'TagsQuery.anyAssigned(tagIds: $tagIds)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(dynamic other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$AnyAssignedTagsQuery &&
|
||||
const DeepCollectionEquality().equals(other.tagIds, tagIds));
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode =>
|
||||
Object.hash(runtimeType, const DeepCollectionEquality().hash(tagIds));
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$AnyAssignedTagsQueryCopyWith<_$AnyAssignedTagsQuery> get copyWith =>
|
||||
__$$AnyAssignedTagsQueryCopyWithImpl<_$AnyAssignedTagsQuery>(
|
||||
this, _$identity);
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() notAssigned,
|
||||
required TResult Function(Iterable<int> tagIds) anyAssigned,
|
||||
required TResult Function(Iterable<int> include, Iterable<int> exclude) ids,
|
||||
}) {
|
||||
return anyAssigned(tagIds);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? notAssigned,
|
||||
TResult? Function(Iterable<int> tagIds)? anyAssigned,
|
||||
TResult? Function(Iterable<int> include, Iterable<int> exclude)? ids,
|
||||
}) {
|
||||
return anyAssigned?.call(tagIds);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? notAssigned,
|
||||
TResult Function(Iterable<int> tagIds)? anyAssigned,
|
||||
TResult Function(Iterable<int> include, Iterable<int> exclude)? ids,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (anyAssigned != null) {
|
||||
return anyAssigned(tagIds);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(NotAssignedTagsQuery value) notAssigned,
|
||||
required TResult Function(AnyAssignedTagsQuery value) anyAssigned,
|
||||
required TResult Function(IdsTagsQuery value) ids,
|
||||
}) {
|
||||
return anyAssigned(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(NotAssignedTagsQuery value)? notAssigned,
|
||||
TResult? Function(AnyAssignedTagsQuery value)? anyAssigned,
|
||||
TResult? Function(IdsTagsQuery value)? ids,
|
||||
}) {
|
||||
return anyAssigned?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(NotAssignedTagsQuery value)? notAssigned,
|
||||
TResult Function(AnyAssignedTagsQuery value)? anyAssigned,
|
||||
TResult Function(IdsTagsQuery value)? ids,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (anyAssigned != null) {
|
||||
return anyAssigned(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$AnyAssignedTagsQueryToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AnyAssignedTagsQuery extends TagsQuery {
|
||||
const factory AnyAssignedTagsQuery({final Iterable<int> tagIds}) =
|
||||
_$AnyAssignedTagsQuery;
|
||||
const AnyAssignedTagsQuery._() : super._();
|
||||
|
||||
factory AnyAssignedTagsQuery.fromJson(Map<String, dynamic> json) =
|
||||
_$AnyAssignedTagsQuery.fromJson;
|
||||
|
||||
Iterable<int> get tagIds;
|
||||
@JsonKey(ignore: true)
|
||||
_$$AnyAssignedTagsQueryCopyWith<_$AnyAssignedTagsQuery> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$IdsTagsQueryCopyWith<$Res> {
|
||||
factory _$$IdsTagsQueryCopyWith(
|
||||
_$IdsTagsQuery value, $Res Function(_$IdsTagsQuery) then) =
|
||||
__$$IdsTagsQueryCopyWithImpl<$Res>;
|
||||
@useResult
|
||||
$Res call({Iterable<int> include, Iterable<int> exclude});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$IdsTagsQueryCopyWithImpl<$Res>
|
||||
extends _$TagsQueryCopyWithImpl<$Res, _$IdsTagsQuery>
|
||||
implements _$$IdsTagsQueryCopyWith<$Res> {
|
||||
__$$IdsTagsQueryCopyWithImpl(
|
||||
_$IdsTagsQuery _value, $Res Function(_$IdsTagsQuery) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? include = null,
|
||||
Object? exclude = null,
|
||||
}) {
|
||||
return _then(_$IdsTagsQuery(
|
||||
include: null == include
|
||||
? _value.include
|
||||
: include // ignore: cast_nullable_to_non_nullable
|
||||
as Iterable<int>,
|
||||
exclude: null == exclude
|
||||
? _value.exclude
|
||||
: exclude // ignore: cast_nullable_to_non_nullable
|
||||
as Iterable<int>,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.idsTagsQuery)
|
||||
class _$IdsTagsQuery extends IdsTagsQuery {
|
||||
const _$IdsTagsQuery(
|
||||
{this.include = const [], this.exclude = const [], final String? $type})
|
||||
: $type = $type ?? 'ids',
|
||||
super._();
|
||||
|
||||
factory _$IdsTagsQuery.fromJson(Map<String, dynamic> json) =>
|
||||
_$$IdsTagsQueryFromJson(json);
|
||||
|
||||
@override
|
||||
@JsonKey()
|
||||
final Iterable<int> include;
|
||||
@override
|
||||
@JsonKey()
|
||||
final Iterable<int> exclude;
|
||||
|
||||
@JsonKey(name: 'runtimeType')
|
||||
final String $type;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'TagsQuery.ids(include: $include, exclude: $exclude)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(dynamic other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$IdsTagsQuery &&
|
||||
const DeepCollectionEquality().equals(other.include, include) &&
|
||||
const DeepCollectionEquality().equals(other.exclude, exclude));
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType,
|
||||
const DeepCollectionEquality().hash(include),
|
||||
const DeepCollectionEquality().hash(exclude));
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$IdsTagsQueryCopyWith<_$IdsTagsQuery> get copyWith =>
|
||||
__$$IdsTagsQueryCopyWithImpl<_$IdsTagsQuery>(this, _$identity);
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function() notAssigned,
|
||||
required TResult Function(Iterable<int> tagIds) anyAssigned,
|
||||
required TResult Function(Iterable<int> include, Iterable<int> exclude) ids,
|
||||
}) {
|
||||
return ids(include, exclude);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult? Function()? notAssigned,
|
||||
TResult? Function(Iterable<int> tagIds)? anyAssigned,
|
||||
TResult? Function(Iterable<int> include, Iterable<int> exclude)? ids,
|
||||
}) {
|
||||
return ids?.call(include, exclude);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function()? notAssigned,
|
||||
TResult Function(Iterable<int> tagIds)? anyAssigned,
|
||||
TResult Function(Iterable<int> include, Iterable<int> exclude)? ids,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (ids != null) {
|
||||
return ids(include, exclude);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(NotAssignedTagsQuery value) notAssigned,
|
||||
required TResult Function(AnyAssignedTagsQuery value) anyAssigned,
|
||||
required TResult Function(IdsTagsQuery value) ids,
|
||||
}) {
|
||||
return ids(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult? Function(NotAssignedTagsQuery value)? notAssigned,
|
||||
TResult? Function(AnyAssignedTagsQuery value)? anyAssigned,
|
||||
TResult? Function(IdsTagsQuery value)? ids,
|
||||
}) {
|
||||
return ids?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(NotAssignedTagsQuery value)? notAssigned,
|
||||
TResult Function(AnyAssignedTagsQuery value)? anyAssigned,
|
||||
TResult Function(IdsTagsQuery value)? ids,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (ids != null) {
|
||||
return ids(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$IdsTagsQueryToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class IdsTagsQuery extends TagsQuery {
|
||||
const factory IdsTagsQuery(
|
||||
{final Iterable<int> include,
|
||||
final Iterable<int> exclude}) = _$IdsTagsQuery;
|
||||
const IdsTagsQuery._() : super._();
|
||||
|
||||
factory IdsTagsQuery.fromJson(Map<String, dynamic> json) =
|
||||
_$IdsTagsQuery.fromJson;
|
||||
|
||||
Iterable<int> get include;
|
||||
Iterable<int> get exclude;
|
||||
@JsonKey(ignore: true)
|
||||
_$$IdsTagsQueryCopyWith<_$IdsTagsQuery> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
@@ -1,13 +1,18 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:paperless_api/config/hive/hive_type_ids.dart';
|
||||
|
||||
import 'query_type.dart';
|
||||
|
||||
part 'text_query.g.dart';
|
||||
|
||||
@HiveType(typeId: PaperlessApiHiveTypeIds.textQuery)
|
||||
@JsonSerializable()
|
||||
class TextQuery extends Equatable {
|
||||
@HiveField(0)
|
||||
final QueryType queryType;
|
||||
@HiveField(1)
|
||||
final String? queryText;
|
||||
|
||||
const TextQuery({
|
||||
@@ -17,8 +22,7 @@ class TextQuery extends Equatable {
|
||||
|
||||
const TextQuery.title(this.queryText) : queryType = QueryType.title;
|
||||
|
||||
const TextQuery.titleAndContent(this.queryText)
|
||||
: queryType = QueryType.titleAndContent;
|
||||
const TextQuery.titleAndContent(this.queryText) : queryType = QueryType.titleAndContent;
|
||||
|
||||
const TextQuery.extended(this.queryText) : queryType = QueryType.extended;
|
||||
|
||||
@@ -68,8 +72,7 @@ class TextQuery extends Equatable {
|
||||
case QueryType.title:
|
||||
return title.contains(queryText!);
|
||||
case QueryType.titleAndContent:
|
||||
return title.contains(queryText!) ||
|
||||
(content?.contains(queryText!) ?? false);
|
||||
return title.contains(queryText!) || (content?.contains(queryText!) ?? false);
|
||||
case QueryType.extended:
|
||||
//TODO: Implement. Might be too complex...
|
||||
return true;
|
||||
@@ -80,8 +83,7 @@ class TextQuery extends Equatable {
|
||||
|
||||
Map<String, dynamic> toJson() => _$TextQueryToJson(this);
|
||||
|
||||
factory TextQuery.fromJson(Map<String, dynamic> json) =>
|
||||
_$TextQueryFromJson(json);
|
||||
factory TextQuery.fromJson(Map<String, dynamic> json) => _$TextQueryFromJson(json);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [queryType, queryText];
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_api/src/models/query_parameters/tags_query/include_tag_id_query.dart';
|
||||
import 'package:paperless_api/src/models/query_parameters/text_query.dart';
|
||||
|
||||
void main() {
|
||||
@@ -70,13 +69,9 @@ void main() {
|
||||
correspondent: const IdQueryParameter.fromId(42),
|
||||
documentType: const IdQueryParameter.fromId(69),
|
||||
storagePath: const IdQueryParameter.fromId(14),
|
||||
tags: const IdsTagsQuery(
|
||||
[
|
||||
IncludeTagIdQuery(1),
|
||||
IncludeTagIdQuery(2),
|
||||
ExcludeTagIdQuery(3),
|
||||
ExcludeTagIdQuery(4),
|
||||
],
|
||||
tags: const TagsQuery.ids(
|
||||
include: [1, 2],
|
||||
exclude: [3, 4],
|
||||
),
|
||||
created: AbsoluteDateRangeQuery(
|
||||
before: DateTime.parse("2022-10-27"),
|
||||
@@ -140,7 +135,7 @@ void main() {
|
||||
correspondent: const IdQueryParameter.notAssigned(),
|
||||
documentType: const IdQueryParameter.notAssigned(),
|
||||
storagePath: const IdQueryParameter.notAssigned(),
|
||||
tags: const OnlyNotAssignedTagsQuery(),
|
||||
tags: const TagsQuery.notAssigned(),
|
||||
);
|
||||
expect(
|
||||
actual,
|
||||
@@ -157,13 +152,10 @@ void main() {
|
||||
correspondent: const IdQueryParameter.fromId(1),
|
||||
documentType: const IdQueryParameter.fromId(2),
|
||||
storagePath: const IdQueryParameter.fromId(3),
|
||||
tags: const IdsTagsQuery([
|
||||
IncludeTagIdQuery(4),
|
||||
IncludeTagIdQuery(5),
|
||||
ExcludeTagIdQuery(6),
|
||||
ExcludeTagIdQuery(7),
|
||||
ExcludeTagIdQuery(8),
|
||||
]),
|
||||
tags: const TagsQuery.ids(
|
||||
include: [4, 5],
|
||||
exclude: [6, 7, 8],
|
||||
),
|
||||
sortField: SortField.added,
|
||||
sortOrder: SortOrder.ascending,
|
||||
created: AbsoluteDateRangeQuery(
|
||||
@@ -241,11 +233,11 @@ void main() {
|
||||
test('Values are correctly parsed if not assigned.', () {
|
||||
expect(
|
||||
SavedView.fromDocumentFilter(
|
||||
DocumentFilter(
|
||||
correspondent: const IdQueryParameter.notAssigned(),
|
||||
documentType: const IdQueryParameter.notAssigned(),
|
||||
storagePath: const IdQueryParameter.notAssigned(),
|
||||
tags: const OnlyNotAssignedTagsQuery(),
|
||||
const DocumentFilter(
|
||||
correspondent: IdQueryParameter.notAssigned(),
|
||||
documentType: IdQueryParameter.notAssigned(),
|
||||
storagePath: IdQueryParameter.notAssigned(),
|
||||
tags: TagsQuery.notAssigned(),
|
||||
sortField: SortField.created,
|
||||
sortOrder: SortOrder.ascending,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user