diff --git a/app/src/main/java/com/freshkeeper/model/Activity.kt b/app/src/main/java/com/freshkeeper/model/Activity.kt index 3a6d989..dc0d3d6 100644 --- a/app/src/main/java/com/freshkeeper/model/Activity.kt +++ b/app/src/main/java/com/freshkeeper/model/Activity.kt @@ -11,5 +11,9 @@ data class Activity( val productName: String? = null, val deleted: Boolean = false, ) { + companion object { + const val FIELD_ID = "id" + } + constructor() : this("", "", "", EventType.EDIT, "", 0, "", "", false) } diff --git a/app/src/main/java/com/freshkeeper/model/FoodItem.kt b/app/src/main/java/com/freshkeeper/model/FoodItem.kt index 8630f85..73df6c8 100644 --- a/app/src/main/java/com/freshkeeper/model/FoodItem.kt +++ b/app/src/main/java/com/freshkeeper/model/FoodItem.kt @@ -20,6 +20,23 @@ data class FoodItem( val nutriScore: String? = null, val picture: Picture? = null, ) { + companion object { + const val FIELD_ID = "id" + const val FIELD_BARCODE = "barcode" + const val FIELD_USER_ID = "userId" + const val FIELD_HOUSEHOLD_ID = "householdId" + const val FIELD_NAME = "name" + const val FIELD_EXPIRY_TIMESTAMP = "expiryTimestamp" + const val FIELD_DISCARD_TIMESTAMP = "discardTimestamp" + const val FIELD_QUANTITY = "quantity" + const val FIELD_UNIT = "unit" + const val FIELD_STORAGE_LOCATION = "storageLocation" + const val FIELD_CATEGORY = "category" + const val FIELD_STATUS = "status" + const val FIELD_NUTRIMENTS = "nutriments" + const val FIELD_NUTRI_SCORE = "nutriScore" + const val FIELD_PICTURE = "picture" + } constructor() : this( "", null, 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..be43173 100644 --- a/app/src/main/java/com/freshkeeper/service/product/ProductServiceImpl.kt +++ b/app/src/main/java/com/freshkeeper/service/product/ProductServiceImpl.kt @@ -100,18 +100,18 @@ class ProductServiceImpl 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, + FoodItem.FIELD_USER_ID to user.id, + FoodItem.FIELD_NAME to productName, + FoodItem.FIELD_EXPIRY_TIMESTAMP to expiryTimestamp, + FoodItem.FIELD_QUANTITY to quantity, + FoodItem.FIELD_UNIT to unit, + FoodItem.FIELD_STORAGE_LOCATION to storageLocation, + FoodItem.FIELD_CATEGORY to category, + FoodItem.FIELD_STATUS to FoodStatus.ACTIVE, ).apply { - cleanedBarcode?.let { this["barcode"] = it } - householdId?.let { this["householdId"] = it } - picture?.let { this["picture"] = it } + cleanedBarcode?.let { this[FoodItem.FIELD_BARCODE] = it } + householdId?.let { this[FoodItem.FIELD_HOUSEHOLD_ID] = it } + picture?.let { this[FoodItem.FIELD_PICTURE] = it } } firestore @@ -121,7 +121,7 @@ class ProductServiceImpl firestore .collection("foodItems") .document(documentReference.id) - .update("id", documentReference.id) + .update(FoodItem.FIELD_ID, documentReference.id) .addOnSuccessListener { coroutineScope.launch { if (user.householdId != null) { @@ -195,19 +195,19 @@ class ProductServiceImpl ) { firestore .collection("foodItems") - .whereEqualTo("id", foodItem.id) + .whereEqualTo(FoodItem.FIELD_ID, foodItem.id) .get() .addOnSuccessListener { querySnapshot -> val document = querySnapshot.documents.firstOrNull() if (document != null) { val updates: MutableMap = mutableMapOf( - "name" to productName, - "quantity" to quantity, - "unit" to unit, - "storageLocation" to storageLocation, - "category" to category, - "expiryTimestamp" to expiryTimestamp, + FoodItem.FIELD_NAME to productName, + FoodItem.FIELD_QUANTITY to quantity, + FoodItem.FIELD_UNIT to unit, + FoodItem.FIELD_STORAGE_LOCATION to storageLocation, + FoodItem.FIELD_CATEGORY to category, + FoodItem.FIELD_EXPIRY_TIMESTAMP to expiryTimestamp, "consumed" to isConsumedChecked, "thrownAway" to isThrownAwayChecked, ) @@ -362,7 +362,7 @@ class ProductServiceImpl .collection("activities") .add(activity) .addOnSuccessListener { documentReference -> - documentReference.update("id", documentReference.id) + documentReference.update(Activity.FIELD_ID, documentReference.id) }.addOnFailureListener { e -> Log.e("Firestore", "Error when adding the activity", e) } diff --git a/gradlew b/gradlew old mode 100644 new mode 100755