shared(create): add createNoteFlow use case (upload→create orchestration) with CreateNoteOutcome
app(main): use createNoteFlow in WriteDocDialog onSave; keep offline outbox path unchanged
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package app.klottr.create
|
||||
|
||||
/** Resultat från create-flödet. */
|
||||
sealed class CreateNoteOutcome {
|
||||
data object Success : CreateNoteOutcome()
|
||||
data class UploadFailed(val message: String?) : CreateNoteOutcome()
|
||||
data object CreateFailed : CreateNoteOutcome()
|
||||
}
|
||||
|
||||
/**
|
||||
* Orkestrerar online-flödet: ev. bilduppladdning → skapa notis.
|
||||
* Plattformsspecifika detaljer injiceras via lambdas.
|
||||
*/
|
||||
suspend fun createNoteFlow(
|
||||
hasImage: Boolean,
|
||||
uploadImage: suspend () -> Long?, // Körs bara om hasImage = true
|
||||
createNote: suspend (imageId: Long?) -> Boolean, // Skapa klotter med ev. imageId
|
||||
getUploadError: () -> String? = { null } // För t.ex. Api.lastUploadError (valfritt)
|
||||
): CreateNoteOutcome {
|
||||
val imageId: Long? = if (hasImage) {
|
||||
val id = uploadImage()
|
||||
if (id == null) return CreateNoteOutcome.UploadFailed(getUploadError())
|
||||
id
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
val ok = createNote(imageId)
|
||||
return if (ok) CreateNoteOutcome.Success else CreateNoteOutcome.CreateFailed
|
||||
}
|
||||
Reference in New Issue
Block a user