Skip to content

Commit e2f72cc

Browse files
authored
refact: batch delete operation serialization (#640)
1 parent 9dbbe55 commit e2f72cc

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/main/scala/algolia/AlgoliaDsl.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ package algolia
2727

2828
import algolia.definitions._
2929
import algolia.dsl._
30+
import algolia.inputs.DeleteObjectOperation
3031
import algolia.objects._
32+
import org.json4s
3133
import org.json4s.JsonAST._
3234
import org.json4s.JsonDSL._
3335
import org.json4s.{CustomSerializer, FieldSerializer, Formats, JField}
@@ -92,6 +94,9 @@ object AlgoliaDsl extends AlgoliaDsl {
9294
new AlternativesSerializer +
9395
new FieldSerializer[IndexSettings](
9496
deserializer = numericAttributesToIndexDeserializer
97+
) +
98+
new FieldSerializer[DeleteObjectOperation[JValue]](
99+
serializer = deleteObjectOperationSerializer
95100
)
96101

97102
val searchableAttributesUnordered: Regex = """^unordered\(([\w-\\.]+)\)$""".r
@@ -417,6 +422,12 @@ object AlgoliaDsl extends AlgoliaDsl {
417422
)
418423
}
419424

425+
def deleteObjectOperationSerializer
426+
: PartialFunction[(String, Any), Option[(String, Any)]] = {
427+
case Tuple2("objectID", objectID) =>
428+
Some("body" -> ("objectID" -> objectID))
429+
}
430+
420431
case object forwardToSlaves extends ForwardToReplicas
421432

422433
case object forwardToReplicas extends ForwardToReplicas

src/test/scala/algolia/dsl/BatchTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ class BatchTest extends AlgoliaTest {
188188
| "requests":[
189189
| {
190190
| "indexName":"test1",
191-
| "objectID":"1",
191+
| "body":{"objectID":"1"},
192192
| "action":"deleteObject"
193193
| },{
194194
| "indexName":"test2",
195-
| "objectID":"2",
195+
| "body":{"objectID":"2"},
196196
| "action":"deleteObject"
197197
| }
198198
| ]

src/test/scala/algolia/dsl/DeleteObjectTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ class DeleteObjectTest extends AlgoliaTest {
6161
| {
6262
| "requests":[
6363
| {
64-
| "objectID":"1",
64+
| "body":{"objectID":"1"},
6565
| "action":"deleteObject"
6666
| },{
67-
| "objectID":"2",
67+
| "body":{"objectID":"2"},
6868
| "action":"deleteObject"
6969
| }
7070
| ]

0 commit comments

Comments
 (0)