Skip to content

Commit

Permalink
Remove opt-in and use visibility modifiers
Browse files Browse the repository at this point in the history
I didn't know kotlinx.serialization can serialize classes with private properties
  • Loading branch information
HeroBrine1st committed Jan 10, 2024
1 parent a89f3ec commit 9dcc80a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ import kotlinx.serialization.json.jsonPrimitive
import ru.herobrine1st.e621.api.API
import ru.herobrine1st.e621.api.E621_MAX_POSTS_IN_QUERY
import ru.herobrine1st.e621.api.model.Post
import ru.herobrine1st.e621.util.InternalState

@Serializable
data class FavouritesSearchOptions(
val favouritesOf: String,
@set:InternalState var id: Int? = null,
private var id: Int? = null,
) : SearchOptions {
override val maxLimit: Int get() = E621_MAX_POSTS_IN_QUERY

@OptIn(InternalState::class)
override suspend fun getPosts(api: API, limit: Int, page: Int): List<Post> {
id = id ?: favouritesOf.let {
api.getUser(favouritesOf).getOrThrow()["id"]!!.jsonPrimitive.content.toInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ import ru.herobrine1st.e621.api.API
import ru.herobrine1st.e621.api.E621_MAX_ITEMS_IN_RANGE_ENUMERATION
import ru.herobrine1st.e621.api.model.Post
import ru.herobrine1st.e621.api.model.PostId
import ru.herobrine1st.e621.util.InternalState

@Serializable
data class PoolSearchOptions(
val poolId: Int,
@set:InternalState var postIds: List<PostId>? = null,
private var postIds: List<PostId>? = null,
) : SearchOptions {
override val maxLimit: Int get() = E621_MAX_ITEMS_IN_RANGE_ENUMERATION

@OptIn(InternalState::class)
override suspend fun getPosts(api: API, limit: Int, page: Int): List<Post> {
require(limit <= maxLimit)
val postIds = (postIds ?: api.getPool(poolId).getOrThrow().posts)
Expand Down
25 changes: 0 additions & 25 deletions app/src/main/java/ru/herobrine1st/e621/util/InternalState.kt

This file was deleted.

0 comments on commit 9dcc80a

Please sign in to comment.