Join Slack
here is my code: override suspend fun updateDocument( productId: String, updates: Ma...
# android
f
Frank Morara
05/30/2024, 2:32 PM
here is my code: override suspend fun updateDocument( productId: String, updates: Map<String, Any> ): Resource<Boolean> { return withContext(
Dispatchers.IO
) { try { val documentSnapshot = db.collection(INVENTORY) .document(productId) .get() .await() if (documentSnapshot.exists()) { Timber.tag(INVENTORY_TAG).d("Document exists") db.collection(INVENTORY) .document(productId) .update(updates) .await() Resource.Success(true) } else { Timber.tag(INVENTORY_TAG).e("Document does not exist") Resource.Error(Exception("Document with ID $productId does not exist")) } } catch (e: Exception) { Timber.tag(INVENTORY_TAG).e(e) Resource.Error(e) } } }
🧵 5
7
Views
Open in Slack
Previous
Next
kotlinlang
A modern programming language that makes developers happier.
Powered by