suspend fun addOrUpdateItem()

in app/src/main/java/co/elastic/apm/opbeans/app/data/source/cart/LocalCartItemSource.kt [45:53]


    suspend fun addOrUpdateItem(productId: Int) {
        val existingCartItemForProduct = cartItemDao.getCartItemWithProduct(productId)
        if (existingCartItemForProduct != null) {
            val newAmount = existingCartItemForProduct.cartItemEntity.amount + 1
            cartItemDao.update(existingCartItemForProduct.cartItemEntity.copy(amount = newAmount))
        } else {
            cartItemDao.insert(CartItemEntity(0, productId, 1, Date().time))
        }
    }