feat(shared): add KMP create.php (text & doc) and delegate Android createNote*

This commit is contained in:
2025-09-06 16:48:30 +02:00
parent b3dcb91922
commit 477b1cb022
2 changed files with 130 additions and 14 deletions

View File

@@ -388,7 +388,6 @@ suspend fun createNote(
* Skapar notis med rubrik/brödtext/bild/radius.
* Returnerar true om servern svarar { ok: true }.
*/
suspend fun createNoteDoc(
lat: Double,
lon: Double,
@@ -402,25 +401,23 @@ suspend fun createNoteDoc(
if (Auth.idToken == null || Auth.userId == null) {
return false
}
val payload = CreateDocBody(
lat = lat, lon = lon,
title = title, body = body,
imageId = imageId, radiusM = radiusM,
return KlottrApiShared.createDoc(
baseUrl = ApiConfig.SERVER_API_BASE_URL,
apiKey = ApiConfig.SERVER_API_KEY,
bearerToken = Auth.idToken,
lat = lat,
lon = lon,
title = title,
body = body,
imageId = imageId,
radiusM = radiusM,
createdAt = createdAt,
userId = Auth.userId,
clientRequestId = clientRequestId
)
val resp = try { Api.svc.createDoc(payload, idempotencyKey = clientRequestId) } catch (_: Throwable) { return false }
if (!resp.isSuccessful) return false
val okField = resp.body()?.get("ok")
return when (okField) {
is Boolean -> okField
is Number -> okField.toInt() != 0
is String -> okField.equals("true", true) || okField == "1" || okField.equals("ok", true)
else -> true
}
}
/**
* Raderar (soft delete) en not du äger. Returnerar true om { ok: true }.
*/