Skip to content

[採用] stub環境で開発を進める仕組みを構築する - Part3 #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import io.ktor.http.*
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json

class GithubServiceImpl(private val format: Json) : GithubService {
class GithubApi(private val format: Json) {
private val httpClient: HttpClient by lazy {
HttpClient(Android) {
defaultRequest {
Expand All @@ -41,25 +41,33 @@ class GithubServiceImpl(private val format: Json) : GithubService {
}
}

override suspend fun searchRepositories(
suspend fun searchRepositories(
query: String,
page: Int,
perPage: Int,
sort: String
perPage: Int = SEARCH_PER_PAGE,
sort: String = "stars"
): List<RepositorySummary> {
/*
サーバーサイドのAPI開発が完了するまではFlavorをstubにし、開発を進める.
format.decodeFromStubData<SearchRepositoryResponse>(
context,
format,
"search_repositories_success.json"
).toModel()
*/
val response: HttpResponse = httpClient.get {
url { path("search", "repositories") }
parameter("q", query)
parameter("page", page)
parameter("per_page", perPage)
parameter("sort", "stars")
parameter("sort", sort)
}
val data =
format.decodeFromString<SearchRepositoryResponse>(response.body())
return data.toModel()
}

override suspend fun fetchRepositoryDetail(
suspend fun fetchRepositoryDetail(
ownerName: String,
repositoryName: String
): RepositoryDetail {
Expand All @@ -73,6 +81,7 @@ class GithubServiceImpl(private val format: Json) : GithubService {
}

companion object {
const val SEARCH_PER_PAGE = 20
private const val TIMEOUT_MILLIS: Long = 30 * 1000
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package com.leoleo.androidgithubsearch.data.paging
import android.util.Log
import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.leoleo.androidgithubsearch.data.api.GithubService
import com.leoleo.androidgithubsearch.data.api.GithubApi
import com.leoleo.androidgithubsearch.data.api.KtorHandler
import com.leoleo.androidgithubsearch.domain.model.RepositorySummary

class GithubRepoPagingSource(
private val query: String,
private val api: GithubService,
private val api: GithubApi,
private val ktorHandler: KtorHandler,
) : PagingSource<Int, RepositorySummary>() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.leoleo.androidgithubsearch.data.repository
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import com.leoleo.androidgithubsearch.data.api.GithubService
import com.leoleo.androidgithubsearch.data.api.GithubService.Companion.SEARCH_PER_PAGE
import com.leoleo.androidgithubsearch.data.api.GithubApi
import com.leoleo.androidgithubsearch.data.api.GithubApi.Companion.SEARCH_PER_PAGE
import com.leoleo.androidgithubsearch.data.api.KtorHandler
import com.leoleo.androidgithubsearch.data.paging.GithubRepoPagingSource
import com.leoleo.androidgithubsearch.domain.model.RepositoryDetail
Expand All @@ -14,7 +14,7 @@ import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class GithubRepoRepositoryImpl @Inject constructor(
private val api: GithubService,
private val api: GithubApi,
private val ktorHandler: KtorHandler,
) : GithubRepoRepository {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.leoleo.androidgithubsearch.di

import com.leoleo.androidgithubsearch.data.api.GithubService
import com.leoleo.androidgithubsearch.data.api.GithubServiceImpl
import com.leoleo.androidgithubsearch.data.api.GithubApi
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand All @@ -23,5 +22,5 @@ import javax.inject.Singleton
object DataSourceModule {
@Singleton
@Provides
fun provideGithubService(format: Json): GithubService = GithubServiceImpl(format)
fun provideGithubService(format: Json): GithubApi = GithubApi(format)
}

This file was deleted.