app(write): on UploadFailed, queue to outbox via shared use case; persist image locally and schedule upload worker
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package app.klottr.create
|
||||
|
||||
/** Resultat från outbox-köning (offline). */
|
||||
sealed class QueueOutboxOutcome {
|
||||
data object Queued : QueueOutboxOutcome() // Lyckades lägga i utkorgen
|
||||
data object ImagePersistFailed : QueueOutboxOutcome() // Bilden kunde inte sparas lokalt
|
||||
}
|
||||
|
||||
/**
|
||||
* Orkestrerar offline-flödet: ev. spara bild lokalt → lägg DOC i outbox → schemalägg uppladdning.
|
||||
* Plattformsspecifika detaljer injiceras via lambdas (DI).
|
||||
*/
|
||||
suspend fun queueNoteDocOutbox(
|
||||
lat: Double,
|
||||
lon: Double,
|
||||
title: String,
|
||||
body: String,
|
||||
createdAt: Long,
|
||||
radiusM: Int,
|
||||
hasImage: Boolean,
|
||||
persistImageIfAny: suspend () -> Pair<String, String>?, // returnerar (imagePath, imageMime) eller null vid fel
|
||||
addOutboxDoc: (lat: Double, lon: Double, title: String, body: String, createdAt: Long, radiusM: Int, imagePath: String?, imageMime: String?) -> Unit,
|
||||
scheduleUpload: () -> Unit
|
||||
): QueueOutboxOutcome {
|
||||
val (imagePath, imageMime) = if (hasImage) {
|
||||
val res = persistImageIfAny() ?: return QueueOutboxOutcome.ImagePersistFailed
|
||||
res
|
||||
} else null to null
|
||||
|
||||
addOutboxDoc(lat, lon, title, body, createdAt, radiusM, imagePath, imageMime)
|
||||
scheduleUpload()
|
||||
return QueueOutboxOutcome.Queued
|
||||
}
|
||||
Reference in New Issue
Block a user