feat(shared): add KMP get_note.php client and delegate Android fetchNoteDetail
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
package app.klottr.net
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import app.klottr.BuildConfig
|
||||
import app.klottr.net.KlottrApiShared
|
||||
import app.klottr.util.Auth
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
||||
@@ -13,14 +19,10 @@ import retrofit2.Retrofit
|
||||
import retrofit2.converter.moshi.MoshiConverterFactory
|
||||
import retrofit2.http.*
|
||||
import retrofit2.http.Url
|
||||
import app.klottr.util.Auth
|
||||
import app.klottr.BuildConfig
|
||||
import app.klottr.net.KlottrApiShared
|
||||
|
||||
import java.io.File
|
||||
import java.util.concurrent.TimeUnit
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
@@ -438,23 +440,41 @@ suspend fun deleteNote(id: Long): Boolean {
|
||||
|
||||
|
||||
suspend fun fetchNoteDetail(id: Long, lat: Double, lon: Double): NoteDetailDTO? {
|
||||
val body = NoteDetailBody(id = id, lat = lat, lon = lon)
|
||||
return try {
|
||||
val resp = Api.svc.getNote(body)
|
||||
app.klottr.util.AppLog.d { "get_note code=${resp.code()} ok=${resp.isSuccessful}"}
|
||||
if (!resp.isSuccessful) {
|
||||
val err = resp.errorBody()?.string()
|
||||
app.klottr.util.AppLog.d { "get_note err=$err"}
|
||||
null
|
||||
} else {
|
||||
resp.body()
|
||||
}
|
||||
val sh = try {
|
||||
KlottrApiShared.getNote(
|
||||
baseUrl = ApiConfig.SERVER_API_BASE_URL,
|
||||
apiKey = ApiConfig.SERVER_API_KEY,
|
||||
bearerToken = app.klottr.util.Auth.idToken,
|
||||
id = id,
|
||||
lat = lat,
|
||||
lon = lon
|
||||
)
|
||||
} catch (t: Throwable) {
|
||||
app.klottr.util.AppLog.d { "get_note exception: ${t.message}"}
|
||||
app.klottr.util.AppLog.d { "get_note exception: ${t.message}" }
|
||||
null
|
||||
}
|
||||
|
||||
if (sh == null) {
|
||||
app.klottr.util.AppLog.d { "get_note FAIL (null)" }
|
||||
return null
|
||||
}
|
||||
|
||||
// Mappa delad modell → Androids Moshi-bundna DTO (behåller nuvarande typer)
|
||||
return NoteDetailDTO(
|
||||
id = sh.id,
|
||||
lat = sh.lat,
|
||||
lon = sh.lon,
|
||||
title = sh.title,
|
||||
body = sh.body,
|
||||
image = sh.image,
|
||||
createdAt = sh.createdAt,
|
||||
updatedAt = sh.updatedAt,
|
||||
username = sh.username,
|
||||
userId = sh.userId
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
/** Anropa me.php – null vid nätverksfel/ej 200 */
|
||||
suspend fun fetchMe(): MeResp? {
|
||||
val resp = try { Api.svc.me() } catch (_: Throwable) { return null }
|
||||
|
||||
Reference in New Issue
Block a user