Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/src/main/java/com/freshkeeper/model/Activity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
17 changes: 17 additions & 0 deletions app/src/main/java/com/freshkeeper/model/FoodItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,18 @@ class ProductServiceImpl

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,
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
Expand All @@ -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) {
Expand Down Expand Up @@ -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<String, Any> =
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,
)
Expand Down Expand Up @@ -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)
}
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.