-
Notifications
You must be signed in to change notification settings - Fork 44
Step2 - GitHub(HTTP) #108
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
Open
oyj7677
wants to merge
11
commits into
next-step:oyj7677
Choose a base branch
from
oyj7677:step2
base: oyj7677
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,131
−43
Open
Step2 - GitHub(HTTP) #108
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5c378e9
Create README.md
oyj7677 678ced4
step2 - GitHub(HTTP)
oyj7677 e0d1e86
README 업데이트
oyj7677 1c2ac73
Merge branch 'oyj7677' into step2
oyj7677 5ab40f8
코루틴 테스트 코드 어노테이션 추가
oyj7677 8dc801b
Merge branch 'step2' of https://github.com/oyj7677/android-github int…
oyj7677 daf059b
data모듈
oyj7677 222dd0b
step2 - 1차 개선사항
oyj7677 759b5b6
제거된 코드 정리
oyj7677 d262f9b
step2 - 3차 개선사항
oyj7677 e515420
코드 정리 및 테스트 코드 주석 수정
oyj7677 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,20 @@ | ||
# android-github | ||
|
||
## 1 단계 - GitHub(모듈 분리) | ||
### 프로그래밍 요구 사항 | ||
- 순수 코틀린 모듈인 domain 모듈을 만든다. | ||
- 순수 코틀린 모듈인 data 모듈을 만든다. | ||
- data 모듈은 domain 모듈에 의존해야 한다. | ||
- app 모듈은 domain 모듈에 의존해야 한다. | ||
|
||
## 2단계 - GitHub(HTTP) | ||
###기능 요구사항 | ||
- GitHub Repository 목록을 가져올 수 있어야 한다. | ||
- GET, https://api.github.com/repositories | ||
- full_name, description 필드만 | ||
|
||
###프로그래밍 요구사항 | ||
- Repository 목록을 가져오는 기능은 data 모듈에 구현되어야 한다. | ||
- data 모듈의 구현체는 모두 internal class로 선언한다. | ||
- HTTP 요청을 통해 가져오는 구현체에 대한 테스트 코드를 작성한다. | ||
- OkHttp MockWebServer 이용 |
This file contains hidden or 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 hidden or 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
8 changes: 8 additions & 0 deletions
8
app/src/main/java/camp/nextstep/edu/github/GitHubViewModel.kt
This file contains hidden or 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,8 @@ | ||
package camp.nextstep.edu.github | ||
|
||
import androidx.lifecycle.ViewModel | ||
import com.example.githubdomain.GitHubRepository | ||
|
||
class GitHubViewModel : ViewModel() { | ||
|
||
} |
This file contains hidden or 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 hidden or 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,21 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".MainActivity" | ||
> | ||
<layout> | ||
<data> | ||
<variable | ||
name="viewModel" | ||
type="camp.nextstep.edu.github.GitHubViewModel" /> | ||
</data> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Hello World!" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
/> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".MainActivity"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="github/repositories 저장" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent"/> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |
This file contains hidden or 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,13 +1,60 @@ | ||
plugins { | ||
id("java-library") | ||
id("org.jetbrains.kotlin.jvm") | ||
id("com.android.library") | ||
id("org.jetbrains.kotlin.android") | ||
id("kotlin-kapt") | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
android { | ||
namespace = "camp.nextstep.edu.github.github_data" | ||
compileSdk = Version.compileSdk | ||
|
||
defaultConfig { | ||
minSdk = Version.minSdk | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles("consumer-rules.pro") | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
|
||
testOptions { | ||
unitTests { | ||
isIncludeAndroidResources = true | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
api(project(":github-domain")) | ||
dependencies{ | ||
implementation(project(":github-domain")) | ||
|
||
implementation("com.squareup.retrofit2:retrofit:2.9.0") | ||
implementation ("com.squareup.retrofit2:converter-gson:2.9.0") | ||
implementation ("com.google.code.gson:gson:2.10.1") | ||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4") | ||
implementation("androidx.room:room-runtime:2.5.2") | ||
implementation("com.squareup.okhttp3:mockwebserver:4.11.0") | ||
implementation("androidx.test:core-ktx:1.5.0") | ||
|
||
kapt ("androidx.room:room-compiler:2.5.2") | ||
|
||
testImplementation("junit:junit:4.13.2") | ||
testImplementation ("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4") | ||
testImplementation("com.google.truth:truth:1.1.3") | ||
testImplementation ("org.robolectric:robolectric:4.9") | ||
|
||
} |
This file contains hidden or 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,10 @@ | ||
package com.example.github | ||
|
||
import com.example.github.data.repository.remote.data.RemoteGithubData | ||
import retrofit2.Response | ||
import retrofit2.http.GET | ||
|
||
interface GitHubApi { | ||
@GET("/repositories") | ||
suspend fun getGitHubRepo(): Response<List<RemoteGithubData>> | ||
} |
16 changes: 16 additions & 0 deletions
16
github-data/src/main/java/com/example/github/GitHubService.kt
This file contains hidden or 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,16 @@ | ||
package com.example.github | ||
|
||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
|
||
internal object GitHubService { | ||
private val BASE_URL = "https://api.github.com" | ||
|
||
fun getGitHubService(): GitHubApi { | ||
return Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
.create(GitHubApi::class.java) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
github-data/src/main/java/com/example/github/data/mapper/Mapper.kt
This file contains hidden or 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,35 @@ | ||
package com.example.github.data.mapper | ||
|
||
import com.example.github.data.repository.remote.data.RemoteGithubData | ||
import com.example.github.data.room.GithubRepoEntity | ||
import com.example.githubdomain.GithubRepoData | ||
|
||
fun List<GithubRepoEntity>.githubRepoEntityToGithubRepoData(): List<GithubRepoData> { | ||
return this.toList().map { | ||
GithubRepoData( | ||
id = it.id, | ||
fullName = it.fullName, | ||
description = it.description ?: "" | ||
) | ||
} | ||
} | ||
|
||
fun List<RemoteGithubData>.remoteGithubDataToGithubRepoData(): List<GithubRepoData> { | ||
return this.toList().map { | ||
GithubRepoData( | ||
id = it.id, | ||
fullName = it.fullName, | ||
description = it.description | ||
) | ||
} | ||
} | ||
|
||
fun List<GithubRepoData>.githubRepoDataToGithubRepoEntity(): List<GithubRepoEntity> { | ||
return this.toList().map { | ||
GithubRepoEntity( | ||
id = it.id, | ||
fullName = it.fullName, | ||
description = it.description | ||
) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
github-data/src/main/java/com/example/github/data/repository/GithubRepositoryImpl.kt
This file contains hidden or 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,32 @@ | ||
package com.example.github.data.repository | ||
import com.example.github.data.mapper.githubRepoEntityToGithubRepoData | ||
import com.example.github.data.mapper.remoteGithubDataToGithubRepoData | ||
import com.example.github.data.repository.local.LocalGithubDataSource | ||
import com.example.github.data.repository.remote.RemoteGithubDataSource | ||
import com.example.githubdomain.GitHubRepository | ||
import com.example.githubdomain.GithubRepoData | ||
|
||
internal class GithubRepositoryImpl( | ||
private val localGithubDataSource: LocalGithubDataSource, | ||
private val remoteGithubDataSource: RemoteGithubDataSource | ||
): GitHubRepository { | ||
|
||
override suspend fun getGitHubRepoData(): List<GithubRepoData> { | ||
val localData = localGithubDataSource.getGitHubRepo() | ||
return if(localData.isNullOrEmpty()) { | ||
try { | ||
remoteGithubDataSource.getGitHubRepo().remoteGithubDataToGithubRepoData().also { | ||
localGithubDataSource.insertGitHubRepo(it) | ||
} | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
emptyList() | ||
} | ||
|
||
} else { | ||
localData.githubRepoEntityToGithubRepoData() | ||
} | ||
} | ||
|
||
suspend fun isEmptyLocalData() = localGithubDataSource.getGitHubRepo().isNullOrEmpty() | ||
} |
14 changes: 14 additions & 0 deletions
14
...a/src/main/java/com/example/github/data/repository/local/FakeLocalGithubDataSourceImpl.kt
This file contains hidden or 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,14 @@ | ||
package com.example.github.data.repository.local | ||
|
||
import com.example.github.data.mapper.githubRepoDataToGithubRepoEntity | ||
import com.example.github.data.room.GithubRepoEntity | ||
import com.example.githubdomain.GithubRepoData | ||
|
||
internal class FakeLocalGithubDataSourceImpl: LocalGithubDataSource { | ||
private val gitHubRepoEntityList = mutableListOf<GithubRepoEntity>() | ||
override suspend fun getGitHubRepo() = gitHubRepoEntityList | ||
|
||
override fun insertGitHubRepo(gitHubRepoDataList: List<GithubRepoData>) { | ||
gitHubRepoEntityList.addAll(gitHubRepoDataList.githubRepoDataToGithubRepoEntity()) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
github-data/src/main/java/com/example/github/data/repository/local/LocalGithubDataSource.kt
This file contains hidden or 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,10 @@ | ||
package com.example.github.data.repository.local | ||
|
||
import com.example.github.data.room.GithubRepoEntity | ||
import com.example.githubdomain.GithubRepoData | ||
|
||
interface LocalGithubDataSource { | ||
suspend fun getGitHubRepo(): List<GithubRepoEntity> | ||
|
||
fun insertGitHubRepo(gitHubRepoDataList: List<GithubRepoData>) | ||
} |
21 changes: 21 additions & 0 deletions
21
...-data/src/main/java/com/example/github/data/repository/local/LocalGithubDataSourceImpl.kt
This file contains hidden or 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,21 @@ | ||
package com.example.github.data.repository.local | ||
|
||
import com.example.github.data.mapper.githubRepoDataToGithubRepoEntity | ||
import com.example.github.data.room.GithubRepoDao | ||
import com.example.github.data.room.GithubRepoEntity | ||
import com.example.githubdomain.GithubRepoData | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.async | ||
|
||
internal class LocalGithubDataSourceImpl(private val githubDao: GithubRepoDao): LocalGithubDataSource { | ||
override suspend fun getGitHubRepo(): List<GithubRepoEntity> { | ||
return CoroutineScope(Dispatchers.IO).async { | ||
githubDao.getGitHubRepo() | ||
}.await() | ||
} | ||
|
||
override fun insertGitHubRepo(gitHubRepoDataList: List<GithubRepoData>) { | ||
githubDao.insertGithubRepoEntityList(gitHubRepoDataList.githubRepoDataToGithubRepoEntity()) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ub-data/src/main/java/com/example/github/data/repository/remote/RemoteGithubDataSource.kt
This file contains hidden or 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,7 @@ | ||
package com.example.github.data.repository.remote | ||
|
||
import com.example.github.data.repository.remote.data.RemoteGithubData | ||
|
||
interface RemoteGithubDataSource { | ||
suspend fun getGitHubRepo(): List<RemoteGithubData> | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UI의 경우는 Step3의 미션입니다 ㅠ,ㅠ! 관련 변경사항은 step3진행하면서 적용해주시면 좋을거같아요!