FirebaseJetpack

@Serializable
data class FirebaseJetpack(val id: String = UUID.randomUUID().toString(), val name: String = String(), val price: Double = 0.0, val userId: String = String(), val lastUpdated: Long = 0, val lastSynced: Long = 0, val deleted: Boolean = false)

Represents a Jetpack item stored in Firebase Firestore with sync metadata.

This model demonstrates the offline-first sync pattern used in this template. It includes metadata fields (lastUpdated, lastSynced, deleted) that enable bidirectional synchronization between local Room database and remote Firestore.

Sync Pattern

  • Pull: Query Firestore for items where lastUpdated > lastSyncTimestamp

  • Push: Upload local items to Firestore based on their SyncAction

  • Soft Delete: Use deleted flag instead of hard deletion for sync safety

Field Initialization

All properties must have default values to work with Firestore's automatic serialization. This is a Firestore requirement for data classes used as document models.

Usage Example

// Create new item
val jetpack = FirebaseJetpack(
name = "Lightning Bolt",
price = 99.99,
userId = currentUser.id,
lastUpdated = System.currentTimeMillis()
)

// Mark for deletion (soft delete)
val deletedJetpack = jetpack.copy(
deleted = true,
lastUpdated = System.currentTimeMillis()
)

Conversion to/from Room Entity

// Extension in repository layer
fun FirebaseJetpack.toEntity() = JetpackEntity(
id = id,
name = name,
price = price,
userId = userId,
lastUpdated = lastUpdated,
lastSynced = lastSynced,
deleted = deleted,
syncAction = SyncAction.SYNCED
)

fun JetpackEntity.toFirebase() = FirebaseJetpack(
id = id,
name = name,
price = price,
userId = userId,
lastUpdated = lastUpdated,
lastSynced = lastSynced,
deleted = deleted
)

See also

dev.atick.core.room.model.JetpackEntity
dev.atick.core.room.model.SyncAction

Constructors

Link copied to clipboard
constructor(id: String = UUID.randomUUID().toString(), name: String = String(), price: Double = 0.0, userId: String = String(), lastUpdated: Long = 0, lastSynced: Long = 0, deleted: Boolean = false)

Properties

Link copied to clipboard

Soft delete flag. When true, the item is considered deleted but remains in both Firestore and Room for sync purposes. Hard deletion happens after confirming all clients have synchronized the deletion.

Link copied to clipboard
val id: String

Unique identifier of the Jetpack (UUID). This is the primary key used across both Firestore and Room databases.

Link copied to clipboard

Timestamp in milliseconds (epoch time) of the last successful sync with Firestore. Updated after successful push/pull operations.

Link copied to clipboard

Timestamp in milliseconds (epoch time) of the last modification to this item. Updated whenever the item is created, modified, or soft-deleted. Used for incremental sync to pull only changed items.

Link copied to clipboard

Jetpack's display name.

Link copied to clipboard

Jetpack's price in the user's currency.

Link copied to clipboard

User's unique identifier (Firebase Auth UID). Used for user-specific queries and Firestore security rules.