refactor(frontend, build): update PingViewModel initialization, resolve view model via Koin, and clean yarn dependencies
Injected `PingViewModel` via Koin to align with dependency injection best practices. Suppressed Gradle deprecation warnings and added the `frontend.core.sync` dependency. Cleaned up outdated packages in `yarn.lock`.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
plugins {
|
||||
alias(libs.plugins.kotlinMultiplatform)
|
||||
alias(libs.plugins.kotlinSerialization)
|
||||
}
|
||||
|
||||
kotlin {
|
||||
// Targets are configured centrally in the shells/feature modules; here we just provide common code.
|
||||
jvm()
|
||||
js(IR) {
|
||||
browser()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
commonMain.dependencies {
|
||||
implementation(projects.core.coreDomain)
|
||||
|
||||
// Networking
|
||||
implementation(libs.ktor.client.core)
|
||||
implementation(libs.ktor.client.contentNegotiation)
|
||||
implementation(libs.ktor.client.serialization.kotlinx.json)
|
||||
|
||||
// Serialization
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
|
||||
// DI
|
||||
implementation(libs.koin.core)
|
||||
}
|
||||
|
||||
commonTest.dependencies {
|
||||
implementation(libs.kotlin.test)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package at.mocode.frontend.core.sync
|
||||
|
||||
import at.mocode.core.sync.Syncable
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.body
|
||||
import io.ktor.client.request.get
|
||||
import io.ktor.client.request.parameter
|
||||
|
||||
/**
|
||||
* Minimaler Repository-Contract für Delta-Sync.
|
||||
*/
|
||||
interface SyncableRepository<T : Syncable> {
|
||||
/**
|
||||
* Cursor für Delta-Sync.
|
||||
*
|
||||
* Konvention: UUIDv7 als String (Backend kann `>` vergleichen) oder ein kompatibler Cursor.
|
||||
*
|
||||
* @return letzter bekannter Cursor lokal oder `null`, wenn noch keine Daten existieren.
|
||||
*/
|
||||
suspend fun getLatestSince(): String?
|
||||
|
||||
/** Insert oder Update (Upsert) der übergebenen Items. */
|
||||
suspend fun upsert(items: List<T>)
|
||||
}
|
||||
|
||||
/**
|
||||
* Generischer Sync-Manager.
|
||||
*
|
||||
* Konvention Backend:
|
||||
* - GET `/api/{entity-plural}/sync?since={timestamp}`
|
||||
* - Response: `List<T>`
|
||||
*/
|
||||
class SyncManager(
|
||||
val ktorClient: HttpClient
|
||||
) {
|
||||
|
||||
suspend inline fun <reified T : Syncable> performSync(
|
||||
repository: SyncableRepository<T>,
|
||||
endpointPath: String
|
||||
) {
|
||||
val since = repository.getLatestSince()
|
||||
|
||||
val remoteItems: List<T> = ktorClient
|
||||
.get(endpointPath) {
|
||||
// `since` optional
|
||||
if (since != null) parameter("since", since)
|
||||
}
|
||||
.body()
|
||||
|
||||
if (remoteItems.isNotEmpty()) {
|
||||
repository.upsert(remoteItems)
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package at.mocode.frontend.core.sync.di
|
||||
|
||||
import at.mocode.frontend.core.sync.SyncManager
|
||||
import org.koin.dsl.module
|
||||
|
||||
/**
|
||||
* Zentrales Koin-Modul für den Sync-Core.
|
||||
*/
|
||||
val syncModule = module {
|
||||
// Provides a singleton instance of SyncManager, using the globally provided HttpClient.
|
||||
single { SyncManager(get()) }
|
||||
}
|
||||
Reference in New Issue
Block a user