Skip to content

[WellSQL Migration] Migrate WCGlobalAttributeModel to Room #14464

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
wants to merge 12 commits into
base: trunk
Choose a base branch
from
Open
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 @@ -2,35 +2,33 @@ package com.woocommerce.android.model

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import org.wordpress.android.fluxc.model.LocalOrRemoteId.LocalId
import org.wordpress.android.fluxc.model.LocalOrRemoteId.RemoteId
import org.wordpress.android.fluxc.model.attribute.WCGlobalAttributeModel

/**
* Represents a global attribute, which is an attribute available store-wide
*/
@Parcelize
data class ProductGlobalAttribute(
val id: Int,
val localSiteId: Int,
val name: String,
val slug: String,
val type: String,
val orderBy: String,
val hasArchives: Boolean,
val termsId: String,
val remoteId: Long
) : Parcelable {
fun toDataModel(cachedAttribute: WCGlobalAttributeModel? = null): WCGlobalAttributeModel {
return (cachedAttribute ?: WCGlobalAttributeModel()).also {
it.id = id
it.localSiteId = localSiteId
it.name = name
it.slug = slug
it.type = type
it.orderBy = orderBy
it.hasArchives = hasArchives
it.termsId = termsId
it.remoteId = remoteId.toInt()
}
return cachedAttribute ?: WCGlobalAttributeModel(
siteId = LocalId(localSiteId),
remoteId = RemoteId(remoteId),
name = name,
slug = slug,
type = type,
orderBy = orderBy,
hasArchives = hasArchives,
)
}

/**
Expand All @@ -50,14 +48,12 @@ data class ProductGlobalAttribute(

fun WCGlobalAttributeModel.toAppModel(): ProductGlobalAttribute {
return ProductGlobalAttribute(
id = this.id,
remoteId = this.remoteId.toLong(),
localSiteId = this.localSiteId,
remoteId = this.remoteId.value,
localSiteId = this.siteId.value,
name = this.name,
slug = this.slug,
type = this.type,
orderBy = this.orderBy,
hasArchives = this.hasArchives,
termsId = this.termsId
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class ProductDetailRepository @Inject constructor(
/**
* Returns a list of global attributes from the local db
*/
fun getGlobalAttributes(): List<ProductGlobalAttribute> {
suspend fun getGlobalAttributes(): List<ProductGlobalAttribute> {
val wooResult = globalAttributeStore.loadCachedStoreAttributes(selectedSite.get())
return wooResult.model?.map { it.toAppModel() } ?: emptyList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1903,7 +1903,7 @@ class ProductDetailViewModel @Inject constructor(
}
}

fun loadGlobalAttributes(): List<ProductGlobalAttribute> =
suspend fun loadGlobalAttributes(): List<ProductGlobalAttribute> =
productRepository.getGlobalAttributes()

/**
Expand Down
Loading