Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.wordpress.android.fluxc.store.WCProductStore.DownloadableOptions
import org.wordpress.android.fluxc.store.WCProductStore.ProductFilterOption
import javax.inject.Inject

// Note: For the Local Catalog feature, the filtering is done locally in WooPosProductsDao.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing the comment, I assume you considered reusing this for the filteriting to have a single source of truth for the whole POS; therefore, just curious why you didn't go with that approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I couldn't figure out a way on how to re-use it.

  1. We likely want to filter on the DB layer for performance/memory reasons.
  2. This config lives in a different module than the DB -> we can't create a circular dependency.
  3. Room queries can reference only constants.
    Wdyt? Can you think of a way on how to re-use it?

class WooPosProductsTypesFilterConfig @Inject constructor() {
val filters: Map<ProductFilterOption, String> =
mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.wordpress.android.fluxc.store.WCProductStore.DownloadableOptions
import org.wordpress.android.fluxc.store.WCProductStore.VariationFilterOption
import javax.inject.Inject

// Note: For the Local Catalog feature, the filtering is done locally in WooPosVariationsDao.
class WooPosVariationsTypesFilterConfig @Inject constructor() {
val filters: Map<VariationFilterOption, String> =
mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,11 @@ class WooPosVariationsInDbDataSource @Inject constructor(
forceRefresh: Boolean
): Flow<FetchResult> = getVariationsFromDatabaseFlow(productId)
.map { variations ->
FetchResult.Remote(Result.success(variations.applyFilter()))
FetchResult.Remote(Result.success(variations))
}
.flowOn(Dispatchers.IO)

override suspend fun loadMore(productId: Long): Result<List<WooPosVariation>> = withContext(Dispatchers.IO) {
Result.success(emptyList())
}
}

private fun List<WooPosVariation>.applyFilter(): List<WooPosVariation> {
return filter { !it.isDownloadable }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,21 @@ import org.wordpress.android.fluxc.persistence.entity.pos.WooPosProductEntity

@Dao
abstract class WooPosProductsDao {
@Query("SELECT * FROM PosProductEntity WHERE localSiteId = :localSiteId ORDER BY LOWER(name)")
companion object {
private const val PRODUCT_STATUS_PUBLISH = "publish"
private const val PRODUCT_TYPE_SIMPLE = "simple"
private const val PRODUCT_TYPE_VARIABLE = "variable"
private const val DOWNLOADABLE_FALSE = 0
}

@Query(
"SELECT * FROM PosProductEntity " +
"WHERE localSiteId = :localSiteId " +
"AND status = '$PRODUCT_STATUS_PUBLISH' " +
"AND (type = '$PRODUCT_TYPE_SIMPLE' OR type = '$PRODUCT_TYPE_VARIABLE') " +
"AND downloadable = '$DOWNLOADABLE_FALSE' " +
"ORDER BY LOWER(name)"
)
abstract fun observeAllProducts(localSiteId: LocalId): Flow<List<WooPosProductEntity>>

@Query("SELECT * FROM PosProductEntity WHERE localSiteId = :localSiteId AND remoteId = :remoteId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@ import org.wordpress.android.fluxc.persistence.entity.pos.WooPosVariationEntity

@Dao
abstract class WooPosVariationsDao {

@Query("SELECT * FROM PosVariationEntity WHERE localSiteId = :localSiteId AND remoteProductId = :productId ORDER BY variationName ASC")
companion object {
private const val VARIATION_STATUS_PUBLISH = "publish"
private const val DOWNLOADABLE_FALSE = 0
}

@Query(
"SELECT * FROM PosVariationEntity " +
"WHERE localSiteId = :localSiteId " +
"AND remoteProductId = :productId " +
"AND status = '$VARIATION_STATUS_PUBLISH' " +
"AND downloadable = '$DOWNLOADABLE_FALSE' " +
"ORDER BY variationName ASC"
)
abstract fun observeVariationsForProduct(
localSiteId: Int,
productId: Long
Expand Down
Loading