From fa613beb7010d5f7689dc15fd67db58b2eb784e5 Mon Sep 17 00:00:00 2001 From: Jaesung Lee Date: Sun, 11 Aug 2024 19:28:10 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[Feat]=20MemeWithPagination=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20=EB=AA=A8=EB=8D=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/team/ppac/domain/model/MemeWithPagination.kt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 core/domain/src/main/java/team/ppac/domain/model/MemeWithPagination.kt diff --git a/core/domain/src/main/java/team/ppac/domain/model/MemeWithPagination.kt b/core/domain/src/main/java/team/ppac/domain/model/MemeWithPagination.kt new file mode 100644 index 00000000..bd298636 --- /dev/null +++ b/core/domain/src/main/java/team/ppac/domain/model/MemeWithPagination.kt @@ -0,0 +1,9 @@ +package team.ppac.domain.model + +import androidx.paging.PagingData +import kotlinx.coroutines.flow.Flow + +data class MemeWithPagination( + val totalMemeCount: Int, + val memes: Flow>, +) From ba922a5d3d7d6135c3de9d5548a77ca184526702 Mon Sep 17 00:00:00 2001 From: Jaesung Lee Date: Sun, 11 Aug 2024 19:28:57 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[Feat]=20=EC=A0=84=EC=B2=B4=20=EB=B0=88=20?= =?UTF-8?q?=EA=B0=AF=EC=88=98=20=EC=A1=B0=ED=9A=8C=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/repository/MemeRepositoryImpl.kt | 29 ++++++++++++------- .../ppac/domain/repository/MemeRepository.kt | 3 +- .../domain/usecase/GetSearchMemeUseCase.kt | 8 ++--- .../ppac/remote/datasource/MemeDataSource.kt | 3 +- .../datasource/impl/MemeDataSourceImpl.kt | 5 ++-- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/core/data/src/main/java/team/ppac/data/repository/MemeRepositoryImpl.kt b/core/data/src/main/java/team/ppac/data/repository/MemeRepositoryImpl.kt index ce34ee41..61e5ec39 100644 --- a/core/data/src/main/java/team/ppac/data/repository/MemeRepositoryImpl.kt +++ b/core/data/src/main/java/team/ppac/data/repository/MemeRepositoryImpl.kt @@ -1,12 +1,11 @@ package team.ppac.data.repository -import androidx.paging.PagingData -import kotlinx.coroutines.flow.Flow import team.ppac.data.mapper.toMeme import team.ppac.data.paging.ITEMS_PER_PAGE import team.ppac.data.paging.createPager import team.ppac.domain.model.Meme import team.ppac.domain.model.MemeWatchType +import team.ppac.domain.model.MemeWithPagination import team.ppac.domain.repository.MemeRepository import team.ppac.remote.datasource.MemeDataSource import javax.inject.Inject @@ -31,15 +30,25 @@ class MemeRepositoryImpl @Inject constructor( return memeDataSource.deleteSavedMeme(memeId) } - override fun getSearchMemes(keyword: String): Flow> { - return createPager { page -> - memeDataSource.getSearchMemes( - keyword = keyword, - page = page, - size = ITEMS_PER_PAGE, - ).map { it.toMeme() } - }.flow + override suspend fun getSearchMemes(keyword: String): MemeWithPagination { + val totalMemeCount = memeDataSource.getSearchMemes( + keyword = keyword, + page = 1, + size = ITEMS_PER_PAGE + ).pagination.total + + return MemeWithPagination( + totalMemeCount = totalMemeCount, + memes = createPager { page -> + memeDataSource.getSearchMemes( + keyword = keyword, + page = page, + size = ITEMS_PER_PAGE, + ).memeList.map { it.toMeme() } + }.flow + ) } + override suspend fun reactMeme(memeId: String): Boolean { return memeDataSource.reactMeme(memeId) } diff --git a/core/domain/src/main/java/team/ppac/domain/repository/MemeRepository.kt b/core/domain/src/main/java/team/ppac/domain/repository/MemeRepository.kt index dd7ded57..e2866665 100644 --- a/core/domain/src/main/java/team/ppac/domain/repository/MemeRepository.kt +++ b/core/domain/src/main/java/team/ppac/domain/repository/MemeRepository.kt @@ -4,13 +4,14 @@ import androidx.paging.PagingData import kotlinx.coroutines.flow.Flow import team.ppac.domain.model.Meme import team.ppac.domain.model.MemeWatchType +import team.ppac.domain.model.MemeWithPagination interface MemeRepository { suspend fun getMeme(memeId: String): Meme suspend fun getRecommendMemes(): List suspend fun saveMeme(memeId: String): Boolean suspend fun deleteSavedMeme(memeId: String): Boolean - fun getSearchMemes(keyword: String): Flow> + suspend fun getSearchMemes(keyword: String): MemeWithPagination suspend fun reactMeme(memeId: String): Boolean suspend fun watchMeme( memeId: String, diff --git a/core/domain/src/main/java/team/ppac/domain/usecase/GetSearchMemeUseCase.kt b/core/domain/src/main/java/team/ppac/domain/usecase/GetSearchMemeUseCase.kt index 3fc93556..5a26a3de 100644 --- a/core/domain/src/main/java/team/ppac/domain/usecase/GetSearchMemeUseCase.kt +++ b/core/domain/src/main/java/team/ppac/domain/usecase/GetSearchMemeUseCase.kt @@ -1,19 +1,17 @@ package team.ppac.domain.usecase -import androidx.paging.PagingData -import kotlinx.coroutines.flow.Flow -import team.ppac.domain.model.Meme +import team.ppac.domain.model.MemeWithPagination import team.ppac.domain.repository.MemeRepository import javax.inject.Inject interface GetSearchMemeUseCase { - operator fun invoke(keyword: String): Flow> + suspend operator fun invoke(keyword: String): MemeWithPagination } internal class GetSearchMemeUseCaseImpl @Inject constructor( private val memeRepository: MemeRepository, ) : GetSearchMemeUseCase { - override fun invoke(keyword: String): Flow> { + override suspend fun invoke(keyword: String): MemeWithPagination { return memeRepository.getSearchMemes(keyword) } } \ No newline at end of file diff --git a/core/remote/src/main/kotlin/team/ppac/remote/datasource/MemeDataSource.kt b/core/remote/src/main/kotlin/team/ppac/remote/datasource/MemeDataSource.kt index 852d9dd9..d4d4c9de 100644 --- a/core/remote/src/main/kotlin/team/ppac/remote/datasource/MemeDataSource.kt +++ b/core/remote/src/main/kotlin/team/ppac/remote/datasource/MemeDataSource.kt @@ -1,6 +1,7 @@ package team.ppac.remote.datasource import team.ppac.remote.model.response.meme.MemeResponse +import team.ppac.remote.model.response.user.SavedMemesResponse interface MemeDataSource { suspend fun getMemeById(memeId: String): MemeResponse @@ -11,7 +12,7 @@ interface MemeDataSource { keyword: String, page: Int, size: Int, - ): List + ): SavedMemesResponse suspend fun reactMeme(memeId: String): Boolean suspend fun watchMeme( memeId: String, diff --git a/core/remote/src/main/kotlin/team/ppac/remote/datasource/impl/MemeDataSourceImpl.kt b/core/remote/src/main/kotlin/team/ppac/remote/datasource/impl/MemeDataSourceImpl.kt index e286ac6f..ec17967c 100644 --- a/core/remote/src/main/kotlin/team/ppac/remote/datasource/impl/MemeDataSourceImpl.kt +++ b/core/remote/src/main/kotlin/team/ppac/remote/datasource/impl/MemeDataSourceImpl.kt @@ -3,6 +3,7 @@ package team.ppac.remote.datasource.impl import team.ppac.remote.api.MemeApi import team.ppac.remote.datasource.MemeDataSource import team.ppac.remote.model.response.meme.MemeResponse +import team.ppac.remote.model.response.user.SavedMemesResponse import javax.inject.Inject internal class MemeDataSourceImpl @Inject constructor( @@ -24,8 +25,8 @@ internal class MemeDataSourceImpl @Inject constructor( return memeApi.deleteSavedMeme(memeId) } - override suspend fun getSearchMemes(keyword: String, page: Int, size: Int): List { - return memeApi.getSearchMemes(keyword, page, size).memeList + override suspend fun getSearchMemes(keyword: String, page: Int, size: Int): SavedMemesResponse { + return memeApi.getSearchMemes(keyword, page, size) } override suspend fun reactMeme(memeId: String): Boolean { From d8a539657e4f0168ac312cd2e0abc5952371dc33 Mon Sep 17 00:00:00 2001 From: Jaesung Lee Date: Sun, 11 Aug 2024 19:29:13 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[Feat]=20uiState=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/team/ppac/search/detail/mvi/SearchDetailUiState.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/feature/search/src/main/java/team/ppac/search/detail/mvi/SearchDetailUiState.kt b/feature/search/src/main/java/team/ppac/search/detail/mvi/SearchDetailUiState.kt index acd02ebb..809135b4 100644 --- a/feature/search/src/main/java/team/ppac/search/detail/mvi/SearchDetailUiState.kt +++ b/feature/search/src/main/java/team/ppac/search/detail/mvi/SearchDetailUiState.kt @@ -9,6 +9,7 @@ import team.ppac.search.detail.model.SearchResultUiModel data class SearchDetailUiState( val isLoading: Boolean, val isError: Boolean, + val totalMemeCount: Int, val memeCategory: String, val searchResults: Flow>, ) : UiState { @@ -17,6 +18,7 @@ data class SearchDetailUiState( val INITIAL_STATE = SearchDetailUiState( isLoading = true, isError = false, + totalMemeCount = 0, memeCategory = "", searchResults = flowOf(PagingData.empty()) ) From 06009c5e944dfd165d3c44002fd87ad8960ff2bd Mon Sep 17 00:00:00 2001 From: Jaesung Lee Date: Sun, 11 Aug 2024 19:29:29 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[Feat]=20=EB=B0=88=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EA=B0=AF=EC=88=98=20update=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team/ppac/search/detail/SearchDetailViewModel.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/feature/search/src/main/java/team/ppac/search/detail/SearchDetailViewModel.kt b/feature/search/src/main/java/team/ppac/search/detail/SearchDetailViewModel.kt index 825649ce..9eca2fc7 100644 --- a/feature/search/src/main/java/team/ppac/search/detail/SearchDetailViewModel.kt +++ b/feature/search/src/main/java/team/ppac/search/detail/SearchDetailViewModel.kt @@ -83,21 +83,26 @@ class SearchDetailViewModel @Inject constructor( private fun getSearchResults(memeCategory: String) = launch { updateLoadingState(true) delay(300L) - val searchResults = getSearchMemeUseCase(memeCategory) + + val paginationResults = getSearchMemeUseCase(memeCategory) + val totalMemeCount = paginationResults.totalMemeCount + val searchResults = paginationResults.memes .map { pagingData -> pagingData.map { it.toSearchResultUiModel() } }.cachedIn(viewModelScope) updateLoadingState(false) - updateSearchResults(memeCategory, searchResults) + updateSearchResults(totalMemeCount, memeCategory, searchResults) } private fun updateSearchResults( + totalMemeCount: Int, memeCategory: String, searchResults: Flow>, ) { reduce { copy( + totalMemeCount = totalMemeCount, memeCategory = memeCategory, searchResults = searchResults ) From 3ae8d0618e792b085288be066d3b61e83b861241 Mon Sep 17 00:00:00 2001 From: Jaesung Lee Date: Sun, 11 Aug 2024 19:29:49 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[Feat]=20=EB=B0=88=EC=9D=B4=20=EC=97=86?= =?UTF-8?q?=EC=9D=84=20=EB=95=8C=20EmptyScreen=20=EB=85=B8=EC=B6=9C=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team/ppac/search/detail/SearchDetailScreen.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/feature/search/src/main/java/team/ppac/search/detail/SearchDetailScreen.kt b/feature/search/src/main/java/team/ppac/search/detail/SearchDetailScreen.kt index de2ebc08..375bc1d7 100644 --- a/feature/search/src/main/java/team/ppac/search/detail/SearchDetailScreen.kt +++ b/feature/search/src/main/java/team/ppac/search/detail/SearchDetailScreen.kt @@ -83,15 +83,16 @@ internal fun SearchDetailScreen( Column( modifier = Modifier.padding(innerPadding) ) { - if (searchResults.itemCount == 0) { + if (uiState.totalMemeCount == 0) { EmptyResultContent() + } else { + SearchDetailResultHeader(totalCount = uiState.totalMemeCount) + SearchDetailResultContent( + searchResults = searchResults, + onMemeClick = onMemeClick, + onCopyClick = onCopyClick + ) } - SearchDetailResultHeader(totalCount = searchResults.itemCount) - SearchDetailResultContent( - searchResults = searchResults, - onMemeClick = onMemeClick, - onCopyClick = onCopyClick - ) } } }