diff options
| author | James Barnett <noreply@jamesbarnett.xyz> | 2020-04-10 13:34:23 +0100 |
|---|---|---|
| committer | James Barnett <noreply@jamesbarnett.xyz> | 2020-04-10 13:34:23 +0100 |
| commit | 78400d587ea5367d3424333913ff4f94ca3f1908 (patch) | |
| tree | 2cf5f5ff8069740b0b7dd00853a4ea8c13d6e05c /src/main/kotlin/io/jamesbarnett/redditlite/model/Post.kt | |
| parent | d5a608143ad2250d8b35b9e4a488d39faaf5a021 (diff) | |
| download | reddit-lite-78400d587ea5367d3424333913ff4f94ca3f1908.tar.xz reddit-lite-78400d587ea5367d3424333913ff4f94ca3f1908.zip | |
Reimplement in Kotlin
Diffstat (limited to 'src/main/kotlin/io/jamesbarnett/redditlite/model/Post.kt')
| -rw-r--r-- | src/main/kotlin/io/jamesbarnett/redditlite/model/Post.kt | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/main/kotlin/io/jamesbarnett/redditlite/model/Post.kt b/src/main/kotlin/io/jamesbarnett/redditlite/model/Post.kt new file mode 100644 index 0000000..4cd723d --- /dev/null +++ b/src/main/kotlin/io/jamesbarnett/redditlite/model/Post.kt @@ -0,0 +1,41 @@ +package io.jamesbarnett.redditlite.model + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonProperty +import com.github.marlonlom.utilities.timeago.TimeAgo +import java.time.Instant + +@JsonIgnoreProperties(ignoreUnknown = true) +data class Post ( + val id: String, + val name: String, + val title: String, + val domain: String, + val score: Int, + val author: String, + private val thumbnail: String?, + val ups: Int, + @JsonProperty("num_comments") + val commentCount: Int, + val url: String, + @JsonProperty("created_utc") + val createdDate: Instant, + @JsonProperty("is_self") + val isSelfPost: Boolean, + @JsonProperty("selftext_html") + val selftextHtml: String?, + val subreddit: String +) { + val primaryLink: String get() { + return if (isSelfPost) { + "/r/${subreddit}/comments/${id}" + } else { + url + } + } + val subredditPath get() = "/r/${subreddit}" + val relativeCreatedDate: String get() = TimeAgo.using(createdDate.toEpochMilli()) + val thumbnailUrl get() = thumbnail?.let { if(thumbnail.startsWith("http")) thumbnail else null } +//val thumbnail get() = if(thumbnailRaw?.startsWith("http") == true) thumbnailRaw else null + +}
\ No newline at end of file |