Skip to content

Commit

Permalink
Get rid of WrappedValue<>. TODO: Get rid of WrappedLocalDateTime &
Browse files Browse the repository at this point in the history
WrappedSubType
  • Loading branch information
Bram-- committed Feb 22, 2024
1 parent 093caa3 commit bc12719
Show file tree
Hide file tree
Showing 29 changed files with 268 additions and 253 deletions.
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ junit5 = "5.8.1"
kermit = "2.0.2"
ktfmt-gradle = "0.15.1"
ktor = "2.3.+"
org-jetbrains-kotlin-jvm = "1.9.10"
org-jetbrains-kotlin-jvm = "1.9.22"
org-jetbrains-kotlin-jdk8 = "1.7.3"
serialization = "1.6.1"
slf4j = "1.7.36"
Expand All @@ -32,3 +32,4 @@ truth = { module = "com.google.truth:truth", version.ref = "truth" }
[plugins]
org-jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "org-jetbrains-kotlin-jvm" }
ktfmt-gradle = { id = "com.ncorti.ktfmt.gradle", version.ref = "ktfmt-gradle" }

10 changes: 5 additions & 5 deletions src/main/kotlin/org/audux/bgg/BggClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ object BggClient {
* @param comments whether to include the comments in the response or not.
*/
@JvmStatic
fun geekList(id: Number, comments: Inclusion? = null) =
fun geekList(id: Int, comments: Inclusion? = null) =
InternalBggClient(engine).geekList(id, comments)

/**
Expand All @@ -268,7 +268,7 @@ object BggClient {
* @param page The page of the members list to return. page size is 25.
*/
@JvmStatic
fun guilds(id: Number, members: Inclusion? = null, sort: String? = null, page: Number? = null) =
fun guilds(id: Int, members: Inclusion? = null, sort: String? = null, page: Int? = null) =
InternalBggClient(engine).guilds(id, members, sort, page)

/**
Expand Down Expand Up @@ -297,12 +297,12 @@ object BggClient {
@JvmStatic
fun plays(
username: String,
id: Number? = null,
id: Int? = null,
type: PlayThingType? = null,
minDate: LocalDate? = null,
maxDate: LocalDate? = null,
subType: SubType? = null,
page: Number? = null,
page: Int? = null,
) = InternalBggClient(engine).plays(username, id, type, minDate, maxDate, subType, page)

/**
Expand Down Expand Up @@ -416,7 +416,7 @@ object BggClient {
top: Inclusion? = null,
hot: Inclusion? = null,
domain: Domains? = null,
page: Number? = null,
page: Int? = null,
) = InternalBggClient(engine).user(name, buddies, guilds, top, hot, domain, page)

/** Logging level Severity for the BGGClient logging. */
Expand Down
34 changes: 18 additions & 16 deletions src/main/kotlin/org/audux/bgg/common/Types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
*/
package org.audux.bgg.common

import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import org.audux.bgg.response.WrappedValue
import org.audux.bgg.response.WrappedDoubleDeserializer
import org.audux.bgg.response.WrappedIntDeserializer

/**
* The different kind/type of things the API may return such as a board game or expansion etc.
Expand Down Expand Up @@ -160,41 +162,41 @@ data class Ratings(
/** A user rating if available. */
@JacksonXmlProperty(isAttribute = true) val value: String? = null,

/** Number of user ratings. */
val usersRated: WrappedValue<Number>? = null,
/** Int of user ratings. */
@JsonDeserialize(using = WrappedIntDeserializer::class) val usersRated: Int? = null,

/** The average rating. */
val average: WrappedValue<Number>? = null,
@JsonDeserialize(using = WrappedDoubleDeserializer::class) val average: Double? = null,

/** Standard deviation. */
val stdDev: WrappedValue<Number>? = null,
@JsonDeserialize(using = WrappedDoubleDeserializer::class) val stdDev: Double? = null,

/** Bayesian average rating. */
val bayesAverage: WrappedValue<Number>? = null,
@JsonDeserialize(using = WrappedDoubleDeserializer::class) val bayesAverage: Double? = null,

/** The median rating. */
val median: WrappedValue<Number>? = null,
@JsonDeserialize(using = WrappedDoubleDeserializer::class) val median: Double? = null,

/** Total number of users owning this thing. */
val owned: WrappedValue<Number>? = null,
@JsonDeserialize(using = WrappedIntDeserializer::class) val owned: Int? = null,

/** Total number of users looking to trade away this thing. */
val trading: WrappedValue<Number>? = null,
@JsonDeserialize(using = WrappedIntDeserializer::class) val trading: Int? = null,

/** Total number of users wanting this thing. */
val wanting: WrappedValue<Number>? = null,
@JsonDeserialize(using = WrappedIntDeserializer::class) val wanting: Int? = null,

/** Total number of users wishing for this thing. */
val wishing: WrappedValue<Number>? = null,
@JsonDeserialize(using = WrappedIntDeserializer::class) val wishing: Int? = null,

/** Total number of comments left on the thing. */
val numComments: WrappedValue<Number>? = null,
@JsonDeserialize(using = WrappedIntDeserializer::class) val numComments: Int? = null,

/** Number of weight ratings. */
val numWeights: WrappedValue<Number>? = null,
/** Int of weight ratings. */
@JsonDeserialize(using = WrappedIntDeserializer::class) val numWeights: Int? = null,

/** Average weight rating. */
val averageWeight: WrappedValue<Number>? = null,
@JsonDeserialize(using = WrappedDoubleDeserializer::class) val averageWeight: Double? = null,

/**
* A thing can be listed on different rankings. For example a board game could both be ranked as
Expand All @@ -206,7 +208,7 @@ data class Ratings(
/** Represents a rank in a single ranking (Consisting of type & name). */
data class Rank(
/** Unique of the ranking type - ID and type+name should always be a coupled. */
@JacksonXmlProperty(isAttribute = true) val id: Number,
@JacksonXmlProperty(isAttribute = true) val id: Int,

/** Type of ranking e.g. the thing's main type or sub type */
@JacksonXmlProperty(isAttribute = true) val type: String? = null,
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/audux/bgg/request/GeekList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import org.audux.bgg.response.Response
* @param id the unique ID for the geek list to retrieve
* @param comments whether to include the comments in the response or not.
*/
internal fun InternalBggClient.geekList(id: Number, comments: Inclusion? = null) = request {
internal fun InternalBggClient.geekList(id: Int, comments: Inclusion? = null) = request {
client()
.get(XML1_API_URL) {
url {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/org/audux/bgg/request/Guilds.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import org.audux.bgg.response.Response
* @param page The page of the members list to return. page size is 25.
*/
internal fun InternalBggClient.guilds(
id: Number,
id: Int,
members: Inclusion? = null,
sort: String? = null,
page: Number? = null
page: Int? = null
) =
PaginatedGuilds(this, members) {
client()
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/org/audux/bgg/request/PaginatedRequests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ internal constructor(
guild.data.members?.let { guildMembers ->
allGuildMembers.addAllAbsent(guildMembers.members)

// Number of pages to paginate: (CurrentPage + 1)..lastPage.
// Int of pages to paginate: (CurrentPage + 1)..lastPage.
val currentPage = guildMembers.page.toInt()
lastPage = min(ceil(guildMembers.count.toDouble() / PAGE_SIZE).toInt(), toPage)

Expand Down Expand Up @@ -200,7 +200,7 @@ internal constructor(
if (plays.data == null) return@Request plays
val allPlays = CopyOnWriteArrayList<Play>().apply { addAllAbsent(plays.data.plays) }

// Number of pages to paginate: (CurrentPage + 1)..lastPage.
// Int of pages to paginate: (CurrentPage + 1)..lastPage.
val currentPage = plays.data.page.toInt()
val lastPage = min(ceil(plays.data.total.toDouble() / PAGE_SIZE).toInt(), toPage)

Expand Down Expand Up @@ -252,7 +252,7 @@ internal constructor(
)
}

// Number of pages to paginate: (CurrentPage + 1)..lastPage.
// Int of pages to paginate: (CurrentPage + 1)..lastPage.
val maxComments =
things.data.things.maxOfOrNull { it.comments?.totalItems ?: 0 } ?: 0
val lastPage = min(toPage, ceil(maxComments.toDouble() / pageSize).toInt())
Expand Down Expand Up @@ -341,7 +341,7 @@ internal constructor(
user.data.buddies?.let { addAllAbsent(it.buddies) }
}

// Number of pages to paginate.
// Int of pages to paginate.
val currentPage =
user.data.guilds?.page?.toInt() ?: user.data.buddies?.page?.toInt() ?: 1

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/org/audux/bgg/request/Plays.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ import org.audux.bgg.response.Response
*/
internal fun InternalBggClient.plays(
username: String,
id: Number? = null,
id: Int? = null,
type: PlayThingType? = null,
minDate: LocalDate? = null,
maxDate: LocalDate? = null,
subType: SubType? = null,
page: Number? = null,
page: Int? = null,
) =
PaginatedPlays(this) {
val formatter = DateTimeFormatter.ofPattern(Constants.REQUEST_DATE_FORMAT)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/audux/bgg/request/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal fun InternalBggClient.user(
top: Inclusion? = null,
hot: Inclusion? = null,
domain: Domains? = null,
page: Number? = null,
page: Int? = null,
) =
PaginatedUser(this, buddies, guilds) {
client()
Expand Down
26 changes: 13 additions & 13 deletions src/main/kotlin/org/audux/bgg/response/Collection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ data class Collection(
@JacksonXmlProperty(isAttribute = true) val termsOfUse: String,

/** Total number of items in the resulting collection. */
@JacksonXmlProperty(isAttribute = true) val totalItems: Number,
@JacksonXmlProperty(isAttribute = true) val totalItems: Int,

/** Date and time when the collection was 'published' i.e. created by the BGG API. */
@JacksonXmlProperty(isAttribute = true, localName = "pubdate") val publishDate: String,
Expand All @@ -41,8 +41,8 @@ data class Collection(
/** An item in the collection e.g. a board game, rpg etc. */
@JsonIgnoreProperties("objecttype")
data class CollectionItem(
@JacksonXmlProperty(isAttribute = true, localName = "collid") val collectionId: Number,
@JacksonXmlProperty(isAttribute = true) val objectId: Number,
@JacksonXmlProperty(isAttribute = true, localName = "collid") val collectionId: Int,
@JacksonXmlProperty(isAttribute = true) val objectId: Int,

/** Rank in the returned list. */
@JacksonXmlProperty(isAttribute = true, localName = "subtype")
Expand All @@ -56,7 +56,7 @@ data class CollectionItem(
val originalName: String? = null,

/** Optional year of publishing. */
val yearPublished: Number? = null,
val yearPublished: Int? = null,

/** Web URL to the thumbnail image. */
@JsonDeserialize(using = TrimmedStringDeserializer::class) val thumbnail: String? = null,
Expand All @@ -67,8 +67,8 @@ data class CollectionItem(
/** Status of the collection item e.g. whether the user owns it, previously owns it etc. */
val status: Status? = null,

/** Number of plays the user had with this item. */
val numPlays: Number? = null,
/** Int of plays the user had with this item. */
val numPlays: Int? = null,

/** Comment owner/user left on the collection item. */
val comment: String? = null,
Expand Down Expand Up @@ -118,7 +118,7 @@ data class Status(
val wishlist: Boolean = false,

/** Whether item is currently owned. */
@JacksonXmlProperty(isAttribute = true) val wishlistPriority: Number? = null,
@JacksonXmlProperty(isAttribute = true) val wishlistPriority: Int? = null,

/** Whether item is currently owned. */
@JsonDeserialize(using = NumberToBooleanDeserializer::class)
Expand All @@ -134,22 +134,22 @@ data class Status(
/** Statistics for a collection item. */
data class CollectionStatistics(
/** Minimum number of players. */
@JacksonXmlProperty(localName = "minplayers") val minimumPlayers: Number?,
@JacksonXmlProperty(localName = "minplayers") val minimumPlayers: Int?,

/** Maximum number of players. */
@JacksonXmlProperty(localName = "maxplayers") val maximumPlayers: Number?,
@JacksonXmlProperty(localName = "maxplayers") val maximumPlayers: Int?,

/** Minimum play time in minutes. */
@JacksonXmlProperty(localName = "minplaytime") val minimumPlayTime: Number?,
@JacksonXmlProperty(localName = "minplaytime") val minimumPlayTime: Int?,

/** Maximum play time in minutes. */
@JacksonXmlProperty(localName = "maxplaytime") val maximumPlayTime: Number?,
@JacksonXmlProperty(localName = "maxplaytime") val maximumPlayTime: Int?,

/** Average playing time. */
@JacksonXmlProperty(localName = "playingtime") val playingTime: Number?,
@JacksonXmlProperty(localName = "playingtime") val playingTime: Int?,

/** How often this item is seen in collections. */
val numOwned: Number?,
val numOwned: Int?,

/** The set of ratings */
@JacksonXmlProperty(localName = "rating") val ratings: Ratings,
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/org/audux/bgg/response/Forum.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ data class Forum(
val title: String,

/** The number of threads that are active/created in the forum. */
@JacksonXmlProperty(isAttribute = true) val numThreads: Number,
@JacksonXmlProperty(isAttribute = true) val numThreads: Int,

/** Total number of posts in the forum spread over the threads. */
@JacksonXmlProperty(isAttribute = true) val numPosts: Number,
@JacksonXmlProperty(isAttribute = true) val numPosts: Int,

/** The date and time a post was last made. */
@JsonFormat(pattern = "E, dd MMM yyyy HH:mm:ss Z")
Expand Down Expand Up @@ -75,7 +75,7 @@ data class ThreadSummary(
val author: String,

/** The number of posts/articles in this thread. */
@JacksonXmlProperty(isAttribute = true) val numArticles: Number,
@JacksonXmlProperty(isAttribute = true) val numArticles: Int,

/** The date and time this thread was created. */
@JsonFormat(pattern = "E, dd MMM yyyy HH:mm:ss Z")
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/org/audux/bgg/response/ForumList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ data class ForumSummary(
val description: String,

/** The number of threads that are active/created in the forum. */
@JacksonXmlProperty(isAttribute = true) val numThreads: Number,
@JacksonXmlProperty(isAttribute = true) val numThreads: Int,

/** Total number of posts in the forum spread over the threads. */
@JacksonXmlProperty(isAttribute = true) val numPosts: Number,
@JacksonXmlProperty(isAttribute = true) val numPosts: Int,

/** The date and time a post was last made. */
@JsonFormat(pattern = "E, dd MMM yyyy HH:mm:ss Z")
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/org/audux/bgg/response/GeekList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ data class GeekList(
@JacksonXmlProperty(isAttribute = true) val termsOfUse: String,

/** Unique ID for the Geek list - same as in the request. */
@JacksonXmlProperty(isAttribute = true) val id: Number,
@JacksonXmlProperty(isAttribute = true) val id: Int,

/** The date and time the geek list was posted/published. */
@JsonFormat(pattern = Constants.REQUEST_XML1_DATE_TIME_FORMAT) val postDate: LocalDateTime,
Expand All @@ -40,10 +40,10 @@ data class GeekList(
@JsonFormat(pattern = Constants.REQUEST_XML1_DATE_TIME_FORMAT) val editDate: LocalDateTime,

/** The number of thumbs up/likes the geek list received. */
val thumbs: Number,
val thumbs: Int,

/** The of number of items in the geek list. */
val numItems: Number,
val numItems: Int,

/** The username of the user that published this geek list. */
val username: String,
Expand Down Expand Up @@ -86,7 +86,7 @@ data class GeekListComment(
val editDate: LocalDateTime,

/** The number of thumbs up/likes on this item. */
@JacksonXmlProperty(isAttribute = true) val thumbs: Number,
@JacksonXmlProperty(isAttribute = true) val thumbs: Int,
) {
/** The actual comment the user posted. */
// As this is the innerText of the XML element, using this in a (Kotlin) data class does
Expand Down Expand Up @@ -132,13 +132,13 @@ data class GeekListItem(
val editDate: LocalDateTime,

/** The number of thumbs up/likes this item has received. */
@JacksonXmlProperty(isAttribute = true) val thumbs: Number,
@JacksonXmlProperty(isAttribute = true) val thumbs: Int,

/**
* The Image ID this item, these can be formatted as an URL as follows: `*
* https://boardgamegeek.com/image/$imageId to display/look up the image.
*/
@JacksonXmlProperty(isAttribute = true) val imageId: Number? = null,
@JacksonXmlProperty(isAttribute = true) val imageId: Int? = null,
@JsonDeserialize(using = TrimmedStringDeserializer::class) val body: String,
) {
/** The list of comments of this list. */
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/org/audux/bgg/response/Guild.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import java.time.LocalDateTime
data class Guild(
/** Terms of use of the BGG API. */
@JacksonXmlProperty(isAttribute = true) val termsOfUse: String,
@JacksonXmlProperty(isAttribute = true) val id: Number,
@JacksonXmlProperty(isAttribute = true) val id: Int,
@JacksonXmlProperty(isAttribute = true) val name: String?,
@JsonFormat(pattern = "E, dd MMM yyyy HH:mm:ss Z")
@JacksonXmlProperty(isAttribute = true, localName = "created")
Expand All @@ -47,8 +47,8 @@ data class Location(
)

data class GuildMembers(
@JacksonXmlProperty(isAttribute = true) val count: Number,
@JacksonXmlProperty(isAttribute = true) val page: Number,
@JacksonXmlProperty(isAttribute = true) val count: Int,
@JacksonXmlProperty(isAttribute = true) val page: Int,
@JsonProperty("member") val members: List<GuildMember>,
)

Expand Down
Loading

0 comments on commit bc12719

Please sign in to comment.