fixing web-app

This commit is contained in:
stefan
2025-09-24 14:21:57 +02:00
parent cd2b0796a6
commit 1c4184809a
156 changed files with 440 additions and 1708 deletions
@@ -0,0 +1,3 @@
package at.mocode
const val SERVER_PORT = 8081
@@ -0,0 +1,9 @@
package at.mocode
class Greeting {
private val platform = getPlatform()
fun greet(): String {
return "Hello, ${platform.name}!"
}
}
@@ -0,0 +1,7 @@
package at.mocode
interface Platform {
val name: String
}
expect fun getPlatform(): Platform
@@ -0,0 +1,10 @@
package at.mocode.model
// Deprecated local DTOs are replaced by typealiases to the shared API contract.
// This preserves binary/source compatibility for existing imports while enforcing SSoT.
typealias PingResponse = at.mocode.ping.api.PingResponse
typealias EnhancedPingResponse = at.mocode.ping.api.EnhancedPingResponse
typealias HealthResponse = at.mocode.ping.api.HealthResponse
@@ -0,0 +1,25 @@
package at.mocode.ping.client
import at.mocode.ping.api.EnhancedPingResponse
import at.mocode.ping.api.HealthResponse
import at.mocode.ping.api.PingApi
import at.mocode.ping.api.PingResponse
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.get
import io.ktor.client.request.parameter
import at.mocode.service.getBaseUrl
class PingApiClient(
private val client: HttpClient,
baseUrl: String = getBaseUrl()
) : PingApi {
private val base = "$baseUrl/api/ping"
override suspend fun simplePing(): PingResponse = client.get("$base/simple").body()
override suspend fun enhancedPing(simulate: Boolean): EnhancedPingResponse =
client.get("$base/enhanced") { parameter("simulate", simulate) }.body()
override suspend fun healthCheck(): HealthResponse = client.get("$base/health").body()
}
@@ -0,0 +1,43 @@
package at.mocode.service
import at.mocode.model.EnhancedPingResponse
import at.mocode.model.HealthResponse
import at.mocode.model.PingResponse
import at.mocode.ping.client.PingApiClient
import io.ktor.client.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.serialization.kotlinx.json.*
import kotlinx.serialization.json.Json
@Deprecated("Use PingApiClient directly for new code")
class PingService(
private val client: HttpClient = HttpClient {
install(ContentNegotiation) {
json(Json {
ignoreUnknownKeys = true
isLenient = true
})
}
install(HttpTimeout) {
requestTimeoutMillis = 10000
connectTimeoutMillis = 5000
}
}
) {
private val api = PingApiClient(client)
suspend fun ping(): Result<PingResponse> = runCatching { api.simplePing() }
suspend fun enhancedPing(simulate: Boolean = false): Result<EnhancedPingResponse> =
runCatching { api.enhancedPing(simulate) }
suspend fun health(): Result<HealthResponse> = runCatching { api.healthCheck() }
suspend fun testFailure(): Result<EnhancedPingResponse> = runCatching {
throw RuntimeException("Simulated failure for testing")
}
}
// Platform-specific base URL required by PingApiClient via getBaseUrl()
expect fun getBaseUrl(): String