@@ -3,58 +3,217 @@ package {{ sdk.namespace | caseDot }}
3
3
import {{ sdk .namespace | caseDot }}.extensions.toJson
4
4
import {{ sdk .namespace | caseDot }}.extensions.fromJson
5
5
6
+ /**
7
+ * Helper class to generate query strings.
8
+ */
6
9
class Query(
7
10
val method: String,
8
11
val attribute: String? = null,
9
12
val values: List<Any >? = null,
10
13
) {
14
+ /**
15
+ * Convert the query object to a JSON string.
16
+ *
17
+ * @returns The JSON string representation of the query object.
18
+ */
11
19
override fun toString() = this.toJson()
12
20
13
21
companion object {
22
+
23
+ /**
24
+ * Filter resources where attribute is equal to value.
25
+ *
26
+ * @param attribute The attribute to filter on.
27
+ * @param value The value to compare against.
28
+ * @returns The query string.
29
+ */
14
30
fun equal(attribute: String, value: Any) = Query("equal", attribute, parseValue(value)).toJson()
15
31
32
+ /**
33
+ * Filter resources where attribute is not equal to value.
34
+ *
35
+ * @param attribute The attribute to filter on.
36
+ * @param value The value to compare against.
37
+ * @returns The query string.
38
+ */
16
39
fun notEqual(attribute: String, value: Any) = Query("notEqual", attribute, parseValue(value)).toJson()
17
40
41
+ /**
42
+ * Filter resources where attribute is less than value.
43
+ *
44
+ * @param attribute The attribute to filter on.
45
+ * @param value The value to compare against.
46
+ * @returns The query string.
47
+ */
18
48
fun lessThan(attribute: String, value: Any) = Query("lessThan", attribute, parseValue(value)).toJson()
19
49
50
+ /**
51
+ * Filter resources where attribute is less than or equal to value.
52
+ *
53
+ * @param attribute The attribute to filter on.
54
+ * @param value The value to compare against.
55
+ * @returns The query string.
56
+ */
20
57
fun lessThanEqual(attribute: String, value: Any) = Query("lessThanEqual", attribute, parseValue(value)).toJson()
21
58
59
+ /**
60
+ * Filter resources where attribute is greater than value.
61
+ *
62
+ * @param attribute The attribute to filter on.
63
+ * @param value The value to compare against.
64
+ * @returns The query string.
65
+ */
22
66
fun greaterThan(attribute: String, value: Any) = Query("greaterThan", attribute, parseValue(value)).toJson()
23
67
68
+ /**
69
+ * Filter resources where attribute is greater than or equal to value.
70
+ *
71
+ * @param attribute The attribute to filter on.
72
+ * @param value The value to compare against.
73
+ * @returns The query string.
74
+ */
24
75
fun greaterThanEqual(attribute: String, value: Any) = Query("greaterThanEqual", attribute, parseValue(value)).toJson()
25
76
77
+ /**
78
+ * Filter resources where attribute matches the search value.
79
+ *
80
+ * @param attribute The attribute to filter on.
81
+ * @param value The search value to match against.
82
+ * @returns The query string.
83
+ */
26
84
fun search(attribute: String, value: String) = Query("search", attribute, listOf(value)).toJson()
27
85
86
+ /**
87
+ * Filter resources where attribute is null.
88
+ *
89
+ * @param attribute The attribute to filter on.
90
+ * @returns The query string.
91
+ */
28
92
fun isNull(attribute: String) = Query("isNull", attribute).toJson()
29
93
94
+ /**
95
+ * Filter resources where attribute is not null.
96
+ *
97
+ * @param attribute The attribute to filter on.
98
+ * @returns The query string.
99
+ */
30
100
fun isNotNull(attribute: String) = Query("isNotNull", attribute).toJson()
31
101
102
+ /**
103
+ * Filter resources where attribute is between start and end (inclusive).
104
+ *
105
+ * @param attribute The attribute to filter on.
106
+ * @param start The start value of the range.
107
+ * @param end The end value of the range.
108
+ * @returns The query string.
109
+ */
32
110
fun between(attribute: String, start: Any, end: Any) = Query("between", attribute, listOf(start, end)).toJson()
33
111
112
+ /**
113
+ * Filter resources where attribute starts with value.
114
+ *
115
+ * @param attribute The attribute to filter on.
116
+ * @param value The value to compare against.
117
+ * @returns The query string.
118
+ */
34
119
fun startsWith(attribute: String, value: String) = Query("startsWith", attribute, listOf(value)).toJson()
35
120
121
+ /**
122
+ * Filter resources where attribute ends with value.
123
+ *
124
+ * @param attribute The attribute to filter on.
125
+ * @param value The value to compare against.
126
+ * @returns The query string.
127
+ */
36
128
fun endsWith(attribute: String, value: String) = Query("endsWith", attribute, listOf(value)).toJson()
37
129
130
+ /**
131
+ * Specify which attributes should be returned by the API call.
132
+ *
133
+ * @param attributes The list of attributes to select.
134
+ * @returns The query string.
135
+ */
38
136
fun select(attributes: List<String >) = Query("select", null, attributes).toJson()
39
137
138
+ /**
139
+ * Sort results by attribute ascending.
140
+ *
141
+ * @param attribute The attribute to sort by.
142
+ * @returns The query string.
143
+ */
40
144
fun orderAsc(attribute: String) = Query("orderAsc", attribute).toJson()
41
145
146
+ /**
147
+ * Sort results by attribute descending.
148
+ *
149
+ * @param attribute The attribute to sort by.
150
+ * @returns The query string.
151
+ */
42
152
fun orderDesc(attribute: String) = Query("orderDesc", attribute).toJson()
43
153
154
+ /**
155
+ * Return results before documentId.
156
+ *
157
+ * @param documentId The document ID to use as cursor.
158
+ * @returns The query string.
159
+ */
44
160
fun cursorBefore(documentId: String) = Query("cursorBefore", null, listOf(documentId)).toJson()
45
161
162
+ /**
163
+ * Return results after documentId.
164
+ *
165
+ * @param documentId The document ID to use as cursor.
166
+ * @returns The query string.
167
+ */
46
168
fun cursorAfter(documentId: String) = Query("cursorAfter", null, listOf(documentId)).toJson()
47
-
169
+
170
+ /**
171
+ * Return only limit results.
172
+ *
173
+ * @param limit The number of results to return.
174
+ * @returns The query string.
175
+ */
48
176
fun limit(limit: Int) = Query("limit", null, listOf(limit)).toJson()
49
177
178
+ /**
179
+ * Filter resources by skipping the first offset results.
180
+ *
181
+ * @param offset The number of results to skip.
182
+ * @returns The query string.
183
+ */
50
184
fun offset(offset: Int) = Query("offset", null, listOf(offset)).toJson()
51
185
186
+ /**
187
+ * Filter resources where attribute contains the specified value.
188
+ *
189
+ * @param attribute The attribute to filter on.
190
+ * @param value The value to compare against.
191
+ * @returns The query string.
192
+ */
52
193
fun contains(attribute: String, value: Any) = Query("contains", attribute, parseValue(value)).toJson()
53
194
195
+ /**
196
+ * Combine multiple queries using logical OR operator.
197
+ *
198
+ * @param queries The list of query strings to combine.
199
+ * @returns The query string.
200
+ */
54
201
fun or(queries: List<String >) = Query("or", null, queries.map { it.fromJson<Query >() }).toJson()
55
202
203
+ /**
204
+ * Combine multiple queries using logical AND operator.
205
+ *
206
+ * @param queries The list of query strings to combine.
207
+ * @returns The query string.
208
+ */
56
209
fun and(queries: List<String >) = Query("and", null, queries.map { it.fromJson<Query >() }).toJson()
57
210
211
+ /**
212
+ * Parse the value to a list of values.
213
+ *
214
+ * @param value The value to parse.
215
+ * @returns The list of parsed values.
216
+ */
58
217
private fun parseValue(value: Any): List<Any > {
59
218
return when (value) {
60
219
is List< *> -> value as List<Any >
0 commit comments