mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 10:37:05 +05:30
all: refactor model classes and serialization
- Move model classes to a standalone `model` Gradle module - Migrate from Moshi to kotlinx.serialization for multiplatform support
This commit is contained in:
parent
76c46b4229
commit
096d2882e2
24 changed files with 155 additions and 137 deletions
|
@ -1,14 +1,12 @@
|
|||
plugins {
|
||||
kotlin("jvm")
|
||||
id("com.google.devtools.ksp") version "1.5.31-1.0.0"
|
||||
}
|
||||
plugins { kotlin("jvm") }
|
||||
|
||||
dependencies {
|
||||
api(projects.model)
|
||||
api(libs.retrofit.lib)
|
||||
ksp(libs.moshix.ksp)
|
||||
implementation(libs.moshi.lib)
|
||||
implementation(libs.retrofit.moshiConverter) { exclude(group = "com.squareup.moshi") }
|
||||
implementation(libs.kotlinx.serialization.core)
|
||||
testImplementation(libs.kotlinx.serialization.json)
|
||||
testImplementation(libs.kotlin.coroutines.core)
|
||||
testImplementation(kotlin("test-junit"))
|
||||
testImplementation(libs.retrofit.kotlinxSerializationConverter) { isTransitive = false }
|
||||
testImplementation(libs.testing.mockWebServer)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package dev.msfjarvis.claw.api
|
||||
|
||||
import dev.msfjarvis.claw.api.model.LobstersPost
|
||||
import dev.msfjarvis.claw.api.model.LobstersPostDetails
|
||||
import dev.msfjarvis.claw.model.LobstersPost
|
||||
import dev.msfjarvis.claw.model.LobstersPostDetails
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Path
|
||||
import retrofit2.http.Query
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package dev.msfjarvis.claw.api.model
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class Comment(
|
||||
@Json(name = "short_id") val shortId: String,
|
||||
@Json(name = "short_id_url") val shortIdUrl: String,
|
||||
@Json(name = "created_at") val createdAt: String,
|
||||
@Json(name = "updated_at") val updatedAt: String,
|
||||
@Json(name = "is_deleted") val isDeleted: Boolean,
|
||||
@Json(name = "is_moderated") val isModerated: Boolean,
|
||||
val score: Long,
|
||||
val flags: Long,
|
||||
val comment: String,
|
||||
val url: String,
|
||||
@Json(name = "indent_level") val indentLevel: Long,
|
||||
@Json(name = "commenting_user") val user: User,
|
||||
)
|
|
@ -1,10 +0,0 @@
|
|||
package dev.msfjarvis.claw.api.model
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class KeybaseSignature(
|
||||
@Json(name = "kb_username") val kbUsername: String,
|
||||
@Json(name = "sig_hash") val sigHash: String,
|
||||
)
|
|
@ -1,20 +0,0 @@
|
|||
package dev.msfjarvis.claw.api.model
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class LobstersPost(
|
||||
@Json(name = "short_id") val shortId: String,
|
||||
@Json(name = "short_id_url") val shortIdUrl: String,
|
||||
@Json(name = "created_at") val createdAt: String,
|
||||
val title: String,
|
||||
val url: String,
|
||||
val score: Long,
|
||||
val flags: Long,
|
||||
@Json(name = "comment_count") val commentCount: Long,
|
||||
val description: String,
|
||||
@Json(name = "comments_url") val commentsUrl: String,
|
||||
@Json(name = "submitter_user") val submitter: User,
|
||||
val tags: List<String>,
|
||||
)
|
|
@ -1,21 +0,0 @@
|
|||
package dev.msfjarvis.claw.api.model
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class LobstersPostDetails(
|
||||
@Json(name = "short_id") val shortId: String,
|
||||
@Json(name = "short_id_url") val shortIdUrl: String,
|
||||
@Json(name = "created_at") val createdAt: String,
|
||||
val title: String,
|
||||
val url: String,
|
||||
val score: Long,
|
||||
val flags: Long,
|
||||
@Json(name = "comment_count") val commentCount: Long,
|
||||
val description: String,
|
||||
@Json(name = "comments_url") val commentsUrl: String,
|
||||
@Json(name = "submitter_user") val submitter: User,
|
||||
val tags: List<String>,
|
||||
val comments: List<Comment>,
|
||||
)
|
|
@ -1,19 +0,0 @@
|
|||
package dev.msfjarvis.claw.api.model
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class User(
|
||||
val username: String,
|
||||
@Json(name = "created_at") val createdAt: String,
|
||||
@Json(name = "is_admin") val isAdmin: Boolean,
|
||||
val about: String,
|
||||
@Json(name = "is_moderator") val isModerator: Boolean,
|
||||
val karma: Long = 0,
|
||||
@Json(name = "avatar_url") val avatarUrl: String,
|
||||
@Json(name = "invited_by_user") val invitedByUser: String,
|
||||
@Json(name = "github_username") val githubUsername: String? = null,
|
||||
@Json(name = "twitter_username") val twitterUsername: String? = null,
|
||||
@Json(name = "keybase_signatures") val keybaseSignatures: List<KeybaseSignature> = emptyList(),
|
||||
)
|
|
@ -1,34 +1,37 @@
|
|||
package dev.msfjarvis.claw.api
|
||||
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
|
||||
import dev.msfjarvis.claw.util.TestUtils
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
import kotlin.test.fail
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.json.Json
|
||||
import mockwebserver3.Dispatcher
|
||||
import mockwebserver3.MockResponse
|
||||
import mockwebserver3.MockWebServer
|
||||
import mockwebserver3.RecordedRequest
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.OkHttpClient
|
||||
import org.junit.AfterClass
|
||||
import org.junit.BeforeClass
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.moshi.MoshiConverterFactory
|
||||
import retrofit2.create
|
||||
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
class LobstersApiTest {
|
||||
|
||||
companion object {
|
||||
private val contentType = "application/json".toMediaType()
|
||||
private val webServer = MockWebServer()
|
||||
private val moshi = Moshi.Builder().build()
|
||||
private val okHttp = OkHttpClient.Builder().build()
|
||||
private val retrofit =
|
||||
Retrofit.Builder()
|
||||
.client(okHttp)
|
||||
.baseUrl("http://localhost:8080/")
|
||||
.addConverterFactory(MoshiConverterFactory.create(moshi))
|
||||
.addConverterFactory(Json.asConverterFactory(contentType))
|
||||
.build()
|
||||
private val apiClient = retrofit.create<LobstersApi>()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue