From 942ce04519abd7dd3c81cbb42743187e360a17da Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 08:03:34 +0000 Subject: [PATCH 1/2] Initial plan From 3f5203ebc367bac8b8a2c5c8ed1f6b320963b64c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 08:09:55 +0000 Subject: [PATCH 2/2] Remove unnecessary FoodItem instantiation before persistence The FoodItem object was being created before persisting to Firestore, but the actual persisted data came from foodItemData map. This created unnecessary object instantiation and potential confusion. Now FoodItem is only created after successful persistence with the actual document ID. Co-authored-by: maxschwinghammer <111356450+maxschwinghammer@users.noreply.github.com> --- .../service/product/ProductServiceImpl.kt | 41 ++++++++----------- gradlew | 0 2 files changed, 18 insertions(+), 23 deletions(-) mode change 100644 => 100755 gradlew 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 0e075db..e8f59e6 100644 --- a/app/src/main/java/com/freshkeeper/service/product/ProductServiceImpl.kt +++ b/app/src/main/java/com/freshkeeper/service/product/ProductServiceImpl.kt @@ -83,21 +83,6 @@ class ProductServiceImpl val cleanedBarcode = barcode?.takeIf { it.isNotBlank() } - val foodItem = - FoodItem( - barcode = cleanedBarcode, - userId = user.id, - householdId = householdId, - name = productName, - expiryTimestamp = expiryTimestamp, - quantity = quantity, - unit = unit, - storageLocation = storageLocation, - category = category, - status = FoodStatus.ACTIVE, - picture = picture, - ) - val foodItemData = mutableMapOf( "userId" to user.id, @@ -123,21 +108,31 @@ class ProductServiceImpl .document(documentReference.id) .update("id", documentReference.id) .addOnSuccessListener { + val foodItem = FoodItem( + id = documentReference.id, + barcode = cleanedBarcode, + userId = user.id, + householdId = householdId, + name = productName, + expiryTimestamp = expiryTimestamp, + quantity = quantity, + unit = unit, + storageLocation = storageLocation, + category = category, + status = FoodStatus.ACTIVE, + picture = picture, + daysDifference = daysDifference, + ) coroutineScope.launch { if (user.householdId != null) { logActivity( - foodItem.copy(id = documentReference.id), + foodItem, productName, EventType.PRODUCT_ADDED, ) } - appendToCsv(productName, foodItem.category, context) - onSuccess( - foodItem.copy( - id = documentReference.id, - daysDifference = daysDifference, - ), - ) + appendToCsv(productName, category, context) + onSuccess(foodItem) } }.addOnFailureListener { e -> onFailure(e) } }.addOnFailureListener { e -> onFailure(e) } diff --git a/gradlew b/gradlew old mode 100644 new mode 100755