Move DSL methods to builders, fix JS compilation
This commit is contained in:
parent
d6a1c0afa1
commit
3913c4af76
2 changed files with 17 additions and 19 deletions
|
@ -66,6 +66,9 @@ kotlin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getByName("jsMain") {
|
getByName("jsMain") {
|
||||||
|
dependencies {
|
||||||
|
implementation(kotlin("stdlib-js"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
getByName("jsTest") {
|
getByName("jsTest") {
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package de.pheerai.rcdbquery.dsl
|
||||||
import de.pheerai.rcdbquery.dataMappings.*
|
import de.pheerai.rcdbquery.dataMappings.*
|
||||||
|
|
||||||
inline class RcdbQueryParams(val params: Map<String, List<String>>)
|
inline class RcdbQueryParams(val params: Map<String, List<String>>)
|
||||||
|
|
||||||
class RcdbQueryParamsBuilder {
|
class RcdbQueryParamsBuilder {
|
||||||
// TODO: Make way for single-valued params as well
|
// TODO: Make way for single-valued params as well
|
||||||
private val params: MutableMap<String, List<RcdbParamOption<Any>>> = mutableMapOf()
|
private val params: MutableMap<String, List<RcdbParamOption<Any>>> = mutableMapOf()
|
||||||
|
@ -15,15 +16,8 @@ class RcdbQueryParamsBuilder {
|
||||||
)
|
)
|
||||||
|
|
||||||
operator fun set(paramName: String, options: List<RcdbParamOption<Any>>) {
|
operator fun set(paramName: String, options: List<RcdbParamOption<Any>>) {
|
||||||
when (paramName) {
|
|
||||||
"order" -> if (this.params.containsKey(paramName)) {
|
|
||||||
this.params[paramName] = this.params[paramName].append(options)
|
|
||||||
} else {
|
|
||||||
this.params[paramName] = options
|
this.params[paramName] = options
|
||||||
}
|
}
|
||||||
else -> this.params[paramName] = options
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
operator fun get(paramName: String) = this.params[paramName]
|
operator fun get(paramName: String) = this.params[paramName]
|
||||||
|
|
||||||
|
@ -70,6 +64,13 @@ class VendorBuilder : RcdbParamOptionBuilder<Int, Vendor>() {
|
||||||
super.add(param)
|
super.add(param)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun of(vendor: Vendor) = this.add(vendor)
|
||||||
|
fun vekoma() = this.add(Vendor.VEKOMA)
|
||||||
|
fun intamin() = this.add(Vendor.INTAMIN)
|
||||||
|
fun mack() = this.add(Vendor.MACK)
|
||||||
|
fun bandm() = this.add(Vendor.B_AND_M)
|
||||||
|
fun gerstlauer() = this.add(Vendor.GERSTLAUER)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun RcdbQueryParamsBuilder.vendors(body: VendorBuilder.() -> VendorBuilder): RcdbQueryParamsBuilder {
|
fun RcdbQueryParamsBuilder.vendors(body: VendorBuilder.() -> VendorBuilder): RcdbQueryParamsBuilder {
|
||||||
|
@ -78,13 +79,6 @@ fun RcdbQueryParamsBuilder.vendors(body: VendorBuilder.() -> VendorBuilder): Rcd
|
||||||
this[Vendor.staticParamName] = builder.build()
|
this[Vendor.staticParamName] = builder.build()
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
fun VendorBuilder.of(vendor: Vendor) = this.add(vendor)
|
|
||||||
fun VendorBuilder.vekoma() = this.add(Vendor.VEKOMA)
|
|
||||||
fun VendorBuilder.intamin() = this.add(Vendor.INTAMIN)
|
|
||||||
fun VendorBuilder.mack() = this.add(Vendor.MACK)
|
|
||||||
fun VendorBuilder.bandm() = this.add(Vendor.B_AND_M)
|
|
||||||
fun VendorBuilder.gerstlauer() = this.add(Vendor.GERSTLAUER)
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
//region Order
|
//region Order
|
||||||
|
@ -93,6 +87,10 @@ class OrderBuilder : RcdbParamOptionBuilder<Int, Order>() {
|
||||||
super.add(param)
|
super.add(param)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun of(order: Order) = this.add(order)
|
||||||
|
fun manufacturer() = this.add(Order.MANUFACTURER)
|
||||||
|
fun inversion() = this.add(Order.INVERSIONS)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun RcdbQueryParamsBuilder.sortBy(body: OrderBuilder.() -> OrderBuilder): RcdbQueryParamsBuilder {
|
fun RcdbQueryParamsBuilder.sortBy(body: OrderBuilder.() -> OrderBuilder): RcdbQueryParamsBuilder {
|
||||||
|
@ -100,11 +98,8 @@ fun RcdbQueryParamsBuilder.sortBy(body: OrderBuilder.() -> OrderBuilder): RcdbQu
|
||||||
builder.body()
|
builder.body()
|
||||||
this[Order.staticParamName] = builder.build()
|
this[Order.staticParamName] = builder.build()
|
||||||
return this
|
return this
|
||||||
}
|
|
||||||
|
|
||||||
fun OrderBuilder.of(order: Order) = this.add(order)
|
}
|
||||||
fun OrderBuilder.manufacturer() = this.add(Order.MANUFACTURER)
|
|
||||||
fun OrderBuilder.inversion() = this.add(Order.INVERSIONS)
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
//region Search type
|
//region Search type
|
||||||
|
|
Loading…
Reference in a new issue