Skip to content

Instantly share code, notes, and snippets.

View lagoJin's full-sized avatar
👀

JinHo Kang lagoJin

👀
  • KakaoPay
  • yongin, Korea
View GitHub Profile
class GithubRepositoryImpl constructor(
private val githubService: GithubService,
private val githubMapper: GithubMapper
) : GithubRepository {
override suspend fun getGithubs(
userId: String,
page: Int,
perPage: Int
): List<DomainEntityGithub> {
interface GithubService {
@GET("search/users")
suspend fun getSearchUsers(
@Query("q") q: String,
@Query("page") page: Int,
@Query("per_page") perPage: Int
): DataEntityGithub
}
class GithubUseCase constructor(
private val githubRepository: GithubRepository
) : BaseUseCase<GithubUseCase.Params, List<DomainEntityGithub>> {
data class Params(val userId: String, val page: Int, val perPage: Int)
override fun invoke(
scope: CoroutineScope,
params: Params,
onSuccess: (List<DomainEntityGithub>) -> Unit,
class MainViewModel @Inject constructor(
private val githubUseCase: GIthubUseCase) : BaseViewModel() {
private val _result = MutableLiveData<List<DomainEntityGithub>>()
val result: LiveData<List<DomainEntityGithub>>
get() = _result
fun search(query: String, page:Int, count :Int) {
_dataLoading.postValue(true)
githubUseCase.invoke(viewModelScope, GithubUseCase.Params(query, page, count),
private const val JOB_KEY = "androidx.lifecycle.ViewModelCoroutineScope.JOB_KEY"
/**
* [CoroutineScope] tied to this [ViewModel].
* This scope will be canceled when ViewModel will be cleared, i.e [ViewModel.onCleared] is called
*
* This scope is bound to [Dispatchers.Main]
*/
val ViewModel.viewModelScope: CoroutineScope
get() {