Skip to content

Commit

Permalink
feat(dart): setHeaderUserIDThenSaveObjects (+ local vars)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fluf22 committed Jan 24, 2025
1 parent 4020690 commit c0256e2
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{> snippets/import}}

final playlists = []; // Your records

void setHeaderUserIDThenSaveObjects() async {
{{> snippets/init}}

for (final playlist in playlists) {
final playlistUserID = playlist["userID"];
final batchParams = BatchWriteParams(
requests: playlists
.map((record) => BatchRequest(
action: Action.addObject,
body: record,
))
.toList());
await {{#dynamicSnippet}}batchChunksWithRequestOptions{{/dynamicSnippet}};
}
}
2 changes: 1 addition & 1 deletion templates/dart/tests/method.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ client.{{method}}(
{{#requestOptions.headers}}
headers: {
{{#parametersWithDataType}}
'{{{key}}}' : '{{value}}',
'{{{key}}}' : {{> tests/param_value}},
{{/parametersWithDataType}}
},
{{/requestOptions.headers}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{{> snippets/import}}
import com.algolia.client.model.search.*

val playlists: List<Map<String, Any>> = listOf() // Your records

suspend fun setHeaderUserIDThenSaveObjects() {
{{> snippets/init}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import scala.concurrent.duration.Duration

{{> snippets/import}}

val playlists: Seq[Any] = Seq() // Your records

def setHeaderUserIDThenSaveObjects(): Future[Unit] = {
{{> snippets/init}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import Foundation
import Core
{{> snippets/import}}

let playlists: [[String: AnyCodable]] = [/* Your records */]

func setHeaderUserIDThenSaveObjects() async throws {
do {
{{> snippets/init}}

for playlist in playlists {
let playlistUserID = playlist.userID
let playlistUserID = playlist["userID"]?.value as! String
{{#dynamicSnippet}}saveObjectsPlaylistsWithRequestOptions{{/dynamicSnippet}}
}
} catch {
Expand Down
12 changes: 12 additions & 0 deletions tests/CTS/guides/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@
}
}
},
"batchChunksWithRequestOptions": {
"method": "batch",
"parameters": {
"indexName": "indexName",
"batchWriteParams": "$var: batchParams"
},
"requestOptions": {
"headers": {
"X-Algolia-User-ID": "$var: playlistUserID"
}
}
},
"setSettings": {
"method": "setSettings",
"parameters": {
Expand Down

0 comments on commit c0256e2

Please sign in to comment.