Skip to content

Commit 02972fc

Browse files
committed
feat(rule): expose rule.consequence.promote.objectIDs string array
1 parent 8b3f5f4 commit 02972fc

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

src/commonMain/kotlin/com/algolia/search/dsl/rule/DSLPromotions.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ public class DSLPromotions(
3434
return Promotion(this, position)
3535
}
3636

37+
/**
38+
* Create a [Promotion] with [this] and [position].
39+
*/
40+
public operator fun List<ObjectID>.invoke(position: Int): Promotion {
41+
return Promotion(this, position)
42+
}
43+
3744
public companion object : DSL<DSLPromotions, List<Promotion>> {
3845

3946
override operator fun invoke(block: DSLPromotions.() -> Unit): List<Promotion> {
Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,45 @@
1+
@file:Suppress("FunctionName")
2+
13
package com.algolia.search.model.rule
24

35
import com.algolia.search.model.ObjectID
46
import com.algolia.search.serialize.KeyObjectID
7+
import com.algolia.search.serialize.KeyObjectIDs
58
import com.algolia.search.serialize.KeyPosition
69
import kotlinx.serialization.SerialName
710
import kotlinx.serialization.Serializable
811

912
@Serializable
10-
public data class Promotion(
11-
/**
12-
* Unique identifier of the object to promote.
13-
*/
14-
@SerialName(KeyObjectID) val objectID: ObjectID,
15-
/**
16-
* Promoted rank for the object.
17-
*/
18-
@SerialName(KeyPosition) val position: Int
19-
)
13+
public sealed class Promotion {
14+
15+
abstract val position: Int
16+
17+
@Serializable
18+
data class Single(
19+
/**
20+
* Unique identifier of the object to promote.
21+
*/
22+
@SerialName(KeyObjectID) val objectID: ObjectID,
23+
24+
/**
25+
* Promoted rank for the object.
26+
*/
27+
@SerialName(KeyPosition) override val position: Int
28+
) : Promotion()
29+
30+
@Serializable
31+
data class Multiple(
32+
/**
33+
* Unique identifier of the object to promote.
34+
*/
35+
@SerialName(KeyObjectIDs) val objectIDs: List<ObjectID>,
36+
/**
37+
* Promoted rank for the object.
38+
*/
39+
@SerialName(KeyPosition) override val position: Int
40+
) : Promotion()
41+
}
42+
43+
fun Promotion(objectID: ObjectID, position: Int): Promotion.Single = Promotion.Single(objectID, position)
44+
45+
fun Promotion(objectIDs: List<ObjectID>, position: Int): Promotion.Multiple = Promotion.Multiple(objectIDs, position)

src/commonTest/kotlin/dsl/rule/TestDSLPromotions.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.algolia.search.dsl.rule.DSLPromotions
44
import com.algolia.search.model.ObjectID
55
import com.algolia.search.model.rule.Promotion
66
import objectIDA
7+
import objectIDB
78
import shouldEqual
89
import kotlin.test.Test
910

@@ -14,11 +15,13 @@ internal class TestDSLPromotions {
1415
val dsl = DSLPromotions {
1516
+objectIDA(10)
1617
+"objectIDB"(10)
18+
+listOf(objectIDA, objectIDB)(10)
1719
}
1820

1921
dsl shouldEqual listOf(
2022
Promotion(objectIDA, 10),
21-
Promotion(ObjectID("objectIDB"), 10)
23+
Promotion(ObjectID("objectIDB"), 10),
24+
Promotion(listOf(objectIDA, objectIDB), 10)
2225
)
2326
}
2427
}

0 commit comments

Comments
 (0)