-
-
Notifications
You must be signed in to change notification settings - Fork 0
Store barcode only when used #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,9 +81,11 @@ class ProductServiceImpl | |
| else -> null | ||
| } | ||
|
|
||
| val cleanedBarcode = barcode?.takeIf { it.isNotBlank() } | ||
|
|
||
| val foodItem = | ||
| FoodItem( | ||
| barcode = barcode, | ||
| barcode = cleanedBarcode, | ||
| userId = user.id, | ||
| householdId = householdId, | ||
| name = productName, | ||
|
|
@@ -96,9 +98,25 @@ class ProductServiceImpl | |
| picture = picture, | ||
| ) | ||
|
||
|
|
||
| val foodItemData = | ||
| mutableMapOf<String, Any>( | ||
| "userId" to user.id, | ||
| "name" to productName, | ||
| "expiryTimestamp" to expiryTimestamp, | ||
| "quantity" to quantity, | ||
| "unit" to unit, | ||
| "storageLocation" to storageLocation, | ||
| "category" to category, | ||
| "status" to FoodStatus.ACTIVE, | ||
| ).apply { | ||
| cleanedBarcode?.let { this["barcode"] = it } | ||
| householdId?.let { this["householdId"] = it } | ||
| picture?.let { this["picture"] = it } | ||
| } | ||
|
||
|
|
||
| firestore | ||
| .collection("foodItems") | ||
| .add(foodItem) | ||
| .add(foodItemData) | ||
| .addOnSuccessListener { documentReference -> | ||
| firestore | ||
| .collection("foodItems") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The FoodItem object is created but never used after line 119 switches to using foodItemData. This creates unnecessary object instantiation and potential confusion about which data structure is actually persisted.