Skip to content

Commit

Permalink
Complete endpoint model
Browse files Browse the repository at this point in the history
  • Loading branch information
HeroBrine1st committed Mar 30, 2024
1 parent 95adce5 commit 876ddb9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/ru/herobrine1st/e621/api/API.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
package ru.herobrine1st.e621.api

import androidx.annotation.IntRange
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonObject
import ru.herobrine1st.e621.api.endpoint.favourites.AddToFavouritesEndpoint
import ru.herobrine1st.e621.api.endpoint.favourites.GetFavouritesEndpoint
import ru.herobrine1st.e621.api.endpoint.posts.GetPostCommentsDTextEndpoint
import ru.herobrine1st.e621.api.endpoint.posts.GetPostCommentsHTMLEndpoint
Expand Down Expand Up @@ -69,7 +69,7 @@ interface API : AutocompleteSuggestionsAPI {

suspend fun addToFavourites(
postId: PostId,
): Result<JsonElement>
): Result<AddToFavouritesEndpoint.Response>


suspend fun removeFromFavourites(
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/ru/herobrine1st/e621/api/APIClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import io.ktor.client.request.header
import io.ktor.client.request.setBody
import io.ktor.http.HttpHeaders
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.serializer
Expand Down Expand Up @@ -149,7 +148,7 @@ class APIImpl(val client: APIClient) : API {
limit: Int?,
) = client.request(GetFavouritesEndpoint(userId, page, limit))

override suspend fun addToFavourites(postId: PostId): Result<JsonElement> =
override suspend fun addToFavourites(postId: PostId): Result<AddToFavouritesEndpoint.Response> =
client.request(AddToFavouritesEndpoint(postId))

override suspend fun removeFromFavourites(postId: PostId) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@ package ru.herobrine1st.e621.api.endpoint.favourites
import io.ktor.resources.Resource
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonElement
import ru.herobrine1st.e621.api.HttpMethod
import ru.herobrine1st.e621.api.HttpMethodType
import ru.herobrine1st.e621.api.endpoint.APIEndpoint
import ru.herobrine1st.e621.api.model.Post
import ru.herobrine1st.e621.api.model.PostId

// TODO proper model
@Serializable
@HttpMethod(HttpMethodType.POST)
@Resource("/favorites.json")
data class AddToFavouritesEndpoint(
@SerialName("post_id") val postId: PostId
): APIEndpoint<Unit, JsonElement>
@SerialName("post_id") val postId: PostId,
) : APIEndpoint<Unit, AddToFavouritesEndpoint.Response> {
@Serializable
data class Response(
val post: Post,
)
}

0 comments on commit 876ddb9

Please sign in to comment.