Skip to content

Commit c0256e2

Browse files
committed
feat(dart): setHeaderUserIDThenSaveObjects (+ local vars)
1 parent 4020690 commit c0256e2

File tree

6 files changed

+39
-2
lines changed

6 files changed

+39
-2
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{> snippets/import}}
2+
3+
final playlists = []; // Your records
4+
5+
void setHeaderUserIDThenSaveObjects() async {
6+
{{> snippets/init}}
7+
8+
for (final playlist in playlists) {
9+
final playlistUserID = playlist["userID"];
10+
final batchParams = BatchWriteParams(
11+
requests: playlists
12+
.map((record) => BatchRequest(
13+
action: Action.addObject,
14+
body: record,
15+
))
16+
.toList());
17+
await {{#dynamicSnippet}}batchChunksWithRequestOptions{{/dynamicSnippet}};
18+
}
19+
}

templates/dart/tests/method.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ client.{{method}}(
77
{{#requestOptions.headers}}
88
headers: {
99
{{#parametersWithDataType}}
10-
'{{{key}}}' : '{{value}}',
10+
'{{{key}}}' : {{> tests/param_value}},
1111
{{/parametersWithDataType}}
1212
},
1313
{{/requestOptions.headers}}

templates/kotlin/guides/search/setHeaderUserIDThenSaveObjects.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{{> snippets/import}}
22
import com.algolia.client.model.search.*
33

4+
val playlists: List<Map<String, Any>> = listOf() // Your records
5+
46
suspend fun setHeaderUserIDThenSaveObjects() {
57
{{> snippets/init}}
68

templates/scala/guides/search/setHeaderUserIDThenSaveObjects.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import scala.concurrent.duration.Duration
55

66
{{> snippets/import}}
77

8+
val playlists: Seq[Any] = Seq() // Your records
9+
810
def setHeaderUserIDThenSaveObjects(): Future[Unit] = {
911
{{> snippets/init}}
1012

templates/swift/guides/search/setHeaderUserIDThenSaveObjects.mustache

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import Foundation
66
import Core
77
{{> snippets/import}}
88

9+
let playlists: [[String: AnyCodable]] = [/* Your records */]
10+
911
func setHeaderUserIDThenSaveObjects() async throws {
1012
do {
1113
{{> snippets/init}}
1214

1315
for playlist in playlists {
14-
let playlistUserID = playlist.userID
16+
let playlistUserID = playlist["userID"]?.value as! String
1517
{{#dynamicSnippet}}saveObjectsPlaylistsWithRequestOptions{{/dynamicSnippet}}
1618
}
1719
} catch {

tests/CTS/guides/search.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@
9292
}
9393
}
9494
},
95+
"batchChunksWithRequestOptions": {
96+
"method": "batch",
97+
"parameters": {
98+
"indexName": "indexName",
99+
"batchWriteParams": "$var: batchParams"
100+
},
101+
"requestOptions": {
102+
"headers": {
103+
"X-Algolia-User-ID": "$var: playlistUserID"
104+
}
105+
}
106+
},
95107
"setSettings": {
96108
"method": "setSettings",
97109
"parameters": {

0 commit comments

Comments
 (0)