Cleanup after getting rid of Mulitplatform.
This commit is contained in:
parent
6f028d6ec6
commit
c01752b5d9
13 changed files with 131 additions and 142 deletions
|
@ -8,7 +8,7 @@ fun main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generateQueryUrl() = rcdbQuery {
|
fun generateQueryUrl() = rcdbQuery {
|
||||||
searchFor(SearchType.COASTER)
|
searchType(SearchType.COASTER)
|
||||||
searchTerm("Dragon")
|
searchTerm("Dragon")
|
||||||
vendors {
|
vendors {
|
||||||
vekoma()
|
vekoma()
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings
|
package de.pheerai.rcdbquery.dataMappings
|
||||||
|
|
||||||
|
import de.pheerai.rcdbquery.dsl.RcdbQueryParamsBuilder
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
enum class Order(
|
enum class Order(
|
||||||
override val prettyName: String,
|
override val prettyName: String,
|
||||||
override val fullName: String,
|
override val fullName: String,
|
||||||
|
@ -52,3 +55,10 @@ enum class Order(
|
||||||
const val staticParamName = "order"
|
const val staticParamName = "order"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun RcdbQueryParamsBuilder.sortBy(body: OrderBuilder.() -> OrderBuilder): RcdbQueryParamsBuilder {
|
||||||
|
val builder = OrderBuilder()
|
||||||
|
builder.body()
|
||||||
|
this[Order.staticParamName] = builder.build()
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
|
@ -5,3 +5,4 @@ interface RcdbParamOption<out T> {
|
||||||
val fullName: String
|
val fullName: String
|
||||||
val paramValue: T
|
val paramValue: T
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package de.pheerai.rcdbquery.dataMappings
|
||||||
|
|
||||||
|
// TODO: Find way to only have one generic parameter
|
||||||
|
sealed class RcdbParamOptionBuilder<out U : Any, T : RcdbParamOption<U>> {
|
||||||
|
private val paramList: MutableList<T> = mutableListOf()
|
||||||
|
|
||||||
|
open fun add(param: T): RcdbParamOptionBuilder<U, T> {
|
||||||
|
paramList.add(param)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun build() = paramList.toList()
|
||||||
|
}
|
||||||
|
|
||||||
|
class VendorBuilder : RcdbParamOptionBuilder<Int, Vendor>() {
|
||||||
|
override fun add(param: Vendor): VendorBuilder {
|
||||||
|
super.add(param)
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
class OrderBuilder : RcdbParamOptionBuilder<Int, Order>() {
|
||||||
|
override fun add(param: Order): OrderBuilder {
|
||||||
|
super.add(param)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun of(order: Order) = this.add(order)
|
||||||
|
fun manufacturer() = this.add(Order.MANUFACTURER)
|
||||||
|
fun inversion() = this.add(Order.INVERSIONS)
|
||||||
|
}
|
|
@ -1,2 +0,0 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings
|
package de.pheerai.rcdbquery.dataMappings
|
||||||
|
|
||||||
|
import de.pheerai.rcdbquery.dsl.RcdbQueryParamsBuilder
|
||||||
|
|
||||||
class SearchTerm(override val paramValue: String): RcdbParamOption<String> {
|
class SearchTerm(override val paramValue: String): RcdbParamOption<String> {
|
||||||
override val prettyName = "Search Term"
|
override val prettyName = "Search Term"
|
||||||
override val fullName = "Search for elements whose name contain this term"
|
override val fullName = "Search for elements whose name contain this term"
|
||||||
|
@ -7,3 +9,17 @@ class SearchTerm(override val paramValue: String): RcdbParamOption<String> {
|
||||||
const val staticParamName = "nc"
|
const val staticParamName = "nc"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun RcdbQueryParamsBuilder.searchTerm(term: String) {
|
||||||
|
if (SearchTerm.staticParamName !in this.keys()) {
|
||||||
|
this[SearchTerm.staticParamName] = listOf(
|
||||||
|
SearchTerm(term)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
error(
|
||||||
|
"""Only one search term must ever be set
|
||||||
|
| Old term: ${this[SearchTerm.staticParamName]!![0].paramValue}
|
||||||
|
| New term: $term""".trimMargin()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings
|
package de.pheerai.rcdbquery.dataMappings
|
||||||
|
|
||||||
|
import de.pheerai.rcdbquery.dsl.RcdbQueryParamsBuilder
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
enum class SearchType(
|
enum class SearchType(
|
||||||
override val prettyName: String,
|
override val prettyName: String,
|
||||||
override val fullName: String,
|
override val fullName: String,
|
||||||
|
@ -15,3 +18,15 @@ enum class SearchType(
|
||||||
const val staticParamName = "ot"
|
const val staticParamName = "ot"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun RcdbQueryParamsBuilder.searchType(searchType: SearchType) {
|
||||||
|
if (SearchType.staticParamName !in this.keys()) {
|
||||||
|
this[SearchType.staticParamName] = listOf(searchType)
|
||||||
|
} else {
|
||||||
|
error(
|
||||||
|
"""Only one search type must ever be set
|
||||||
|
| Old type: ${this[SearchType.staticParamName]!![0].prettyName}
|
||||||
|
| New type: ${searchType.prettyName}""".trimMargin()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package de.pheerai.rcdbquery.dataMappings
|
package de.pheerai.rcdbquery.dataMappings
|
||||||
|
|
||||||
|
import de.pheerai.rcdbquery.dsl.RcdbQueryParamsBuilder
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
enum class Vendor(
|
enum class Vendor(
|
||||||
override val prettyName: String,
|
override val prettyName: String,
|
||||||
override val fullName: String,
|
override val fullName: String,
|
||||||
|
@ -223,9 +226,6 @@ enum class Vendor(
|
||||||
YEISK_PLANT_ATTRACTION("Yeisk Plant Attraction", 18040),
|
YEISK_PLANT_ATTRACTION("Yeisk Plant Attraction", 18040),
|
||||||
HEBEI_H_AND_S_AMUSEMENT_EQUIPMENT("Hebei H&S Amusement Equipment Co, LTD.", 18205),
|
HEBEI_H_AND_S_AMUSEMENT_EQUIPMENT("Hebei H&S Amusement Equipment Co, LTD.", 18205),
|
||||||
GOLDEN_DRAGON_AMUSEMENT("Golden Dragon Amusement Group", 18224),
|
GOLDEN_DRAGON_AMUSEMENT("Golden Dragon Amusement Group", 18224),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
INTAMIN("Intamin", "Intamin Amusement Rides", 6837),
|
INTAMIN("Intamin", "Intamin Amusement Rides", 6837),
|
||||||
VEKOMA("Vekoma", 6836),
|
VEKOMA("Vekoma", 6836),
|
||||||
MACK("Mack Rides", "Mack Rides GmbH & Co KG", 6856),
|
MACK("Mack Rides", "Mack Rides GmbH & Co KG", 6856),
|
||||||
|
@ -253,3 +253,10 @@ enum class Vendor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun RcdbQueryParamsBuilder.vendors(body: VendorBuilder.() -> VendorBuilder): RcdbQueryParamsBuilder {
|
||||||
|
val builder = VendorBuilder()
|
||||||
|
builder.body()
|
||||||
|
this[Vendor.staticParamName] = builder.build()
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package de.pheerai.rcdbquery.dataMappings
|
||||||
|
|
||||||
|
import de.pheerai.rcdbquery.dsl.RcdbQueryParamsBuilder
|
||||||
|
|
||||||
|
//region Unknown fields
|
||||||
|
@Suppress("unused")
|
||||||
|
@Deprecated(
|
||||||
|
"The parameter for extra columns has not yet been discovered (if it even exists). Use multiple values in the `sortBy` param instead (first values take sorting precedence)",
|
||||||
|
ReplaceWith("sortBy"), DeprecationLevel.ERROR
|
||||||
|
)
|
||||||
|
fun RcdbQueryParamsBuilder.extraColumns(orders: List<Order>): Nothing =
|
||||||
|
error("The parameter for extra columns has not yet been discovered (if it even exists). Use multiple values in the `sortBy` param instead (first values take sorting precedence)")
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
@Deprecated(
|
||||||
|
"The parameter for extra columns has not yet been discovered (if it even exists). Use multiple values in the `sortBy` param instead (first values take sorting precedence)",
|
||||||
|
ReplaceWith("sortBy"), DeprecationLevel.ERROR
|
||||||
|
)
|
||||||
|
fun RcdbQueryParamsBuilder.extraColumns(vararg orders: Order): Nothing =
|
||||||
|
error("The parameter for extra columns has not yet been discovered (if it even exists). Use multiple values in the `sortBy` param instead (first values take sorting precedence)")
|
|
@ -1,19 +1,25 @@
|
||||||
package de.pheerai.rcdbquery.dsl
|
package de.pheerai.rcdbquery.dsl
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dataMappings.*
|
import de.pheerai.rcdbquery.dataMappings.RcdbParamOption
|
||||||
|
import de.pheerai.rcdbquery.dataMappings.SearchType
|
||||||
|
|
||||||
inline class RcdbQueryParams(val params: Map<String, List<String>>)
|
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()
|
||||||
|
|
||||||
// TODO: Validate that search type is set
|
/**
|
||||||
fun build() = RcdbQueryParams(
|
* Creates the Query Params from this builder.
|
||||||
params
|
* If no Search type has been set, this will default to "Coaster"
|
||||||
|
*/
|
||||||
|
fun build() = params.apply {
|
||||||
|
putIfAbsent(SearchType.staticParamName, listOf(SearchType.COASTER))
|
||||||
|
}
|
||||||
.filter { it.value.isNotEmpty() }
|
.filter { it.value.isNotEmpty() }
|
||||||
.mapValues { e -> e.value.map { o -> o.paramValue.toString() } }
|
.mapValues { e -> e.value.map { o -> o.paramValue.toString() } }
|
||||||
)
|
.let { RcdbQueryParams(it) }
|
||||||
|
|
||||||
|
|
||||||
operator fun set(paramName: String, options: List<RcdbParamOption<Any>>) {
|
operator fun set(paramName: String, options: List<RcdbParamOption<Any>>) {
|
||||||
this.params[paramName] = options
|
this.params[paramName] = options
|
||||||
|
@ -21,9 +27,6 @@ class RcdbQueryParamsBuilder {
|
||||||
|
|
||||||
operator fun get(paramName: String) = this.params[paramName]
|
operator fun get(paramName: String) = this.params[paramName]
|
||||||
|
|
||||||
private fun List<RcdbParamOption<Any>>?.append(options: List<RcdbParamOption<Any>>) =
|
|
||||||
this?.toMutableList()?.also { it.addAll(options) } ?: options
|
|
||||||
|
|
||||||
fun keys() = this.params.keys.toSet()
|
fun keys() = this.params.keys.toSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,110 +43,12 @@ data class RcdbUrlQuery(val baseUrl: String, val params: RcdbQueryParams) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builder for the parameters only (mainly because it might be possilbe in the future to have an API with a POST search object?
|
||||||
|
*/
|
||||||
fun rcdbQueryParams(body: RcdbQueryParamsBuilder.() -> RcdbQueryParamsBuilder): RcdbQueryParams {
|
fun rcdbQueryParams(body: RcdbQueryParamsBuilder.() -> RcdbQueryParamsBuilder): RcdbQueryParams {
|
||||||
val builder = RcdbQueryParamsBuilder()
|
val builder = RcdbQueryParamsBuilder()
|
||||||
builder.body()
|
builder.body()
|
||||||
return builder.build()
|
return builder.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Find way to only have one generic parameter
|
|
||||||
sealed class RcdbParamOptionBuilder<out U : Any, T : RcdbParamOption<U>> {
|
|
||||||
private val paramList: MutableList<T> = mutableListOf()
|
|
||||||
|
|
||||||
open fun add(param: T): RcdbParamOptionBuilder<U, T> {
|
|
||||||
paramList.add(param)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
fun build() = paramList.toList()
|
|
||||||
}
|
|
||||||
|
|
||||||
//region Vendors
|
|
||||||
class VendorBuilder : RcdbParamOptionBuilder<Int, Vendor>() {
|
|
||||||
override fun add(param: Vendor): VendorBuilder {
|
|
||||||
super.add(param)
|
|
||||||
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 {
|
|
||||||
val builder = VendorBuilder()
|
|
||||||
builder.body()
|
|
||||||
this[Vendor.staticParamName] = builder.build()
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
//endregion
|
|
||||||
|
|
||||||
//region Order
|
|
||||||
class OrderBuilder : RcdbParamOptionBuilder<Int, Order>() {
|
|
||||||
override fun add(param: Order): OrderBuilder {
|
|
||||||
super.add(param)
|
|
||||||
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 {
|
|
||||||
val builder = OrderBuilder()
|
|
||||||
builder.body()
|
|
||||||
this[Order.staticParamName] = builder.build()
|
|
||||||
return this
|
|
||||||
|
|
||||||
}
|
|
||||||
//endregion
|
|
||||||
|
|
||||||
//region Search type
|
|
||||||
fun RcdbQueryParamsBuilder.searchFor(searchType: SearchType) {
|
|
||||||
if (SearchType.staticParamName !in this.keys()) {
|
|
||||||
this[SearchType.staticParamName] = listOf(searchType)
|
|
||||||
} else {
|
|
||||||
error(
|
|
||||||
"""Only one search type must ever be set
|
|
||||||
| Old type: ${this[SearchType.staticParamName]!![0].prettyName}
|
|
||||||
| New type: ${searchType.prettyName}""".trimMargin()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//endregion
|
|
||||||
|
|
||||||
//region Search Term
|
|
||||||
fun RcdbQueryParamsBuilder.searchTerm(term: String) {
|
|
||||||
if (SearchTerm.staticParamName !in this.keys()) {
|
|
||||||
this[SearchTerm.staticParamName] = listOf(SearchTerm(term))
|
|
||||||
} else {
|
|
||||||
error(
|
|
||||||
"""Only one search term must ever be set
|
|
||||||
| Old term: ${this[SearchTerm.staticParamName]!![0].paramValue}
|
|
||||||
| New term: $term""".trimMargin()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//endregion
|
|
||||||
|
|
||||||
//region Unknown fields
|
|
||||||
@Suppress("unused")
|
|
||||||
@Deprecated(
|
|
||||||
"The parameter for extra columns has not yet been discovered (if it even exists). Use multiple values in the `sortBy` param instead (first values take sorting precedence)",
|
|
||||||
ReplaceWith("sortBy"), DeprecationLevel.ERROR
|
|
||||||
)
|
|
||||||
fun RcdbQueryParamsBuilder.extraColumns(orders: List<Order>): Nothing =
|
|
||||||
error("The parameter for extra columns has not yet been discovered (if it even exists). Use multiple values in the `sortBy` param instead (first values take sorting precedence)")
|
|
||||||
|
|
||||||
@Suppress("unused")
|
|
||||||
@Deprecated(
|
|
||||||
"The parameter for extra columns has not yet been discovered (if it even exists). Use multiple values in the `sortBy` param instead (first values take sorting precedence)",
|
|
||||||
ReplaceWith("sortBy"), DeprecationLevel.ERROR
|
|
||||||
)
|
|
||||||
fun RcdbQueryParamsBuilder.extraColumns(vararg orders: Order): Nothing =
|
|
||||||
error("The parameter for extra columns has not yet been discovered (if it even exists). Use multiple values in the `sortBy` param instead (first values take sorting precedence)")
|
|
||||||
//endregion
|
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
package de.pheerai.rcdbquery
|
|
||||||
|
|
||||||
import kotlin.test.Test
|
|
||||||
import kotlin.test.assertTrue
|
|
||||||
|
|
||||||
class SampleTests {
|
|
||||||
@Test
|
|
||||||
fun testMe() {
|
|
||||||
assertTrue(true)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
package de.pheerai.rcdbquery
|
|
||||||
|
|
||||||
import kotlin.test.Test
|
|
||||||
import kotlin.test.assertTrue
|
|
||||||
|
|
||||||
class SampleTestsJVM {
|
|
||||||
@Test
|
|
||||||
fun testHello() {
|
|
||||||
assertTrue(true)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +1,8 @@
|
||||||
package de.pheerai.rcdbquery.dsl
|
package de.pheerai.rcdbquery.dsl
|
||||||
|
|
||||||
import de.pheerai.rcdbquery.dataMappings.Order
|
|
||||||
import de.pheerai.rcdbquery.dataMappings.Vendor
|
import de.pheerai.rcdbquery.dataMappings.Vendor
|
||||||
|
import de.pheerai.rcdbquery.dataMappings.sortBy
|
||||||
|
import de.pheerai.rcdbquery.dataMappings.vendors
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
@ -9,7 +10,7 @@ class RcdbQueryDslTest {
|
||||||
@Test
|
@Test
|
||||||
fun testQueryParamBuilder() {
|
fun testQueryParamBuilder() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"https://www.rcdb.com/r.htm?mk=6836,6856,6905&order=24,30",
|
"https://www.rcdb.com/r.htm?mk=6836,6856,6905&order=24,30&ot=2",
|
||||||
rcdbQuery {
|
rcdbQuery {
|
||||||
vendors {
|
vendors {
|
||||||
vekoma()
|
vekoma()
|
||||||
|
|
Loading…
Reference in a new issue