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 @@ -9,7 +9,7 @@ import com.woocommerce.android.ui.woopos.common.data.models.WooPosProductModel
import com.woocommerce.android.util.WooLog
import com.woocommerce.android.viewmodel.ResourceProvider
import org.wordpress.android.fluxc.model.WCProductVariationModel
import org.wordpress.android.fluxc.persistence.entity.pos.WCPosVariationModel
import org.wordpress.android.fluxc.persistence.entity.pos.WooPosVariationEntity
import javax.inject.Inject
import javax.inject.Singleton

Expand Down Expand Up @@ -74,7 +74,7 @@ class WooPosVariationMapper @Inject constructor(
}

@Suppress("SwallowedException")
fun fromWCPosVariationModel(model: WCPosVariationModel): WooPosVariation {
fun fromWooPosVariationEntity(model: WooPosVariationEntity): WooPosVariation {
val attributesList = parseAttributesJson(model.attributesJson)

return WooPosVariation(
Expand Down Expand Up @@ -162,8 +162,8 @@ fun ProductVariation.toWooPosVariation(mapper: WooPosVariationMapper): WooPosVar
fun WCProductVariationModel.toWooPosVariation(mapper: WooPosVariationMapper): WooPosVariation =
mapper.fromWCProductVariationModel(this)

fun WCPosVariationModel.toWooPosVariation(mapper: WooPosVariationMapper): WooPosVariation =
mapper.fromWCPosVariationModel(this)
fun WooPosVariationEntity.toWooPosVariation(mapper: WooPosVariationMapper): WooPosVariation =
mapper.fromWooPosVariationEntity(this)

fun WooPosVariation.getNameForPOS(
mapper: WooPosVariationMapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.google.gson.JsonSyntaxException
import com.google.gson.reflect.TypeToken
import com.woocommerce.android.ui.woopos.common.util.WooPosLogWrapper
import dagger.Reusable
import org.wordpress.android.fluxc.persistence.entity.pos.WCPosProductEntity
import org.wordpress.android.fluxc.persistence.entity.pos.WooPosProductEntity
import java.math.BigDecimal
import javax.inject.Inject

Expand All @@ -18,7 +18,7 @@ import javax.inject.Inject
@Reusable
class WooPosProductModelMapper @Inject constructor(val logger: WooPosLogWrapper) {
private val gson = Gson()
fun fromEntity(entity: WCPosProductEntity): WooPosProductModel {
fun fromEntity(entity: WooPosProductEntity): WooPosProductModel {
return WooPosProductModel(
remoteId = entity.remoteId.value,
parentId = entity.parentId,
Expand All @@ -45,7 +45,7 @@ class WooPosProductModelMapper @Inject constructor(val logger: WooPosLogWrapper)
)
}

fun fromEntities(entities: List<WCPosProductEntity>): List<WooPosProductModel> {
fun fromEntities(entities: List<WooPosProductEntity>): List<WooPosProductModel> {
return entities.map { fromEntity(it) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.mockito.Mockito.mock
import org.wordpress.android.fluxc.model.LocalOrRemoteId
import org.wordpress.android.fluxc.persistence.entity.pos.WCPosProductEntity
import org.wordpress.android.fluxc.persistence.entity.pos.WooPosProductEntity
import java.math.BigDecimal

@ExperimentalCoroutinesApi
Expand Down Expand Up @@ -44,7 +44,7 @@ class WooPosProductModelMapperTest : BaseUnitTest() {
@Test
fun `given entity with pricing information, when mapping to model, then pricing is handled correctly`() {
// Regular pricing only
var entity = WCPosProductEntity(
var entity = WooPosProductEntity(
remoteId = LocalOrRemoteId.RemoteId(123),
regularPrice = "25.99",
onSale = false
Expand All @@ -55,7 +55,7 @@ class WooPosProductModelMapperTest : BaseUnitTest() {
assertThat(regularPricing.price).isEqualTo(BigDecimal("25.99"))

// Sale pricing
entity = WCPosProductEntity(
entity = WooPosProductEntity(
remoteId = LocalOrRemoteId.RemoteId(123),
regularPrice = "29.99",
salePrice = "19.99",
Expand All @@ -68,7 +68,7 @@ class WooPosProductModelMapperTest : BaseUnitTest() {
assertThat(salePricing.salePrice).isEqualTo(BigDecimal("19.99"))

// No pricing
entity = WCPosProductEntity(
entity = WooPosProductEntity(
remoteId = LocalOrRemoteId.RemoteId(123),
price = "",
regularPrice = "",
Expand All @@ -82,7 +82,7 @@ class WooPosProductModelMapperTest : BaseUnitTest() {

@Test
fun `given entity with invalid price format, when mapping to model, then pricing defaults to NoPricing`() {
val entity = WCPosProductEntity(
val entity = WooPosProductEntity(
remoteId = LocalOrRemoteId.RemoteId(123),
price = "invalid",
regularPrice = "not-a-number",
Expand All @@ -99,7 +99,7 @@ class WooPosProductModelMapperTest : BaseUnitTest() {
@Test
fun `given entity with JSON images, when mapping to model, then images are parsed correctly`() {
val imagesJson = """[{"id": 1, "src": "https://example.com/image.jpg", "name": "Image 1", "alt": "Alt text"}]"""
val entity = WCPosProductEntity(
val entity = WooPosProductEntity(
remoteId = LocalOrRemoteId.RemoteId(123),
images = imagesJson
)
Expand All @@ -117,7 +117,7 @@ class WooPosProductModelMapperTest : BaseUnitTest() {

@Test
fun `given entity with malformed JSON, when mapping to model, then returns empty collections gracefully`() {
val entity = WCPosProductEntity(
val entity = WooPosProductEntity(
remoteId = LocalOrRemoteId.RemoteId(123),
images = "malformed json",
attributes = "invalid json",
Expand All @@ -135,7 +135,7 @@ class WooPosProductModelMapperTest : BaseUnitTest() {

@Test
fun `given entity with empty JSON collections, when mapping to model, then returns empty lists`() {
val entity = WCPosProductEntity(
val entity = WooPosProductEntity(
remoteId = LocalOrRemoteId.RemoteId(123),
images = "",
attributes = "",
Expand All @@ -155,7 +155,7 @@ class WooPosProductModelMapperTest : BaseUnitTest() {
fun `given entity with valid JSON attributes, when mapping to model, then attributes are parsed correctly`() {
val attributesJson =
"""[{"id": 1, "name": "Color", "options": ["Red", "Blue"], "visible": true, "variation": false}]"""
val entity = WCPosProductEntity(
val entity = WooPosProductEntity(
remoteId = LocalOrRemoteId.RemoteId(123),
attributes = attributesJson
)
Expand All @@ -174,7 +174,7 @@ class WooPosProductModelMapperTest : BaseUnitTest() {

@Test
fun `given product model with JSON collections, when accessing multiple times, then returns same parsed data`() {
val entity = WCPosProductEntity(
val entity = WooPosProductEntity(
remoteId = LocalOrRemoteId.RemoteId(123),
images = """[{"id": 1, "src": "test.jpg"}]""",
attributes = """[{"id": 2, "name": "Size"}]"""
Expand Down Expand Up @@ -232,7 +232,7 @@ class WooPosProductModelMapperTest : BaseUnitTest() {
)

testCases.forEach { (typeString, expectedType) ->
val entity = WCPosProductEntity(
val entity = WooPosProductEntity(
remoteId = LocalOrRemoteId.RemoteId(123),
type = typeString
)
Expand All @@ -255,7 +255,7 @@ class WooPosProductModelMapperTest : BaseUnitTest() {
)

testCases.forEach { (statusString, expectedStatus) ->
val entity = WCPosProductEntity(
val entity = WooPosProductEntity(
remoteId = LocalOrRemoteId.RemoteId(123),
status = statusString
)
Expand Down Expand Up @@ -317,7 +317,7 @@ class WooPosProductModelMapperTest : BaseUnitTest() {
assertThat(mapper.mapProductStatus("unknown")).isEqualTo(WooPosProductModel.WooPosProductStatus.UNKNOWN)
}

private fun createCompleteEntity() = WCPosProductEntity(
private fun createCompleteEntity() = WooPosProductEntity(
localSiteId = LocalOrRemoteId.LocalId(1),
remoteId = LocalOrRemoteId.RemoteId(123),
name = "Test Product",
Expand All @@ -342,7 +342,7 @@ class WooPosProductModelMapperTest : BaseUnitTest() {
dateModified = "2023-01-01T00:00:00"
)

private fun createMinimalEntity(id: Long) = WCPosProductEntity(
private fun createMinimalEntity(id: Long) = WooPosProductEntity(
remoteId = LocalOrRemoteId.RemoteId(id)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ typealias ProductDto = ProductApiResponse
@Suppress("ConstructorParameterNaming")
data class ProductApiResponse(
val id: Long? = null,
val localSiteId: Int = 0,
val name: String? = null,
val slug: String? = null,
val permalink: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package org.wordpress.android.fluxc.network.rest.wpcom.wc.product.pos
import org.wordpress.android.fluxc.model.LocalOrRemoteId
import org.wordpress.android.fluxc.model.pos.WooPosVariationApiResponse
import org.wordpress.android.fluxc.network.rest.wpcom.wc.product.ProductApiResponse
import org.wordpress.android.fluxc.persistence.entity.pos.WCPosProductEntity
import org.wordpress.android.fluxc.persistence.entity.pos.WCPosVariationModel
import org.wordpress.android.fluxc.persistence.entity.pos.WooPosProductEntity
import org.wordpress.android.fluxc.persistence.entity.pos.WooPosVariationEntity

@Suppress("CyclomaticComplexMethod")
fun ProductApiResponse.mapToPOSEntity(): WCPosProductEntity =
WCPosProductEntity(
localSiteId = LocalOrRemoteId.LocalId(this.localSiteId),
fun ProductApiResponse.mapToWooPOSEntity(localSiteId: LocalOrRemoteId.LocalId): WooPosProductEntity =
WooPosProductEntity(
localSiteId = localSiteId,
remoteId = LocalOrRemoteId.RemoteId(this.id ?: 0),
name = this.name ?: "",
dateModified = this.date_modified ?: "",
Expand Down Expand Up @@ -40,8 +40,8 @@ fun ProductApiResponse.mapToPOSEntity(): WCPosProductEntity =

fun WooPosVariationApiResponse.mapToPosVariationModel(
localSiteId: LocalOrRemoteId.LocalId
): WCPosVariationModel {
return WCPosVariationModel(
): WooPosVariationEntity {
return WooPosVariationEntity(
localSiteId = localSiteId,
remoteProductId = LocalOrRemoteId.RemoteId(this.productId),
remoteVariationId = LocalOrRemoteId.RemoteId(this.id),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ import org.wordpress.android.fluxc.persistence.entity.WooPaymentsManualDepositEn
import org.wordpress.android.fluxc.persistence.entity.WooShippingLabelEntity
import org.wordpress.android.fluxc.persistence.entity.WooShippingPackagesEntity
import org.wordpress.android.fluxc.persistence.entity.WooShippingShipmentEntity
import org.wordpress.android.fluxc.persistence.entity.pos.WCPosProductEntity
import org.wordpress.android.fluxc.persistence.entity.pos.WCPosVariationModel
import org.wordpress.android.fluxc.persistence.entity.pos.WooPosProductEntity
import org.wordpress.android.fluxc.persistence.entity.pos.WooPosVariationEntity
import org.wordpress.android.fluxc.persistence.migrations.AutoMigration13to14
import org.wordpress.android.fluxc.persistence.migrations.AutoMigration14to15
import org.wordpress.android.fluxc.persistence.migrations.AutoMigration16to17
Expand Down Expand Up @@ -145,8 +145,8 @@ const val WC_DATABASE_VERSION = 64
ShippingMethodEntity::class,
CustomerFromAnalyticsEntity::class,
WCProductModel::class,
WCPosProductEntity::class,
WCPosVariationModel::class,
WooPosProductEntity::class,
WooPosVariationEntity::class,
WCProductCategoryModel::class,
WCProductVariationModel::class,
WCProductTagModel::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import androidx.room.Upsert
import kotlinx.coroutines.flow.Flow
import org.wordpress.android.fluxc.model.LocalOrRemoteId.LocalId
import org.wordpress.android.fluxc.model.LocalOrRemoteId.RemoteId
import org.wordpress.android.fluxc.persistence.entity.pos.WCPosProductEntity
import org.wordpress.android.fluxc.persistence.entity.pos.WooPosProductEntity

@Dao
abstract class WooPosProductsDao {
@Query("SELECT * FROM PosProductEntity WHERE localSiteId = :localSiteId")
abstract fun observeAllProducts(localSiteId: LocalId): Flow<List<WCPosProductEntity>>
abstract fun observeAllProducts(localSiteId: LocalId): Flow<List<WooPosProductEntity>>

@Query("SELECT * FROM PosProductEntity WHERE localSiteId = :localSiteId AND remoteId = :remoteId")
abstract suspend fun getProduct(localSiteId: LocalId, remoteId: RemoteId): WCPosProductEntity?
abstract suspend fun getProduct(localSiteId: LocalId, remoteId: RemoteId): WooPosProductEntity?

@Upsert
abstract suspend fun upsertProducts(products: List<WCPosProductEntity>)
abstract suspend fun upsertProducts(products: List<WooPosProductEntity>)

@Query("DELETE FROM PosProductEntity WHERE localSiteId = :localSiteId AND remoteId = :remoteId")
abstract suspend fun deleteProduct(localSiteId: LocalId, remoteId: RemoteId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,29 @@ import androidx.room.Upsert
import kotlinx.coroutines.flow.Flow
import org.wordpress.android.fluxc.model.LocalOrRemoteId.LocalId
import org.wordpress.android.fluxc.model.LocalOrRemoteId.RemoteId
import org.wordpress.android.fluxc.persistence.entity.pos.WCPosVariationModel
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")
abstract fun observeVariationsForProduct(localSiteId: LocalId, productId: RemoteId): Flow<List<WCPosVariationModel>>
abstract fun observeVariationsForProduct(
localSiteId: LocalId,
productId: RemoteId
): Flow<List<WooPosVariationEntity>>

@Query("SELECT * FROM PosVariationEntity WHERE localSiteId = :localSiteId AND remoteProductId = :productId AND remoteVariationId = :variationId")
abstract suspend fun getVariation(
localSiteId: LocalId,
productId: RemoteId,
variationId: RemoteId
): WCPosVariationModel?
): WooPosVariationEntity?

@Upsert
abstract suspend fun upsertVariations(variations: List<WCPosVariationModel>)
abstract suspend fun upsertVariations(variations: List<WooPosVariationEntity>)

@Upsert
abstract suspend fun upsertVariation(variation: WCPosVariationModel)
abstract suspend fun upsertVariation(variation: WooPosVariationEntity)

@Query("DELETE FROM PosVariationEntity WHERE localSiteId = :localSiteId AND remoteProductId = :productId AND remoteVariationId = :variationId")
abstract suspend fun deleteVariation(localSiteId: LocalId, productId: RemoteId, variationId: RemoteId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.wordpress.android.fluxc.model.LocalOrRemoteId.RemoteId
tableName = "PosProductEntity",
primaryKeys = ["localSiteId", "remoteId"],
)
data class WCPosProductEntity(
data class WooPosProductEntity(
val localSiteId: LocalId = LocalId(0),
val remoteId: RemoteId = RemoteId(0),
val name: String = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.wordpress.android.fluxc.model.LocalOrRemoteId.RemoteId
tableName = "PosVariationEntity",
primaryKeys = ["localSiteId", "remoteProductId", "remoteVariationId"],
)
data class WCPosVariationModel(
data class WooPosVariationEntity(
val localSiteId: LocalId = LocalId(0),
val remoteProductId: RemoteId = RemoteId(0),
val remoteVariationId: RemoteId = RemoteId(0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooError
import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooErrorType
import org.wordpress.android.fluxc.network.rest.wpcom.wc.product.pos.WooPosProductRestClient
import org.wordpress.android.fluxc.network.rest.wpcom.wc.product.pos.mapToPOSEntity
import org.wordpress.android.fluxc.network.rest.wpcom.wc.product.pos.mapToPosVariationModel
import org.wordpress.android.fluxc.network.rest.wpcom.wc.product.pos.mapToWooPOSEntity
import org.wordpress.android.fluxc.persistence.WCAndroidDatabase
import org.wordpress.android.fluxc.persistence.dao.pos.WooPosProductsDao
import org.wordpress.android.fluxc.persistence.dao.pos.WooPosVariationsDao
import org.wordpress.android.fluxc.persistence.entity.pos.WCPosProductEntity
import org.wordpress.android.fluxc.persistence.entity.pos.WCPosVariationModel
import org.wordpress.android.fluxc.persistence.entity.pos.WooPosProductEntity
import org.wordpress.android.fluxc.persistence.entity.pos.WooPosVariationEntity
import org.wordpress.android.fluxc.tools.CoroutineEngine
import org.wordpress.android.fluxc.utils.HeadersParser
import org.wordpress.android.util.AppLog.T.API
Expand Down Expand Up @@ -42,7 +42,7 @@ class WooPosLocalCatalogStore @Inject constructor(
*/
fun observeProducts(
siteId: LocalOrRemoteId.LocalId
): Flow<Result<List<WCPosProductEntity>>> =
): Flow<Result<List<WooPosProductEntity>>> =
posProductDao.observeAllProducts(siteId)
.map { products ->
Result.success(products)
Expand All @@ -58,7 +58,7 @@ class WooPosLocalCatalogStore @Inject constructor(
suspend fun getProduct(
siteId: LocalOrRemoteId.LocalId,
remoteProductId: LocalOrRemoteId.RemoteId
): Result<WCPosProductEntity?> =
): Result<WooPosProductEntity?> =
coroutineEngine.withDefaultContext(API, this, "getProduct") {
val product = posProductDao.getProduct(siteId, remoteProductId)
Result.success(product)
Expand Down Expand Up @@ -128,7 +128,7 @@ class WooPosLocalCatalogStore @Inject constructor(
)

else -> {
val products = response.model.map { it.mapToPOSEntity() }
val products = response.model.map { it.mapToWooPOSEntity(site.localId()) }

if (storeInDb) {
val upsertResult = runCatching { posProductDao.upsertProducts(products) }
Expand Down Expand Up @@ -178,7 +178,7 @@ class WooPosLocalCatalogStore @Inject constructor(
fun observeVariationsForProduct(
siteId: LocalOrRemoteId.LocalId,
productId: LocalOrRemoteId.RemoteId
): Flow<Result<List<WCPosVariationModel>>> =
): Flow<Result<List<WooPosVariationEntity>>> =
posVariationsDao.observeVariationsForProduct(siteId, productId)
.map { variations ->
Result.success(variations)
Expand All @@ -196,7 +196,7 @@ class WooPosLocalCatalogStore @Inject constructor(
siteId: LocalOrRemoteId.LocalId,
productId: LocalOrRemoteId.RemoteId,
variationId: LocalOrRemoteId.RemoteId
): Result<WCPosVariationModel?> =
): Result<WooPosVariationEntity?> =
coroutineEngine.withDefaultContext(API, this, "getVariation") {
val variation = posVariationsDao.getVariation(siteId, productId, variationId)
Result.success(variation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.robolectric.RobolectricTestRunner
import org.wordpress.android.fluxc.model.LocalOrRemoteId.LocalId
import org.wordpress.android.fluxc.model.LocalOrRemoteId.RemoteId
import org.wordpress.android.fluxc.persistence.DatabaseTestRule
import org.wordpress.android.fluxc.persistence.entity.pos.WCPosProductEntity
import org.wordpress.android.fluxc.persistence.entity.pos.WooPosProductEntity
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull
Expand Down Expand Up @@ -265,7 +265,7 @@ class WooPosProductsDaoTest {
attributes: String = "",
images: String = "",
dateModified: String = "2024-01-01T10:00:00Z"
) = WCPosProductEntity(
) = WooPosProductEntity(
localSiteId = LocalId(siteId),
remoteId = RemoteId(remoteId),
name = name,
Expand Down
Loading
Loading