diff --git a/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt b/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt index 4014d63439..44849397ab 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClientTest.kt @@ -20,6 +20,7 @@ import org.mockito.junit.MockitoJUnitRunner import org.wordpress.android.fluxc.Dispatcher import org.wordpress.android.fluxc.UnitTestUtils import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.fluxc.model.dashboard.CardModel import org.wordpress.android.fluxc.network.BaseRequest.BaseNetworkError import org.wordpress.android.fluxc.network.BaseRequest.GenericErrorType import org.wordpress.android.fluxc.network.UserAgent @@ -31,6 +32,7 @@ import org.wordpress.android.fluxc.network.rest.wpcom.auth.AccessToken import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.CardsResponse import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.PostResponse import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.PostsResponse +import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.TodaysStatsResponse import org.wordpress.android.fluxc.store.dashboard.CardsStore.CardsErrorType import org.wordpress.android.fluxc.store.dashboard.CardsStore.CardsPayload import org.wordpress.android.fluxc.test @@ -39,8 +41,19 @@ import org.wordpress.android.fluxc.test private const val DATE_FORMAT_PATTERN = "yyyy-MM-dd HH:mm:ss" +/* CARD TYPES */ + +private val CARD_TYPES = listOf(CardModel.Type.TODAYS_STATS, CardModel.Type.POSTS) + /* RESPONSE */ +private val TODAYS_STATS_RESPONSE = TodaysStatsResponse( + views = 100, + visitors = 30, + likes = 50, + comments = 10 +) + private val DRAFT_POST_RESPONSE_TWO = PostResponse( id = 708, title = "", @@ -77,6 +90,7 @@ private val POSTS_RESPONSE = PostsResponse( ) private val CARDS_RESPONSE = CardsResponse( + todaysStats = TODAYS_STATS_RESPONSE, posts = POSTS_RESPONSE ) @@ -90,6 +104,7 @@ class CardsRestClientTest { @Mock private lateinit var site: SiteModel private lateinit var urlCaptor: KArgumentCaptor + private lateinit var paramsCaptor: KArgumentCaptor> private lateinit var restClient: CardsRestClient private val siteId: Long = 1 @@ -97,6 +112,7 @@ class CardsRestClientTest { @Before fun setUp() { urlCaptor = argumentCaptor() + paramsCaptor = argumentCaptor() restClient = CardsRestClient( wpComGsonRequestBuilder, dispatcher, @@ -112,7 +128,7 @@ class CardsRestClientTest { val json = UnitTestUtils.getStringFromResourceFile(javaClass, DASHBOARD_CARDS_JSON) initFetchCards(data = getCardsResponseFromJsonString(json)) - restClient.fetchCards(site) + restClient.fetchCards(site, CARD_TYPES) assertEquals(urlCaptor.firstValue, "$API_SITE_PATH/${site.siteId}/$API_DASHBOARD_CARDS_PATH") } @@ -122,7 +138,7 @@ class CardsRestClientTest { val json = UnitTestUtils.getStringFromResourceFile(javaClass, DASHBOARD_CARDS_JSON) initFetchCards(data = getCardsResponseFromJsonString(json)) - val result = restClient.fetchCards(site) + val result = restClient.fetchCards(site, CARD_TYPES) assertSuccess(CARDS_RESPONSE, result) } @@ -131,7 +147,7 @@ class CardsRestClientTest { fun `given timeout, when fetch cards gets triggered, then return cards timeout error`() = test { initFetchCards(error = WPComGsonNetworkError(BaseNetworkError(GenericErrorType.TIMEOUT))) - val result = restClient.fetchCards(site) + val result = restClient.fetchCards(site, CARD_TYPES) assertError(CardsErrorType.TIMEOUT, result) } @@ -140,7 +156,7 @@ class CardsRestClientTest { fun `given network error, when fetch cards gets triggered, then return cards api error`() = test { initFetchCards(error = WPComGsonNetworkError(BaseNetworkError(GenericErrorType.NETWORK_ERROR))) - val result = restClient.fetchCards(site) + val result = restClient.fetchCards(site, CARD_TYPES) assertError(CardsErrorType.API_ERROR, result) } @@ -149,7 +165,7 @@ class CardsRestClientTest { fun `given invalid response, when fetch cards gets triggered, then return cards invalid response error`() = test { initFetchCards(error = WPComGsonNetworkError(BaseNetworkError(GenericErrorType.INVALID_RESPONSE))) - val result = restClient.fetchCards(site) + val result = restClient.fetchCards(site, CARD_TYPES) assertError(CardsErrorType.INVALID_RESPONSE, result) } @@ -158,7 +174,7 @@ class CardsRestClientTest { fun `given not authenticated, when fetch cards gets triggered, then return cards auth required error`() = test { initFetchCards(error = WPComGsonNetworkError(BaseNetworkError(GenericErrorType.NOT_AUTHENTICATED))) - val result = restClient.fetchCards(site) + val result = restClient.fetchCards(site, CARD_TYPES) assertError(CardsErrorType.AUTHORIZATION_REQUIRED, result) } @@ -167,7 +183,7 @@ class CardsRestClientTest { fun `given unknown error, when fetch cards gets triggered, then return cards generic error`() = test { initFetchCards(error = WPComGsonNetworkError(BaseNetworkError(GenericErrorType.UNKNOWN))) - val result = restClient.fetchCards(site) + val result = restClient.fetchCards(site, CARD_TYPES) assertError(CardsErrorType.GENERIC_ERROR, result) } @@ -188,7 +204,7 @@ class CardsRestClientTest { wpComGsonRequestBuilder.syncGetRequest( eq(restClient), urlCaptor.capture(), - eq(mapOf()), + paramsCaptor.capture(), eq(CardsResponse::class.java), eq(false), any(), @@ -226,7 +242,7 @@ class CardsRestClientTest { companion object { private const val API_BASE_PATH = "https://public-api.wordpress.com/wpcom/v2" private const val API_SITE_PATH = "$API_BASE_PATH/sites" - private const val API_DASHBOARD_CARDS_PATH = "dashboard/cards/" + private const val API_DASHBOARD_CARDS_PATH = "dashboard/cards-data/" private const val DASHBOARD_CARDS_JSON = "wp/dashboard/cards.json" } diff --git a/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt b/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt index a4b850a983..20a77065da 100644 --- a/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt +++ b/example/src/test/java/org/wordpress/android/fluxc/store/dashboard/CardsStoreTest.kt @@ -14,10 +14,12 @@ import org.wordpress.android.fluxc.model.SiteModel import org.wordpress.android.fluxc.model.dashboard.CardModel import org.wordpress.android.fluxc.model.dashboard.CardModel.PostsCardModel import org.wordpress.android.fluxc.model.dashboard.CardModel.PostsCardModel.PostCardModel +import org.wordpress.android.fluxc.model.dashboard.CardModel.TodaysStatsCardModel import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.CardsResponse import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.PostResponse import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.PostsResponse +import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsRestClient.TodaysStatsResponse import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsUtils import org.wordpress.android.fluxc.persistence.dashboard.CardsDao import org.wordpress.android.fluxc.persistence.dashboard.CardsDao.CardEntity @@ -34,6 +36,13 @@ import kotlin.test.assertNull const val SITE_LOCAL_ID = 1 +/* TODAY'S STATS */ + +const val TODAYS_STATS_VIEWS = 100 +const val TODAYS_STATS_VISITORS = 30 +const val TODAYS_STATS_LIKES = 50 +const val TODAYS_STATS_COMMENTS = 10 + /* POST */ const val POST_ID = 1 @@ -42,8 +51,19 @@ const val POST_CONTENT = "content" const val POST_FEATURED_IMAGE = "featuredImage" const val POST_DATE = "2021-12-27 11:33:55" +/* CARD TYPES */ + +private val CARD_TYPES = listOf(CardModel.Type.TODAYS_STATS, CardModel.Type.POSTS) + /* RESPONSE */ +private val TODAYS_STATS_RESPONSE = TodaysStatsResponse( + views = TODAYS_STATS_VIEWS, + visitors = TODAYS_STATS_VISITORS, + likes = TODAYS_STATS_LIKES, + comments = TODAYS_STATS_COMMENTS +) + private val POST_RESPONSE = PostResponse( id = POST_ID, title = POST_TITLE, @@ -59,10 +79,17 @@ private val POSTS_RESPONSE = PostsResponse( ) private val CARDS_RESPONSE = CardsResponse( + todaysStats = TODAYS_STATS_RESPONSE, posts = POSTS_RESPONSE ) /* MODEL */ +private val TODAYS_STATS_MODEL = TodaysStatsCardModel( + views = TODAYS_STATS_VIEWS, + visitors = TODAYS_STATS_VISITORS, + likes = TODAYS_STATS_LIKES, + comments = TODAYS_STATS_COMMENTS +) private val POST_MODEL = PostCardModel( id = POST_ID, @@ -79,10 +106,17 @@ private val POSTS_MODEL = PostsCardModel( ) private val CARDS_MODEL = listOf( + TODAYS_STATS_MODEL, POSTS_MODEL ) /* ENTITY */ +private val TODAYS_STATS_ENTITY = CardEntity( + siteLocalId = SITE_LOCAL_ID, + type = CardModel.Type.TODAYS_STATS.name, + date = CardsUtils.getInsertDate(), + json = CardsUtils.GSON.toJson(TODAYS_STATS_MODEL) +) private val POSTS_ENTITY = CardEntity( siteLocalId = SITE_LOCAL_ID, @@ -92,6 +126,7 @@ private val POSTS_ENTITY = CardEntity( ) private val CARDS_ENTITY = listOf( + TODAYS_STATS_ENTITY, POSTS_ENTITY ) @@ -118,21 +153,41 @@ class CardsStoreTest { } @Test - fun `given cards response, when fetch cards gets triggered, then cards model is inserted into db`() = test { + fun `given all card types, when fetch cards triggered, then all cards model is inserted into db`() = test { val payload = CardsPayload(CARDS_RESPONSE) - whenever(restClient.fetchCards(siteModel)).thenReturn(payload) + whenever(restClient.fetchCards(siteModel, CARD_TYPES)).thenReturn(payload) - cardsStore.fetchCards(siteModel) + cardsStore.fetchCards(siteModel, CARD_TYPES) verify(dao).insertWithDate(siteModel.id, CARDS_MODEL) } + @Test + fun `given todays stats type, when fetch cards triggered, then today's stats card model inserted into db`() = test { + val payload = CardsPayload(CardsResponse(todaysStats = TODAYS_STATS_RESPONSE)) + whenever(restClient.fetchCards(siteModel, listOf(CardModel.Type.TODAYS_STATS))).thenReturn(payload) + + cardsStore.fetchCards(siteModel, listOf(CardModel.Type.TODAYS_STATS)) + + verify(dao).insertWithDate(siteModel.id, listOf(TODAYS_STATS_MODEL)) + } + + @Test + fun `given posts type, when fetch cards triggered, then post card model inserted into db`() = test { + val payload = CardsPayload(CardsResponse(posts = POSTS_RESPONSE)) + whenever(restClient.fetchCards(siteModel, listOf(CardModel.Type.POSTS))).thenReturn(payload) + + cardsStore.fetchCards(siteModel, listOf(CardModel.Type.POSTS)) + + verify(dao).insertWithDate(siteModel.id, listOf(POSTS_MODEL)) + } + @Test fun `given cards response, when fetch cards gets triggered, then empty cards model is returned`() = test { val payload = CardsPayload(CARDS_RESPONSE) - whenever(restClient.fetchCards(siteModel)).thenReturn(payload) + whenever(restClient.fetchCards(siteModel, CARD_TYPES)).thenReturn(payload) - val result = cardsStore.fetchCards(siteModel) + val result = cardsStore.fetchCards(siteModel, CARD_TYPES) assertThat(result.model).isNull() assertThat(result.error).isNull() @@ -141,10 +196,10 @@ class CardsStoreTest { @Test fun `given card response with exception, when fetch cards gets triggered, then cards error is returned`() = test { val payload = CardsPayload(CARDS_RESPONSE) - whenever(restClient.fetchCards(siteModel)).thenReturn(payload) + whenever(restClient.fetchCards(siteModel, CARD_TYPES)).thenReturn(payload) whenever(dao.insertWithDate(siteModel.id, CARDS_MODEL)).thenThrow(IllegalStateException("Error")) - val result = cardsStore.fetchCards(siteModel) + val result = cardsStore.fetchCards(siteModel, CARD_TYPES) assertThat(result.model).isNull() assertEquals(CardsErrorType.GENERIC_ERROR, result.error.type) @@ -155,9 +210,9 @@ class CardsStoreTest { fun `given cards error, when fetch cards gets triggered, then cards error is returned`() = test { val errorType = CardsErrorType.API_ERROR val payload = CardsPayload(CardsError(errorType)) - whenever(restClient.fetchCards(siteModel)).thenReturn(payload) + whenever(restClient.fetchCards(siteModel, CARD_TYPES)).thenReturn(payload) - val result = cardsStore.fetchCards(siteModel) + val result = cardsStore.fetchCards(siteModel, CARD_TYPES) assertThat(result.model).isNull() assertEquals(errorType, result.error.type) @@ -168,9 +223,9 @@ class CardsStoreTest { fun `given authorization required, when fetch cards gets triggered, then db is cleared of cards model`() = test { val errorType = CardsErrorType.AUTHORIZATION_REQUIRED val payload = CardsPayload(CardsError(errorType)) - whenever(restClient.fetchCards(siteModel)).thenReturn(payload) + whenever(restClient.fetchCards(siteModel, CARD_TYPES)).thenReturn(payload) - cardsStore.fetchCards(siteModel) + cardsStore.fetchCards(siteModel, CARD_TYPES) verify(dao).clear() } @@ -179,9 +234,9 @@ class CardsStoreTest { fun `given authorization required, when fetch cards gets triggered, then empty cards model is returned`() = test { val errorType = CardsErrorType.AUTHORIZATION_REQUIRED val payload = CardsPayload(CardsError(errorType)) - whenever(restClient.fetchCards(siteModel)).thenReturn(payload) + whenever(restClient.fetchCards(siteModel, CARD_TYPES)).thenReturn(payload) - val result = cardsStore.fetchCards(siteModel) + val result = cardsStore.fetchCards(siteModel, CARD_TYPES) assertThat(result.model).isNull() assertThat(result.error).isNull() @@ -190,9 +245,9 @@ class CardsStoreTest { @Test fun `given empty cards payload, when fetch cards gets triggered, then cards error is returned`() = test { val payload = CardsPayload() - whenever(restClient.fetchCards(siteModel)).thenReturn(payload) + whenever(restClient.fetchCards(siteModel, CARD_TYPES)).thenReturn(payload) - val result = cardsStore.fetchCards(siteModel) + val result = cardsStore.fetchCards(siteModel, CARD_TYPES) assertThat(result.model).isNull() assertEquals(CardsErrorType.INVALID_RESPONSE, result.error.type) @@ -201,10 +256,30 @@ class CardsStoreTest { @Test fun `when get cards gets triggered, then a flow of cards model is returned`() = test { - whenever(dao.get(SITE_LOCAL_ID)).thenReturn(flowOf(CARDS_ENTITY)) + whenever(dao.get(SITE_LOCAL_ID, CARD_TYPES)).thenReturn(flowOf(CARDS_ENTITY)) - val result = cardsStore.getCards(siteModel).single() + val result = cardsStore.getCards(siteModel, CARD_TYPES).single() assertThat(result).isEqualTo(CardsResult(CARDS_MODEL)) } + + @Test + fun `when get cards gets triggered for today's stats only, then a flow of today's stats card model is returned`() = + test { + whenever(dao.get(SITE_LOCAL_ID, listOf(CardModel.Type.TODAYS_STATS))) + .thenReturn(flowOf(listOf(TODAYS_STATS_ENTITY))) + + val result = cardsStore.getCards(siteModel, listOf(CardModel.Type.TODAYS_STATS)).single() + + assertThat(result).isEqualTo(CardsResult(listOf(TODAYS_STATS_MODEL))) + } + + @Test + fun `when get cards gets triggered for posts only, then a flow of post card model is returned`() = test { + whenever(dao.get(SITE_LOCAL_ID, listOf(CardModel.Type.POSTS))).thenReturn(flowOf(listOf(POSTS_ENTITY))) + + val result = cardsStore.getCards(siteModel, listOf(CardModel.Type.POSTS)).single() + + assertThat(result).isEqualTo(CardsResult(listOf(POSTS_MODEL))) + } } diff --git a/example/src/test/resources/wp/dashboard/cards.json b/example/src/test/resources/wp/dashboard/cards.json index 9949521ff1..01fd779343 100644 --- a/example/src/test/resources/wp/dashboard/cards.json +++ b/example/src/test/resources/wp/dashboard/cards.json @@ -1,4 +1,10 @@ { + "todays_stats": { + "views": 100, + "visitors": 30, + "likes": 50, + "comments": 10 + }, "posts": { "has_published": true, "draft": [ diff --git a/fluxc-processor/src/main/resources/wp-com-v2-endpoints.txt b/fluxc-processor/src/main/resources/wp-com-v2-endpoints.txt index 6a5dd9c0d3..affad8cabe 100644 --- a/fluxc-processor/src/main/resources/wp-com-v2-endpoints.txt +++ b/fluxc-processor/src/main/resources/wp-com-v2-endpoints.txt @@ -2,7 +2,7 @@ /read/sites/$site#String/notification-subscriptions/$action#String -/sites/$site/dashboard/cards +/sites/$site/dashboard/cards-data /sites/$site/activity /sites/$site/activity/count/group diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/model/dashboard/CardModel.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/model/dashboard/CardModel.kt index 3cbfd27b63..7cf3a0911c 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/model/dashboard/CardModel.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/model/dashboard/CardModel.kt @@ -6,11 +6,20 @@ sealed class CardModel( val type: Type ) { enum class Type( - val classOf: Class<*> + val classOf: Class<*>, + val label: String ) { - POSTS(PostsCardModel::class.java) + TODAYS_STATS(TodaysStatsCardModel::class.java, "todays_stats"), + POSTS(PostsCardModel::class.java, "posts") } + data class TodaysStatsCardModel( + val views: Int, + val visitors: Int, + val likes: Int, + val comments: Int + ) : CardModel(Type.TODAYS_STATS) + data class PostsCardModel( val hasPublished: Boolean, val draft: List, diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt index 6c7422d2ce..8803b80d9a 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpcom/dashboard/CardsRestClient.kt @@ -6,8 +6,10 @@ import com.google.gson.annotations.SerializedName import org.wordpress.android.fluxc.Dispatcher import org.wordpress.android.fluxc.generated.endpoint.WPCOMV2 import org.wordpress.android.fluxc.model.SiteModel +import org.wordpress.android.fluxc.model.dashboard.CardModel import org.wordpress.android.fluxc.model.dashboard.CardModel.PostsCardModel import org.wordpress.android.fluxc.model.dashboard.CardModel.PostsCardModel.PostCardModel +import org.wordpress.android.fluxc.model.dashboard.CardModel.TodaysStatsCardModel import org.wordpress.android.fluxc.network.BaseRequest.GenericErrorType import org.wordpress.android.fluxc.network.UserAgent import org.wordpress.android.fluxc.network.rest.wpcom.BaseWPComRestClient @@ -32,12 +34,13 @@ class CardsRestClient @Inject constructor( accessToken: AccessToken, userAgent: UserAgent ) : BaseWPComRestClient(appContext, dispatcher, requestQueue, accessToken, userAgent) { - suspend fun fetchCards(site: SiteModel): CardsPayload { - val url = WPCOMV2.sites.site(site.siteId).dashboard.cards.url + suspend fun fetchCards(site: SiteModel, cardTypes: List): CardsPayload { + val url = WPCOMV2.sites.site(site.siteId).dashboard.cards_data.url + val params = buildDashboardCardsParams(cardTypes) val response = wpComGsonRequestBuilder.syncGetRequest( this, url, - mapOf(), + params, CardsResponse::class.java ) return when (response) { @@ -46,11 +49,30 @@ class CardsRestClient @Inject constructor( } } + private fun buildDashboardCardsParams(cardTypes: List) = + mapOf(CARDS to cardTypes.joinToString(",") { it.label }) + data class CardsResponse( - @SerializedName("posts") val posts: PostsResponse + @SerializedName("todays_stats") val todaysStats: TodaysStatsResponse? = null, + @SerializedName("posts") val posts: PostsResponse? = null + ) { + fun toCards() = arrayListOf().apply { + todaysStats?.let { add(it.toTodaysStatsCard()) } + posts?.let { add(it.toPosts()) } + }.toList() + } + + data class TodaysStatsResponse( + @SerializedName("views") val views: Int? = null, + @SerializedName("visitors") val visitors: Int? = null, + @SerializedName("likes") val likes: Int? = null, + @SerializedName("comments") val comments: Int? = null ) { - fun toCards() = listOf( - posts.toPosts() + fun toTodaysStatsCard() = TodaysStatsCardModel( + views = views ?: 0, + visitors = visitors ?: 0, + likes = likes ?: 0, + comments = comments ?: 0 ) } @@ -81,6 +103,10 @@ class CardsRestClient @Inject constructor( date = CardsUtils.fromDate(date) ) } + + companion object { + private const val CARDS = "cards" + } } fun WPComGsonNetworkError.toCardsError(): CardsError { diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/dashboard/CardsDao.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/dashboard/CardsDao.kt index ada34d7d34..51a97a7502 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/dashboard/CardsDao.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/dashboard/CardsDao.kt @@ -11,8 +11,8 @@ import org.wordpress.android.fluxc.network.rest.wpcom.dashboard.CardsUtils @Dao abstract class CardsDao { - @Query("SELECT * FROM DashboardCards WHERE siteLocalId = :siteLocalId") - abstract fun get(siteLocalId: Int): Flow> + @Query("SELECT * FROM DashboardCards WHERE siteLocalId = :siteLocalId AND type IN (:cardTypes)") + abstract fun get(siteLocalId: Int, cardTypes: List): Flow> @Insert(onConflict = OnConflictStrategy.REPLACE) abstract suspend fun insert(card: List) diff --git a/fluxc/src/main/java/org/wordpress/android/fluxc/store/dashboard/CardsStore.kt b/fluxc/src/main/java/org/wordpress/android/fluxc/store/dashboard/CardsStore.kt index 7fc57818b1..efcb9e4c5c 100644 --- a/fluxc/src/main/java/org/wordpress/android/fluxc/store/dashboard/CardsStore.kt +++ b/fluxc/src/main/java/org/wordpress/android/fluxc/store/dashboard/CardsStore.kt @@ -21,9 +21,10 @@ class CardsStore @Inject constructor( private val coroutineEngine: CoroutineEngine ) { suspend fun fetchCards( - site: SiteModel + site: SiteModel, + cardTypes: List ) = coroutineEngine.withDefaultContext(AppLog.T.API, this, "fetchCards") { - val payload = restClient.fetchCards(site) + val payload = restClient.fetchCards(site, cardTypes) return@withDefaultContext storeCards(site, payload) } @@ -57,8 +58,9 @@ class CardsStore @Inject constructor( } fun getCards( - site: SiteModel - ) = cardsDao.get(site.id).map { cards -> + site: SiteModel, + cardTypes: List + ) = cardsDao.get(site.id, cardTypes).map { cards -> CardsResult(cards.map { it.toCard() }) }