createOrUpdateJetpack
Creates or updates a Jetpack item in Firestore (upsert operation).
This method uses Firestore's set() operation to either create a new document or replace an existing one. This is the preferred method for sync operations as it handles both new items and updates uniformly.
Behavior
If document doesn't exist: Creates new document
If document exists: Completely replaces the document with new data
Warning: This performs a full replace, not a merge. All fields are overwritten.
Document Path
/dev.atick.jetpack/jetpacks/{userId}/{jetpackId}
Usage in Sync
suspend fun syncPush() {
val pendingItems = localDataSource.getItemsWithSyncAction(
SyncAction.CREATE, SyncAction.UPDATE
)
pendingItems.forEach { local ->
val firebaseItem = local.toFirebase().copy(
lastUpdated = System.currentTimeMillis()
)
firebaseDataSource.createOrUpdateJetpack(firebaseItem)
localDataSource.markAsSynced(local.id)
}
}Content copied to clipboard
Parameters
firebaseJetpack
The FirebaseJetpack object to create or update. Should have lastUpdated set to the current timestamp.
Throws
FirebaseFirestoreException
if the operation fails
FirebaseNetworkException
if network is unavailable
if Firestore security rules deny the operation