@@ -8,13 +8,8 @@ import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooError
8
8
import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooErrorType.GENERIC_ERROR
9
9
import org.wordpress.android.fluxc.network.rest.wpcom.wc.WooResult
10
10
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
13
11
import org.wordpress.android.fluxc.persistence.WCGlobalAttributeSqlUtils.getCurrentAttributes
14
12
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
18
13
import org.wordpress.android.fluxc.tools.CoroutineEngine
19
14
import org.wordpress.android.util.AppLog
20
15
import javax.inject.Inject
@@ -59,120 +54,6 @@ class WCGlobalAttributeStore @Inject constructor(
59
54
.result?.map { mapper.responseToAttributeTermModel(it, attributeID.toInt(), site) }
60
55
?.let { WooResult (it) }
61
56
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
-
176
57
companion object {
177
58
const val DEFAULT_PAGE_SIZE = 100
178
59
const val DEFAULT_PAGE_INDEX = 1
0 commit comments