Skip to content

Commit 2f1b0e7

Browse files
committed
Cleanup: Remove unused product attribute related store/rest/sql code
1 parent 6e07007 commit 2f1b0e7

File tree

8 files changed

+0
-588
lines changed

8 files changed

+0
-588
lines changed

libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/product/attributes/ProductAttributeRestClient.kt

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,6 @@ class ProductAttributeRestClient @Inject constructor(private val wooNetwork: Woo
1515
) = WOOCOMMERCE.products.attributes.pathV3
1616
.request<Array<AttributeApiResponse>>(site)
1717

18-
suspend fun fetchSingleAttribute(
19-
site: SiteModel,
20-
attributeID: Long
21-
) = WOOCOMMERCE.products.attributes.attribute(attributeID).pathV3
22-
.request<AttributeApiResponse>(site)
23-
24-
suspend fun postNewAttribute(
25-
site: SiteModel,
26-
args: Map<String, String>
27-
) = WOOCOMMERCE.products.attributes.pathV3
28-
.post<AttributeApiResponse>(site, args)
29-
30-
suspend fun updateExistingAttribute(
31-
site: SiteModel,
32-
attributeID: Long,
33-
args: Map<String, String>
34-
) = WOOCOMMERCE.products.attributes.attribute(attributeID).pathV3
35-
.put<AttributeApiResponse>(site, args)
36-
37-
suspend fun deleteExistingAttribute(
38-
site: SiteModel,
39-
attributeID: Long
40-
) = WOOCOMMERCE.products.attributes.attribute(attributeID).pathV3
41-
.delete<AttributeApiResponse>(site)
42-
4318
suspend fun fetchAllAttributeTerms(
4419
site: SiteModel,
4520
attributeID: Long,
@@ -54,28 +29,6 @@ class ProductAttributeRestClient @Inject constructor(private val wooNetwork: Woo
5429
)
5530
)
5631

57-
suspend fun postNewTerm(
58-
site: SiteModel,
59-
attributeID: Long,
60-
args: Map<String, String>
61-
) = WOOCOMMERCE.products.attributes.attribute(attributeID).terms.pathV3
62-
.post<AttributeTermApiResponse>(site, args)
63-
64-
suspend fun updateExistingTerm(
65-
site: SiteModel,
66-
args: Map<String, String>,
67-
attributeID: Long,
68-
termID: Long
69-
) = WOOCOMMERCE.products.attributes.attribute(attributeID).terms.term(termID).pathV3
70-
.put<AttributeTermApiResponse>(site, args)
71-
72-
suspend fun deleteExistingTerm(
73-
site: SiteModel,
74-
attributeID: Long,
75-
termID: Long
76-
) = WOOCOMMERCE.products.attributes.attribute(attributeID).terms.term(termID).pathV3
77-
.delete<AttributeTermApiResponse>(site)
78-
7932
private suspend inline fun <reified T : Any> String.request(
8033
site: SiteModel,
8134
params: Map<String, String> = emptyMap()
@@ -85,32 +38,4 @@ class ProductAttributeRestClient @Inject constructor(private val wooNetwork: Woo
8538
clazz = T::class.java,
8639
params = params
8740
).toWooPayload()
88-
89-
private suspend inline fun <reified T : Any> String.post(
90-
site: SiteModel,
91-
args: Map<String, String>
92-
) = wooNetwork.executeGetGsonRequest(
93-
site = site,
94-
path = this,
95-
clazz = T::class.java,
96-
params = args
97-
).toWooPayload()
98-
99-
private suspend inline fun <reified T : Any> String.put(
100-
site: SiteModel,
101-
args: Map<String, String>
102-
) = wooNetwork.executePostGsonRequest(
103-
site = site,
104-
path = this,
105-
clazz = T::class.java,
106-
body = args
107-
).toWooPayload()
108-
109-
private suspend inline fun <reified T : Any> String.delete(
110-
site: SiteModel
111-
) = wooNetwork.executeDeleteGsonRequest(
112-
site = site,
113-
path = this,
114-
clazz = T::class.java
115-
).toWooPayload()
11641
}

libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/persistence/WCGlobalAttributeSqlUtils.kt

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,49 +20,6 @@ object WCGlobalAttributeSqlUtils {
2020
.asSingleTransaction(true).execute()
2121
}
2222

23-
fun insertSingleAttribute(attribute: WCGlobalAttributeModel) = attribute.apply {
24-
WellSql.insert(attribute)
25-
.asSingleTransaction(true)
26-
.execute()
27-
}
28-
29-
fun fetchSingleStoredAttribute(attributeId: Int, siteID: Int) =
30-
WellSql.select(WCGlobalAttributeModel::class.java)
31-
.where().beginGroup()
32-
.equals(WCGlobalAttributeModelTable.REMOTE_ID, attributeId)
33-
.equals(WCGlobalAttributeModelTable.LOCAL_SITE_ID, siteID)
34-
.endGroup().endWhere()
35-
.asModel
36-
.takeIf { it.isNotEmpty() }
37-
?.first()
38-
39-
fun deleteSingleStoredAttribute(attribute: WCGlobalAttributeModel, siteID: Int) = attribute.apply {
40-
WellSql.delete(WCGlobalAttributeModel::class.java)
41-
.where().beginGroup()
42-
.equals(WCGlobalAttributeModelTable.REMOTE_ID, attribute.remoteId)
43-
.equals(WCGlobalAttributeModelTable.LOCAL_SITE_ID, siteID)
44-
.endGroup().endWhere()
45-
.execute()
46-
}
47-
48-
fun updateSingleStoredAttribute(attribute: WCGlobalAttributeModel, siteID: Int) = attribute.apply {
49-
WellSql.update(WCGlobalAttributeModel::class.java)
50-
.where().beginGroup()
51-
.equals(WCGlobalAttributeModelTable.REMOTE_ID, attribute.remoteId)
52-
.equals(WCGlobalAttributeModelTable.LOCAL_SITE_ID, siteID)
53-
.endGroup().endWhere()
54-
.put(attribute)
55-
.execute()
56-
}
57-
58-
fun insertOrUpdateSingleAttribute(attribute: WCGlobalAttributeModel, siteID: Int) =
59-
fetchSingleStoredAttribute(attribute.remoteId, siteID)
60-
?.let {
61-
attribute.id = it.id
62-
updateSingleStoredAttribute(attribute, siteID)
63-
}
64-
?: insertSingleAttribute(attribute)
65-
6623
private fun deleteCompleteAttributesList(siteID: Int) =
6724
WellSql.delete(WCGlobalAttributeModel::class.java)
6825
.where().beginGroup()

libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/store/WCGlobalAttributeStore.kt

Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@ import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooError
88
import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooErrorType.GENERIC_ERROR
99
import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooResult
1010
import org.wordpress.android.fluxc.network.rest.wpcom.wc.product.attributes.ProductAttributeRestClient
11-
import org.wordpress.android.fluxc.persistence.WCGlobalAttributeSqlUtils.deleteSingleStoredAttribute
12-
import org.wordpress.android.fluxc.persistence.WCGlobalAttributeSqlUtils.fetchSingleStoredAttribute
1311
import org.wordpress.android.fluxc.persistence.WCGlobalAttributeSqlUtils.getCurrentAttributes
1412
import org.wordpress.android.fluxc.persistence.WCGlobalAttributeSqlUtils.insertFromScratchCompleteAttributesList
15-
import org.wordpress.android.fluxc.persistence.WCGlobalAttributeSqlUtils.insertOrUpdateSingleAttribute
16-
import org.wordpress.android.fluxc.persistence.WCGlobalAttributeSqlUtils.insertSingleAttribute
17-
import org.wordpress.android.fluxc.persistence.WCGlobalAttributeSqlUtils.updateSingleStoredAttribute
1813
import org.wordpress.android.fluxc.tools.CoroutineEngine
1914
import org.wordpress.android.util.AppLog
2015
import javax.inject.Inject
@@ -59,120 +54,6 @@ class WCGlobalAttributeStore @Inject constructor(
5954
.result?.map { mapper.responseToAttributeTermModel(it, attributeID.toInt(), site) }
6055
?.let { WooResult(it) }
6156

62-
suspend fun fetchAttribute(
63-
site: SiteModel,
64-
attributeID: Long,
65-
withTerms: Boolean = false
66-
): WooResult<WCGlobalAttributeModel> =
67-
coroutineEngine.withDefaultContext(AppLog.T.API, this, "createStoreAttributes") {
68-
restClient.fetchSingleAttribute(site, attributeID)
69-
.asWooResult()
70-
.model
71-
?.let { mapper.responseToAttributeModel(it, site) }
72-
?.let { insertOrUpdateSingleAttribute(it, site.id) }
73-
?.apply { takeIf { withTerms }?.let { fetchAttributeTerms(site, attributeID) } }
74-
?.let { fetchSingleStoredAttribute(attributeID.toInt(), site.id) }
75-
?.let { WooResult(it) }
76-
?: WooResult(WooError(GENERIC_ERROR, UNKNOWN))
77-
}
78-
79-
suspend fun createAttribute(
80-
site: SiteModel,
81-
name: String,
82-
slug: String = name,
83-
type: String = "select",
84-
orderBy: String = "menu_order",
85-
hasArchives: Boolean = false
86-
): WooResult<WCGlobalAttributeModel> =
87-
coroutineEngine.withDefaultContext(AppLog.T.API, this, "createStoreAttributes") {
88-
restClient.postNewAttribute(
89-
site, mapOf(
90-
"name" to name,
91-
"slug" to slug,
92-
"type" to type,
93-
"order_by" to orderBy,
94-
"has_archives" to hasArchives.toString()
95-
)
96-
)
97-
.asWooResult()
98-
.model
99-
?.let { mapper.responseToAttributeModel(it, site) }
100-
?.let { insertSingleAttribute(it) }
101-
?.let { WooResult(it) }
102-
?: WooResult(WooError(GENERIC_ERROR, UNKNOWN))
103-
}
104-
105-
suspend fun updateAttribute(
106-
site: SiteModel,
107-
attributeID: Long,
108-
name: String,
109-
slug: String = name,
110-
type: String = "select",
111-
orderBy: String = "menu_order",
112-
hasArchives: Boolean = false
113-
): WooResult<WCGlobalAttributeModel> =
114-
coroutineEngine.withDefaultContext(AppLog.T.API, this, "updateStoreAttributes") {
115-
restClient.updateExistingAttribute(
116-
site, attributeID, mapOf(
117-
"id" to attributeID.toString(),
118-
"name" to name,
119-
"slug" to slug,
120-
"type" to type,
121-
"order_by" to orderBy,
122-
"has_archives" to hasArchives.toString()
123-
)
124-
)
125-
.asWooResult()
126-
.model
127-
?.let { mapper.responseToAttributeModel(it, site) }
128-
?.let { updateSingleStoredAttribute(it, site.id) }
129-
?.let { WooResult(it) }
130-
?: WooResult(WooError(GENERIC_ERROR, UNKNOWN))
131-
}
132-
133-
suspend fun deleteAttribute(
134-
site: SiteModel,
135-
attributeID: Long
136-
): WooResult<WCGlobalAttributeModel> =
137-
coroutineEngine.withDefaultContext(AppLog.T.API, this, "deleteStoreAttributes") {
138-
restClient.deleteExistingAttribute(site, attributeID)
139-
.asWooResult()
140-
.model
141-
?.let { mapper.responseToAttributeModel(it, site) }
142-
?.let { deleteSingleStoredAttribute(it, site.id) }
143-
?.let { WooResult(it) }
144-
?: WooResult(WooError(GENERIC_ERROR, UNKNOWN))
145-
}
146-
147-
suspend fun createOptionValueForAttribute(
148-
site: SiteModel,
149-
attributeID: Long,
150-
term: String
151-
): WooResult<WCGlobalAttributeModel> =
152-
coroutineEngine.withDefaultContext(AppLog.T.API, this, "createAttributeTerm") {
153-
restClient.postNewTerm(
154-
site, attributeID,
155-
mapOf("name" to term)
156-
)
157-
.asWooResult()
158-
.model
159-
?.let { fetchAttribute(site, attributeID) }
160-
?: WooResult(WooError(GENERIC_ERROR, UNKNOWN))
161-
}
162-
163-
suspend fun deleteOptionValueFromAttribute(
164-
site: SiteModel,
165-
attributeID: Long,
166-
termID: Long
167-
): WooResult<WCGlobalAttributeModel> =
168-
coroutineEngine.withDefaultContext(AppLog.T.API, this, "deleteAttributeTerm") {
169-
restClient.deleteExistingTerm(site, attributeID, termID)
170-
.asWooResult()
171-
.model
172-
?.let { fetchAttribute(site, attributeID) }
173-
?: WooResult(WooError(GENERIC_ERROR, UNKNOWN))
174-
}
175-
17657
companion object {
17758
const val DEFAULT_PAGE_SIZE = 100
17859
const val DEFAULT_PAGE_INDEX = 1

0 commit comments

Comments
 (0)