-
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.
Merge pull request #98 from team-JMT/feat/upgrade_search
그룹 전용 검색 화면 플래그로 구별하도록 구현, 그룹 검색 API 연결
- Loading branch information
Showing
20 changed files
with
331 additions
and
31 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
data/src/main/java/org/gdsc/data/database/GroupBySearchPagingSource.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,33 @@ | ||
package org.gdsc.data.database | ||
|
||
import androidx.paging.PagingSource | ||
import androidx.paging.PagingState | ||
import org.gdsc.data.network.GroupAPI | ||
import org.gdsc.domain.model.GroupPreview | ||
import org.gdsc.domain.model.request.GroupSearchRequest | ||
|
||
class GroupBySearchPagingSource( | ||
private val api: GroupAPI, | ||
private val groupSearchRequest: GroupSearchRequest, | ||
): PagingSource<Int, GroupPreview>() { | ||
override fun getRefreshKey(state: PagingState<Int, GroupPreview>): Int? { | ||
return state.anchorPosition?.let { anchorPosition -> | ||
val anchorPage = state.closestPageToPosition(anchorPosition) | ||
anchorPage?.prevKey?.plus(1) ?: anchorPage?.nextKey?.minus(1) | ||
} | ||
} | ||
|
||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, GroupPreview> { | ||
val page = params.key ?: 1 | ||
return try { | ||
val items = api.searchGroup(groupSearchRequest) | ||
LoadResult.Page( | ||
data = items.data.groupList, | ||
prevKey = null, | ||
nextKey = if (items.data.groupList.isEmpty()) null else page + 1 | ||
) | ||
} catch (e: Exception) { | ||
return LoadResult.Error(e) | ||
} | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
domain/src/main/java/org/gdsc/domain/usecase/GetGroupBySearchUseCase.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,18 @@ | ||
package org.gdsc.domain.usecase | ||
|
||
import androidx.paging.PagingData | ||
import kotlinx.coroutines.flow.Flow | ||
import org.gdsc.domain.model.GroupPreview | ||
import org.gdsc.domain.repository.GroupRepository | ||
import javax.inject.Inject | ||
|
||
class GetGroupBySearchUseCase @Inject constructor( | ||
private val groupRepository: GroupRepository | ||
) { | ||
suspend operator fun invoke( | ||
keyword: String, | ||
): Flow<PagingData<GroupPreview>> { | ||
|
||
return groupRepository.searchPagingGroup(keyword) | ||
} | ||
} |
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
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.