From 850f9c017c2aad8341ffa146349b0a9f82f1dc86 Mon Sep 17 00:00:00 2001 From: Max Schwinghammer Date: Thu, 21 Aug 2025 14:42:27 +0200 Subject: [PATCH] Store barcode only when used --- .../service/product/ProductServiceImpl.kt | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/freshkeeper/service/product/ProductServiceImpl.kt b/app/src/main/java/com/freshkeeper/service/product/ProductServiceImpl.kt index 57a70ff..0e075db 100644 --- a/app/src/main/java/com/freshkeeper/service/product/ProductServiceImpl.kt +++ b/app/src/main/java/com/freshkeeper/service/product/ProductServiceImpl.kt @@ -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( + "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")