-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[οΏ½FEAT/#328] νμ λ·° / νμ΄μ§ μΆκ°
- Loading branch information
Showing
14 changed files
with
252 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
data/search/src/main/java/com/terning/data/search/pagingsource/SearchPagingSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.terning.data.search.pagingsource | ||
|
||
import androidx.paging.PagingSource | ||
import androidx.paging.PagingState | ||
import com.terning.data.search.datasource.SearchDataSource | ||
import com.terning.data.search.dto.request.SearchRequestDto | ||
import com.terning.data.search.dto.response.SearchResultResponseDto | ||
|
||
class SearchPagingSource( | ||
private val query: String, | ||
private val sortBy: String, | ||
private val dataSource: SearchDataSource, | ||
) : PagingSource<Int, Pair<Int, SearchResultResponseDto.SearchAnnouncementDto>>() { | ||
|
||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Pair<Int, SearchResultResponseDto.SearchAnnouncementDto>> { | ||
return try { | ||
val nextParamKey = params.key ?: 0 | ||
|
||
val response = dataSource.getSearch( | ||
request = SearchRequestDto( | ||
keyword = query, | ||
sortBy = sortBy, | ||
page = nextParamKey, | ||
) | ||
) | ||
val totalCount = response.result.totalCount | ||
val hasNextPage = response.result.hasNext | ||
|
||
val nextKey = if (hasNextPage) nextParamKey + 1 else null | ||
|
||
LoadResult.Page( | ||
data = response.result.announcements.map { | ||
Pair(totalCount, it) | ||
}, | ||
prevKey = null, | ||
nextKey = nextKey | ||
) | ||
} catch (e: Exception) { | ||
LoadResult.Error(e) | ||
} | ||
} | ||
|
||
override fun getRefreshKey(state: PagingState<Int, Pair<Int, SearchResultResponseDto.SearchAnnouncementDto>>): Int? { | ||
return state.anchorPosition?.let { anchorPosition -> | ||
state.closestPageToPosition(anchorPosition)?.prevKey?.plus(1) | ||
?: state.closestPageToPosition(anchorPosition)?.nextKey?.minus(1) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
plugins { | ||
alias(libs.plugins.terning.kotlin) | ||
} | ||
|
||
dependencies { | ||
implementation(libs.paging.common) | ||
} |
1 change: 1 addition & 0 deletions
1
domain/search/src/main/java/com/terning/domain/search/entity/SearchResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
domain/search/src/main/java/com/terning/domain/search/repository/SearchRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.