Skip to content

Commit

Permalink
Make all responses @serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram-- committed Mar 23, 2024
1 parent bde59f7 commit bee885c
Show file tree
Hide file tree
Showing 28 changed files with 244 additions and 15 deletions.
6 changes: 6 additions & 0 deletions src/main/kotlin/org/audux/bgg/response/Collection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import com.fasterxml.jackson.annotation.JsonRootName
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import java.time.LocalDateTime
import kotlinx.serialization.Serializable
import org.audux.bgg.common.Ratings
import org.audux.bgg.common.ThingType

/**
* Response wrapper for the user's Collection. These contain lists of items like board games wrapped
* in [CollectionItem].
*/
@Serializable
@JsonRootName("items")
data class Collection(
/** Terms of use of the BGG API. */
Expand All @@ -43,6 +45,7 @@ data class Collection(

/** An item in the collection e.g. a board game, rpg etc. */
@JsonIgnoreProperties("objecttype")
@Serializable
data class CollectionItem(
@JacksonXmlProperty(isAttribute = true, localName = "collid") val collectionId: Int,
@JacksonXmlProperty(isAttribute = true) val objectId: Int,
Expand Down Expand Up @@ -84,6 +87,7 @@ data class CollectionItem(
)

/** The status of collection item e.g. whether the user owns it, wants it etc. */
@Serializable
data class Status(
/** Whether item is currently owned. */
@JsonDeserialize(using = NumberToBooleanDeserializer::class)
Expand Down Expand Up @@ -131,10 +135,12 @@ data class Status(
/** Whether item is currently owned. */
@JacksonXmlProperty(isAttribute = true)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Serializable(with = LocalDateSerializer::class)
val lastModified: LocalDateTime? = null,
)

/** Statistics for a collection item. */
@Serializable
data class CollectionStatistics(
/** Minimum number of players. */
@JacksonXmlProperty(localName = "minplayers") val minimumPlayers: Int?,
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/org/audux/bgg/response/Family.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ package org.audux.bgg.response
import com.fasterxml.jackson.annotation.JsonRootName
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import kotlinx.serialization.Serializable
import org.audux.bgg.common.FamilyType
import org.audux.bgg.common.Link
import org.audux.bgg.common.Name

/** Response wrapper for Family items, e.g. games having a related theme or gameplay. */
@JsonRootName("items")
@Serializable
data class Family(
/** Terms of use of the BGG API. */
@JacksonXmlProperty(isAttribute = true) val termsOfUse: String,
Expand All @@ -31,6 +33,7 @@ data class Family(
)

/** The actual Family item e.g. a `boardgamefamily`, rpg etc. */
@Serializable
data class FamilyItem(
/** Unique ID that can be used to look up more information using the thing endpoint. */
@JacksonXmlProperty(isAttribute = true) val id: Int,
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/org/audux/bgg/response/Forum.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import java.time.LocalDateTime
import kotlinx.serialization.Serializable

/**
* Encapsulates a forum containing a list of thread summaries - these can be retrieve using in
* [org.audux.bgg.request.thread] endpoint.
*/
@JsonRootName("forum")
@Serializable
data class Forum(
/** Terms of use of the BGG API. */
@JacksonXmlProperty(isAttribute = true) val termsOfUse: String,
Expand All @@ -51,6 +53,7 @@ data class Forum(
/** The date and time a post was last made. */
@JsonFormat(pattern = "E, dd MMM yyyy HH:mm:ss Z")
@JacksonXmlProperty(isAttribute = true)
@Serializable(with = LocalDateTimeSerializer::class)
val lastPostDate: LocalDateTime?,

/** The list of threads in this forum. */
Expand All @@ -60,6 +63,7 @@ data class Forum(
/**
* Summary of a thread in the forum, contains some stats and aggregated data but no articles/posts.
*/
@Serializable
data class ThreadSummary(
/** Unique ID that can be used to look up more information using the thread endpoint. */
@JacksonXmlProperty(isAttribute = true) val id: Int,
Expand All @@ -80,10 +84,12 @@ data class ThreadSummary(
/** The date and time this thread was created. */
@JsonFormat(pattern = "E, dd MMM yyyy HH:mm:ss Z")
@JacksonXmlProperty(isAttribute = true)
@Serializable(with = LocalDateTimeSerializer::class)
val postDate: LocalDateTime?,

/** The date and time a post was last made in this thread. */
@JsonFormat(pattern = "E, dd MMM yyyy HH:mm:ss Z")
@JacksonXmlProperty(isAttribute = true)
@Serializable(with = LocalDateTimeSerializer::class)
val lastPostDate: LocalDateTime?,
)
4 changes: 4 additions & 0 deletions src/main/kotlin/org/audux/bgg/response/ForumList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import com.fasterxml.jackson.annotation.JsonRootName
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import java.time.LocalDateTime
import kotlinx.serialization.Serializable
import org.audux.bgg.common.ForumListType

/** Response wrapper for a list of forums for the given id/thing pair. */
@JsonRootName("forums")
@Serializable
data class ForumList(
/** Terms of use of the BGG API. */
@JacksonXmlProperty(isAttribute = true) val termsOfUse: String,
Expand All @@ -42,6 +44,7 @@ data class ForumList(
* Encapsulates the summary of a forum - these can be retrieve using the
* [org.audux.bgg.request.forum] endpoint.
*/
@Serializable
data class ForumSummary(
/** Unique ID that can be used to look up more information using the forum endpoint. */
@JacksonXmlProperty(isAttribute = true) val id: Int,
Expand Down Expand Up @@ -73,5 +76,6 @@ data class ForumSummary(
/** The date and time a post was last made. */
@JsonFormat(pattern = "E, dd MMM yyyy HH:mm:ss Z")
@JacksonXmlProperty(isAttribute = true)
@Serializable(with = LocalDateSerializer::class)
val lastPostDate: LocalDateTime?,
)
31 changes: 23 additions & 8 deletions src/main/kotlin/org/audux/bgg/response/GeekList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonRootName
import com.fasterxml.jackson.annotation.JsonSetter
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText
import java.time.LocalDateTime
import kotlinx.serialization.Serializable
import org.audux.bgg.common.Constants

/** Encapsulates a geek list including its items and optionally its comments. */
@JsonRootName("geeklist")
@JsonIgnoreProperties("postdate_timestamp", "editdate_timestamp")
@Serializable
data class GeekList(
/** Terms of use of the BGG API. */
@JacksonXmlProperty(isAttribute = true) val termsOfUse: String,
Expand All @@ -34,10 +37,14 @@ data class GeekList(
@JacksonXmlProperty(isAttribute = true) val id: Int,

/** The date and time the geek list was posted/published. */
@JsonFormat(pattern = Constants.DAY_FIRST_DATE_TIME_FORMAT) val postDate: LocalDateTime,
@JsonFormat(pattern = Constants.DAY_FIRST_DATE_TIME_FORMAT)
@Serializable(with = LocalDateTimeSerializer::class)
val postDate: LocalDateTime,

/** The date and time the geek list was last edited - the same as [postDate] if not edited. */
@JsonFormat(pattern = Constants.DAY_FIRST_DATE_TIME_FORMAT) val editDate: LocalDateTime,
@JsonFormat(pattern = Constants.DAY_FIRST_DATE_TIME_FORMAT)
@Serializable(with = LocalDateTimeSerializer::class)
val editDate: LocalDateTime,

/** The number of thumbs up/likes the geek list received. */
val thumbs: Int,
Expand Down Expand Up @@ -66,23 +73,27 @@ data class GeekList(
}

/** A single comment on either a Geek list or a Geek list item. */
@Serializable
data class GeekListComment(
/** The username of the user that left the comment. */
@JacksonXmlProperty(isAttribute = true) val username: String,

/** The date the comment was originally posted. */
@JacksonXmlProperty(isAttribute = true)
@JsonFormat(pattern = Constants.DAY_FIRST_DATE_TIME_FORMAT)
@Serializable(with = LocalDateTimeSerializer::class)
val date: LocalDateTime,

/** The date the comment was originally posted. */
@JacksonXmlProperty(isAttribute = true)
@JsonFormat(pattern = Constants.DAY_FIRST_DATE_TIME_FORMAT)
@Serializable(with = LocalDateTimeSerializer::class)
val postDate: LocalDateTime,

/** The date the comment was last edited - the same as [postDate] if not edited. */
@JacksonXmlProperty(isAttribute = true)
@JsonFormat(pattern = Constants.DAY_FIRST_DATE_TIME_FORMAT)
@Serializable(with = LocalDateTimeSerializer::class)
val editDate: LocalDateTime,

/** The number of thumbs up/likes on this item. */
Expand All @@ -97,6 +108,7 @@ data class GeekListComment(
}

/** An item in the geek list e.g. a board game including a description/[body] */
@Serializable
data class GeekListItem(
/** The ID of the geek list item - NOT the id of the object. */
@JacksonXmlProperty(isAttribute = true) val id: Int,
Expand Down Expand Up @@ -124,11 +136,13 @@ data class GeekListItem(
/** The original date this item was added/posted to the list. */
@JacksonXmlProperty(isAttribute = true)
@JsonFormat(pattern = Constants.DAY_FIRST_DATE_TIME_FORMAT)
@Serializable(with = LocalDateTimeSerializer::class)
val postDate: LocalDateTime,

/** The date this item was last edited/changed. */
@JacksonXmlProperty(isAttribute = true)
@JsonFormat(pattern = Constants.DAY_FIRST_DATE_TIME_FORMAT)
@Serializable(with = LocalDateTimeSerializer::class)
val editDate: LocalDateTime,

/** The number of thumbs up/likes this item has received. */
Expand All @@ -140,11 +154,12 @@ data class GeekListItem(
*/
@JacksonXmlProperty(isAttribute = true) val imageId: Int? = null,
@JsonDeserialize(using = TrimmedStringDeserializer::class) val body: String,
) {

/** The list of comments of this list. */
@JsonProperty("comment")
var comments: List<GeekListComment> = mutableListOf()
set(value) {
field = field + value
}
var comments: List<GeekListComment> = mutableListOf(),
) {
@JsonSetter("comment")
fun internalSetComment(value: List<GeekListComment>) {
comments = comments + value
}
}
7 changes: 7 additions & 0 deletions src/main/kotlin/org/audux/bgg/response/Guild.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.JsonRootName
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import java.time.LocalDateTime
import kotlinx.serialization.Serializable
import org.audux.bgg.common.Constants

/** Response wrapper for Guilds to be returned. */
@JsonRootName("guild")
@Serializable
data class Guild(
/** Terms of use of the BGG API. */
@JacksonXmlProperty(isAttribute = true) val termsOfUse: String,
Expand All @@ -35,6 +37,7 @@ data class Guild(
/** The date and time the guild was created. */
@JsonFormat(pattern = Constants.DAY_FIRST_DATE_TIME_FORMAT)
@JacksonXmlProperty(isAttribute = true, localName = "created")
@Serializable(with = LocalDateTimeSerializer::class)
val createdAt: LocalDateTime?,

/** The category of the Guild e.g. an interest group, regional group etc. */
Expand All @@ -57,6 +60,7 @@ data class Guild(
)

/** The physical location of the guild. */
@Serializable
data class Location(
/** First address line. */
@JsonProperty("addr1") val addressLine1: String,
Expand All @@ -78,6 +82,7 @@ data class Location(
)

/** Represents a (partial) list of members of the guild. */
@Serializable
data class GuildMembers(
/** The total number of guild members. */
@JacksonXmlProperty(isAttribute = true) val count: Int,
Expand All @@ -97,12 +102,14 @@ data class GuildMembers(
* A GuildMember entry, consisting of simply a username (can be used to retrieve more user info) and
* a join date and time.
*/
@Serializable
data class GuildMember(
/** The username of the guild member. */
@JacksonXmlProperty(isAttribute = true) val name: String,

/** When the user joined the guild. */
@JsonFormat(pattern = Constants.DAY_FIRST_DATE_TIME_FORMAT)
@JacksonXmlProperty(isAttribute = true, localName = "date")
@Serializable(with = LocalDateTimeSerializer::class)
val joinDate: LocalDateTime,
)
3 changes: 3 additions & 0 deletions src/main/kotlin/org/audux/bgg/response/HotList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ package org.audux.bgg.response
import com.fasterxml.jackson.annotation.JsonRootName
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import kotlinx.serialization.Serializable

/** Response wrapper for Hot lists to be returned. */
@JsonRootName("items")
@Serializable
data class HotList(
/** Terms of use of the BGG API. */
@JacksonXmlProperty(isAttribute = true) val termsOfUse: String,
Expand All @@ -28,6 +30,7 @@ data class HotList(
)

/** Encapsulates a ranked item in the hot list. */
@Serializable
data class HotListItem(
/** Unique ID that can be used to look up more information using the thing endpoint. */
@JacksonXmlProperty(isAttribute = true) val id: Int,
Expand Down
10 changes: 9 additions & 1 deletion src/main/kotlin/org/audux/bgg/response/Plays.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import java.time.LocalDate
import kotlinx.serialization.Serializable
import org.audux.bgg.common.PlayThingType

/** Response wrapper for plays by the user to be returned. */
@JsonRootName("plays")
@Serializable
data class Plays(
/** Terms of use of the BGG API. */
@JacksonXmlProperty(isAttribute = true) val termsOfUse: String,
Expand All @@ -46,12 +48,15 @@ data class Plays(
* Represents a single(or batched as specified by `quantity`) play, including the 'thing'/game and
* its players.
*/
@Serializable
data class Play(
/** Unique ID of the play - not used */
@JacksonXmlProperty(isAttribute = true) val id: Int,

/** The date the play took place. */
@JacksonXmlProperty(isAttribute = true) val date: LocalDate,
@JacksonXmlProperty(isAttribute = true)
@Serializable(with = LocalDateSerializer::class)
val date: LocalDate,

/** The number of plays, of the same game with the same players. */
@JacksonXmlProperty(isAttribute = true) val quantity: Int,
Expand Down Expand Up @@ -86,6 +91,7 @@ data class Play(
)

/** Represents the item/thing that was played e.g. a board game. */
@Serializable
data class PlayItem(
/** The name of the item. */
@JacksonXmlProperty(isAttribute = true) val name: String,
Expand All @@ -107,6 +113,7 @@ data class PlayItem(
)

/** A SubType of a thing e.g. board game. */
@Serializable
data class SubType(
@JsonDeserialize(using = WrappedSubTypeDeserializer::class)
val subtype: org.audux.bgg.common.SubType
Expand All @@ -116,6 +123,7 @@ data class SubType(
* Represents a person in the play i.e. their username, id, what color they played, how they did
* etc.
*/
@Serializable
data class Player(
/** Optional username of the player. */
@JacksonXmlProperty(isAttribute = true) val username: String?,
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/org/audux/bgg/response/Search.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ package org.audux.bgg.response
import com.fasterxml.jackson.annotation.JsonRootName
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import kotlinx.serialization.Serializable
import org.audux.bgg.common.Name
import org.audux.bgg.common.ThingType

/** Response wrapper for the search results/items to be returned. */
@JsonRootName("items")
@Serializable
data class SearchResults(
/** Terms of use of the BGG API. */
@JacksonXmlProperty(isAttribute = true) val termsOfUse: String,
Expand All @@ -33,6 +35,7 @@ data class SearchResults(
)

/** Encapsulates a single search result. */
@Serializable
data class SearchResult(
/** Primary or alternative name. */
val name: Name,
Expand Down
Loading

0 comments on commit bee885c

Please sign in to comment.