Skip to content

Commit

Permalink
Add Things properties to constructor and use @JsonSetter instead. This
Browse files Browse the repository at this point in the history
should help when using these data classes in other place so the links, names properties are not skipped.
  • Loading branch information
Bram-- committed Mar 19, 2024
1 parent c040e72 commit f517a7c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 90 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using it is as simple as adding a single line to Gradle.
##### Gradle

```kotlin
implementation("org.audux.bgg:bggclient:0.6.0")
implementation("org.audux.bgg:bggclient:0.7.0")
```

##### Maven
Expand All @@ -35,7 +35,7 @@ implementation("org.audux.bgg:bggclient:0.6.0")
<dependency>
<groupId>org.audux.bgg</groupId>
<artifactId>bggclient</artifactId>
<version>0.6.0</version>
<version>0.7.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ publishing {
create<MavenPublication>("mavenJava") {
groupId = "org.audux.bgg"
artifactId = "bggclient"
version = "0.6.0"
version = "0.7.0"

pom {
name = "Unofficial JVM BGG client"
Expand Down
2 changes: 1 addition & 1 deletion examples/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dependencies {
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0")
implementation("io.coil-kt:coil-compose:2.5.0")
implementation("org.audux.bgg:bggclient:0.6.0")
implementation("org.audux.bgg:bggclient:0.7.0")

testImplementation("junit:junit:4.13.2")

Expand Down
2 changes: 1 addition & 1 deletion examples/java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repositories {
}

dependencies {
implementation("org.audux.bgg:bggclient:0.6.0")
implementation("org.audux.bgg:bggclient:0.7.0")

testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
Expand Down
2 changes: 1 addition & 1 deletion examples/paginate/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ application {
}

dependencies {
implementation("org.audux.bgg:bggclient:0.6.0")
implementation("org.audux.bgg:bggclient:0.7.0")

testImplementation("org.jetbrains.kotlin:kotlin-test")
}
Expand Down
123 changes: 39 additions & 84 deletions src/main/kotlin/org/audux/bgg/response/Things.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonRootName
import com.fasterxml.jackson.annotation.JsonSetter
import com.fasterxml.jackson.annotation.JsonSubTypes
import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
Expand Down Expand Up @@ -138,85 +139,36 @@ data class Thing(
@JsonDeserialize(using = WrappedIntDeserializer::class) val issueIndex: Int?,

/** Primary name. */
@JsonIgnore var name: String = ""
) {
@JsonIgnore var name: String = "",

/** Contains a list of polls such as the [PlayerAgePoll]. */
@JsonProperty("poll")
var polls: List<Poll> = listOf()
set(value) {
field = field + value
}
var polls: List<Poll> = listOf(),

/**
* Depending on the [type] this list may contain different links e.g. for boardgames links such
* as: `boardgamecategory`, `boardgamefamily`, `boardgamemechanic` etc. may be included. For
* `rpgitem` similar but different links are returned e.g. `rpgitemcategory` etc.
*/
@JacksonXmlProperty(localName = "link")
var links: List<Link> = listOf()
set(value) {
field = field + value
}
var links: List<Link> = listOf(),

/** Names of the thing, consisting of a primary and optionally alternatives. */
@JsonProperty("name")
var names: List<Name> = listOf()
set(value) {
field = field + value
field.forEach { if (it.type == "primary") name = it.value }
}

fun copy(
id: Int = this.id,
type: ThingType = this.type,
thumbnail: String? = this.thumbnail,
image: String? = this.image,
description: String? = this.description,
yearPublished: Int? = this.yearPublished,
datePublished: String? = this.datePublished,
releaseDate: LocalDate? = this.releaseDate,
minPlayers: Int? = this.minPlayers,
maxPlayers: Double? = this.maxPlayers,
playingTimeInMinutes: Int? = this.playingTimeInMinutes,
minPlayingTimeInMinutes: Int? = this.minPlayingTimeInMinutes,
maxPlayingTimeInMinutes: Int? = this.maxPlayingTimeInMinutes,
minAge: Int? = this.minAge,
videos: List<Video> = this.videos,
comments: Comments? = this.comments,
statistics: Statistics? = this.statistics,
listings: List<MarketplaceListing> = this.listings,
versions: List<Version> = this.versions,
seriesCode: String? = this.seriesCode,
issueIndex: Int? = this.issueIndex
) =
Thing(
id,
type,
thumbnail,
image,
description,
yearPublished,
datePublished,
releaseDate,
minPlayers,
maxPlayers,
playingTimeInMinutes,
minPlayingTimeInMinutes,
maxPlayingTimeInMinutes,
minAge,
videos,
comments,
statistics,
listings,
versions,
seriesCode,
issueIndex,
)
.also {
it.names = this.names
it.links = this.links
it.polls = this.polls
}
var names: List<Name> = listOf(),
) {
@JsonSetter("poll")
fun internalSetPolls(value: List<Poll>) {
polls = polls + value
}

@JsonSetter("link")
fun internalSetLinks(value: List<Link>) {
links = links + value
}

@JsonSetter("name")
fun internalSetNames(value: List<Name>) {
names = names + value
names.forEach { if (it.type == "primary") name = it.value }
}
}

/** Available versions of the thing e.g. Different prints of a boardgame. */
Expand Down Expand Up @@ -253,24 +205,27 @@ data class Version(

/** Weight in lbs (pounds). */
@JsonDeserialize(using = WrappedDoubleDeserializer::class) val weight: Double?,
) {
/** Names of the product, consisting of a primary and optionally alternatives. */
@JsonProperty("name")
var names: List<Name> = listOf()
set(value) {
field = field + value
field.forEach { if (it.type == "primary") name = it.value }
}

/** Primary name. */
@JsonIgnore var name = ""
@JsonIgnore var name: String = "",

/** Names of the product, consisting of a primary and optionally alternatives. */
var names: List<Name> = listOf(),

/** Additional information about this product e.g. Language, artist(s) etc. */
var links: List<Link> = listOf(),
) {
@JsonSetter("name")
fun internalSetNames(value: List<Name>) {
names = names + value
names.forEach { if (it.type == "primary") name = it.value }
}

/** Additional information about this product e.g. Language, artist(s) etc. */
@JsonProperty("link")
var links: List<Link> = listOf()
set(value) {
field = field + value
}
@JsonSetter("link")
fun internalSetLinks(value: List<Link>) {
links = links + value
}
}

/**
Expand Down

0 comments on commit f517a7c

Please sign in to comment.