-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathparams_post_list.dart
More file actions
113 lines (108 loc) · 3.46 KB
/
params_post_list.dart
File metadata and controls
113 lines (108 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import 'package:flutter_wordpress/constants.dart';
/// This class holds all arguments which can be used to filter posts when using
/// [WordPress.fetchPosts] method.
///
/// [List Posts' Arguments](https://developer.wordpress.org/rest-api/reference/posts/#list-posts)
class ParamsPostList {
final WordPressContext context;
final int pageNum;
final int perPage;
final String searchQuery;
final String afterDate;
final String beforeDate;
final List<int> includeAuthorIDs;
final List<int> excludeAuthorIDs;
final List<int> includePostIDs;
final List<int> excludePostIDs;
final int? offset;
final Order order;
final PostOrderBy orderBy;
final String slug;
final PostPageStatus postStatus;
final List<int> includeCategories;
final List<int> excludeCategories;
final List<int> includeTags;
final List<int> excludeTags;
final bool? sticky;
final List<String> fields;
ParamsPostList({
this.context = WordPressContext.view,
this.pageNum = 1,
this.perPage = 10,
this.searchQuery = '',
this.afterDate = '',
this.beforeDate = '',
this.includeAuthorIDs = const [],
this.excludeAuthorIDs = const [],
this.includePostIDs = const [],
this.excludePostIDs = const [],
this.offset,
this.order = Order.desc,
this.orderBy = PostOrderBy.date,
this.slug = '',
this.postStatus = PostPageStatus.publish,
this.includeCategories = const [],
this.excludeCategories = const [],
this.includeTags = const [],
this.excludeTags = const [],
this.sticky,
this.fields = const [],
});
Map<String, String> toMap() {
return {
'context': '${enumStringToName(this.context.toString())}',
'page': '${this.pageNum}',
'per_page': '${this.perPage}',
'search': '${this.searchQuery}',
'after': '${this.afterDate}',
'before': '${this.beforeDate}',
'author': '${listToUrlString(this.includeAuthorIDs)}',
'author_exclude': '${listToUrlString(this.excludeAuthorIDs)}',
'include': '${listToUrlString(includePostIDs)}',
'exclude': '${listToUrlString(excludePostIDs)}',
'offset': '${this.offset == null ? '' : this.offset}',
'order': '${enumStringToName(this.order.toString())}',
'orderby': '${enumStringToName(this.orderBy.toString())}',
'slug': '${this.slug}',
'status': '${enumStringToName(this.postStatus.toString())}',
'categories': '${listToUrlString(includeCategories)}',
'categories_exclude': '${listToUrlString(excludeCategories)}',
'tags': '${listToUrlString(includeTags)}',
'tags_exclude': '${listToUrlString(excludeTags)}',
'sticky': '${this.sticky == null ? '' : this.sticky}',
'_fields': this.fields.join(',')
};
}
ParamsPostList copyWith({
int? pageNum,
int? perPage,
}) {
return ParamsPostList(
afterDate: afterDate,
beforeDate: beforeDate,
context: context,
excludeAuthorIDs: excludeAuthorIDs,
excludeCategories: excludeCategories,
excludePostIDs: excludePostIDs,
excludeTags: excludeTags,
includeAuthorIDs: includeAuthorIDs,
includeCategories: includeCategories,
includePostIDs: includePostIDs,
includeTags: includeTags,
offset: offset,
order: order,
orderBy: orderBy,
pageNum: pageNum ?? this.pageNum,
perPage: perPage ?? this.perPage,
postStatus: postStatus,
searchQuery: searchQuery,
slug: slug,
sticky: sticky,
fields: fields,
);
}
@override
String toString() {
return constructUrlParams(toMap());
}
}