-
Notifications
You must be signed in to change notification settings - Fork 133
[POS][Local Catalog] Connect product list to POS database #14636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
samiuelson
wants to merge
12
commits into
woomob-1069-woo-poslocal-catalog-update-ptr-behavior-fetch-products-and
Choose a base branch
from
woomob-1072-woo-poslocal-catalog-connect-product-list-to-pos-products
base: woomob-1069-woo-poslocal-catalog-update-ptr-behavior-fetch-products-and
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
744aabf
Get product from DB in Cart
samiuelson ed171b0
Update test
samiuelson 69e53d4
Create in-DB products data source
samiuelson 3737d65
Plug in in-DB products data source into products VM
samiuelson 0350226
Sort products by name lowercase
samiuelson 8966f1c
Get variation and product from DB in totals screen
samiuelson fe4f6b0
Satisfy detekt's complaints
samiuelson 267d0c7
Fix tests
samiuelson 553d120
Merge branch 'woomob-1069-woo-poslocal-catalog-update-ptr-behavior-fe…
samiuelson 1892909
Clean up code
samiuelson b00c544
Clean up code
samiuelson 6ad04db
Fix variation fetching in totals
samiuelson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...om/woocommerce/android/ui/woopos/home/items/products/WooPosProductsDataSourceInterface.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.woocommerce.android.ui.woopos.home.items.products | ||
|
||
import com.woocommerce.android.ui.woopos.common.data.models.WooPosProductModel | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface WooPosProductsDataSourceInterface { | ||
fun fetchFirstPage( | ||
searchQuery: String? = null, | ||
forceRefresh: Boolean | ||
): Flow<WooPosProductsDataSource.ProductsResult> | ||
|
||
suspend fun loadMore(): Result<List<WooPosProductModel>> | ||
|
||
val hasMorePages: Boolean | ||
|
||
suspend fun resetState() | ||
} |
59 changes: 59 additions & 0 deletions
59
...lin/com/woocommerce/android/ui/woopos/home/items/products/WooPosProductsInDbDataSource.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.woocommerce.android.ui.woopos.home.items.products | ||
|
||
import com.woocommerce.android.tools.SelectedSite | ||
import com.woocommerce.android.ui.woopos.common.data.models.WooPosProductModel | ||
import com.woocommerce.android.ui.woopos.common.data.models.WooPosProductModelMapper | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.flowOn | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.withContext | ||
import org.wordpress.android.fluxc.store.pos.localcatalog.WooPosLocalCatalogStore | ||
import javax.inject.Inject | ||
|
||
class WooPosProductsInDbDataSource @Inject constructor( | ||
private val posLocalCatalogStore: WooPosLocalCatalogStore, | ||
private val selectedSite: SelectedSite, | ||
private val mapper: WooPosProductModelMapper | ||
) : WooPosProductsDataSourceInterface { | ||
|
||
private fun getProductsFromDatabaseFlow(): Flow<List<WooPosProductModel>> { | ||
val siteModel = selectedSite.getOrNull() ?: return flow { emit(emptyList()) } | ||
val siteId = org.wordpress.android.fluxc.model.LocalOrRemoteId.LocalId(siteModel.id) | ||
|
||
return posLocalCatalogStore.observeProducts(siteId) | ||
.map { result -> | ||
result.getOrNull()?.map { entity -> | ||
mapper.fromEntity(entity) | ||
} ?: emptyList() | ||
} | ||
} | ||
|
||
override fun fetchFirstPage( | ||
searchQuery: String?, | ||
forceRefresh: Boolean | ||
): Flow<WooPosProductsDataSource.ProductsResult> = getProductsFromDatabaseFlow() | ||
.map { products -> | ||
val filteredProducts = if (searchQuery.isNullOrBlank()) { | ||
products | ||
} else { | ||
products.filter { product -> | ||
product.name.contains(searchQuery, ignoreCase = true) || product.sku.contains( | ||
searchQuery, | ||
ignoreCase = true | ||
) | ||
} | ||
} | ||
WooPosProductsDataSource.ProductsResult.Remote(Result.success(filteredProducts)) | ||
} | ||
samiuelson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
.flowOn(Dispatchers.IO) | ||
|
||
override suspend fun loadMore(): Result<List<WooPosProductModel>> = withContext(Dispatchers.IO) { | ||
Result.success(emptyList()) | ||
} | ||
|
||
override val hasMorePages: Boolean = false | ||
|
||
override suspend fun resetState() = Unit | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.