Skip to content

Commit

Permalink
Device enum to uppercase
Browse files Browse the repository at this point in the history
  • Loading branch information
anonvt committed Aug 19, 2024
1 parent 75d7997 commit cd0327e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sealed class BannerConfig private constructor() {
data class LandingPage(
val slotId: String,
val ids: List<String>,
val device: Device = Device.mobile,
val device: Device = Device.MOBILE,
val geoTargeting: String? = null
) : BannerConfig()

Expand All @@ -33,7 +33,7 @@ sealed class BannerConfig private constructor() {
data class CategorySingle(
val slotId: String,
val category: String,
val device: Device = Device.mobile,
val device: Device = Device.MOBILE,
val geoTargeting: String? = null
) : BannerConfig()

Expand All @@ -48,7 +48,7 @@ sealed class BannerConfig private constructor() {
data class CategoryMultiple(
val slotId: String,
val categories: List<String>,
val device: Device = Device.mobile,
val device: Device = Device.MOBILE,
val geoTargeting: String? = null,
) : BannerConfig()

Expand All @@ -63,7 +63,7 @@ sealed class BannerConfig private constructor() {
data class CategoryDisjunctions(
val slotId: String,
val disjunctions: List<List<String>>,
val device: Device = Device.mobile,
val device: Device = Device.MOBILE,
val geoTargeting: String? = null,
) : BannerConfig()

Expand All @@ -78,7 +78,7 @@ sealed class BannerConfig private constructor() {
data class Keyword(
val slotId: String,
val keyword: String,
val device: Device = Device.mobile,
val device: Device = Device.MOBILE,
val geoTargeting: String? = null,
) : BannerConfig()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.topsort.analytics.model.auctions

import org.json.JSONObject

data class Auction private constructor(
val type: String,
val slots: Int,
Expand All @@ -11,6 +13,36 @@ data class Auction private constructor(
val device: Device? = null,
) {

fun toJsonObject(): JSONObject {
val builder = JSONObject()

with(builder) {
put("type", type)
put("slots", slots)
if (products != null) {
put("products", products)
}
if (category != null) {
put("category", category)
}
if (searchQuery != null) {
put("searchQuery", searchQuery)
}
if (geoTargeting != null) {
put("geoTargeting", geoTargeting)
}
if (slotId != null) {
put("slotId", slotId)
}
if (device != null) {
put("device", device.name.lowercase())
}
}

return builder

}

object Factory {

@JvmOverloads
Expand Down Expand Up @@ -88,7 +120,7 @@ data class Auction private constructor(
slots: Int,
slotId: String,
ids: List<String>,
device: Device = Device.mobile,
device: Device = Device.MOBILE,
geoTargeting: String? = null,
): Auction {
return Auction(
Expand All @@ -106,7 +138,7 @@ data class Auction private constructor(
slots: Int,
slotId: String,
category: String,
device: Device = Device.mobile,
device: Device = Device.MOBILE,
geoTargeting: String? = null,
): Auction {
return Auction(
Expand All @@ -124,7 +156,7 @@ data class Auction private constructor(
slots: Int,
slotId: String,
categories: List<String>,
device: Device = Device.mobile,
device: Device = Device.MOBILE,
geoTargeting: String? = null,
): Auction {
return Auction(
Expand All @@ -142,7 +174,7 @@ data class Auction private constructor(
slots: Int,
slotId: String,
disjunctions: List<List<String>>,
device: Device = Device.mobile,
device: Device = Device.MOBILE,
geoTargeting: String? = null,
): Auction {
return Auction(
Expand All @@ -160,7 +192,7 @@ data class Auction private constructor(
slots: Int,
slotId: String,
keyword: String,
device: Device = Device.mobile,
device: Device = Device.MOBILE,
geoTargeting: String? = null,
): Auction {
return Auction(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.topsort.analytics.model.auctions

import org.json.JSONArray
import org.json.JSONObject

data class AuctionRequest(
val auctions : List<Auction>
){
fun toJsonObject(): JSONObject {
return JSONObject().put("auctions", auctions)
val array = JSONArray()
auctions.indices.map {
array.put(it, auctions[it].toJsonObject())
}
return JSONObject().put("auctions", array)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.topsort.analytics.model.auctions

@Suppress("EnumNaming")
enum class Device {
desktop,
mobile
}
DESKTOP,
MOBILE,
}

0 comments on commit cd0327e

Please sign in to comment.