-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 패키지명 변경 - LocalDataSource, RemoteDataSource 인터페이스 수정 - local Data 저장 로직 추가 - GlobalScope 제거 - 테스트 케이스 네이밍 수정 - 오류 테스트 케이스 추가
- Loading branch information
Showing
26 changed files
with
612 additions
and
230 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
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>> | ||
} |
2 changes: 1 addition & 1 deletion
2
.../com/example/github_data/GitHubService.kt → .../java/com/example/github/GitHubService.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
35 changes: 35 additions & 0 deletions
35
github-data/src/main/java/com/example/github/data/mapper/Mapper.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,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 | ||
) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
github-data/src/main/java/com/example/github/data/repository/GithubRepositoryImpl.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 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 | ||
import java.net.SocketTimeoutException | ||
|
||
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 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 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 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 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> | ||
} |
22 changes: 22 additions & 0 deletions
22
...ata/src/main/java/com/example/github/data/repository/remote/RemoteGithubDataSourceImpl.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,22 @@ | ||
package com.example.github.data.repository.remote | ||
|
||
import com.example.github.GitHubApi | ||
import com.example.github.GitHubService | ||
import com.example.github.data.repository.remote.data.RemoteGithubData | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.async | ||
|
||
internal class RemoteGithubDataSourceImpl(private val githubService: GitHubApi = GitHubService.getGitHubService()): RemoteGithubDataSource { | ||
|
||
override suspend fun getGitHubRepo(): List<RemoteGithubData> { | ||
return CoroutineScope(Dispatchers.IO).async { | ||
val response = githubService.getGitHubRepo() | ||
if(response.isSuccessful) { | ||
response.body()?: emptyList() | ||
} else { | ||
emptyList() | ||
} | ||
}.await() | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
github-data/src/main/java/com/example/github/data/repository/remote/data/Owner.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,43 @@ | ||
package com.example.github.data.repository.remote.data | ||
|
||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class Owner( | ||
@SerializedName("avatar_url") | ||
val avatarUrl: String, | ||
@SerializedName("events_url") | ||
val eventsUrl: String, | ||
@SerializedName("followers_url") | ||
val followersUrl: String, | ||
@SerializedName("following_url") | ||
val followingUrl: String, | ||
@SerializedName("gists_url") | ||
val gistsUrl: String, | ||
@SerializedName("gravatar_id") | ||
val gravatarId: String, | ||
@SerializedName("html_url") | ||
val htmlUrl: String, | ||
@SerializedName("id") | ||
val id: Int, | ||
@SerializedName("login") | ||
val login: String, | ||
@SerializedName("node_id") | ||
val nodeId: String, | ||
@SerializedName("organizations_url") | ||
val organizationsUrl: String, | ||
@SerializedName("received_events_url") | ||
val receivedEventsUrl: String, | ||
@SerializedName("repos_url") | ||
val reposUrl: String, | ||
@SerializedName("site_admin") | ||
val siteAdmin: Boolean, | ||
@SerializedName("starred_url") | ||
val starredUrl: String, | ||
@SerializedName("subscriptions_url") | ||
val subscriptionsUrl: String, | ||
@SerializedName("type") | ||
val type: String, | ||
@SerializedName("url") | ||
val url: String | ||
) |
98 changes: 98 additions & 0 deletions
98
github-data/src/main/java/com/example/github/data/repository/remote/data/RemoteGithubData.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,98 @@ | ||
package com.example.github.data.repository.remote.data | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class RemoteGithubData( | ||
@SerializedName("archive_url") | ||
val archiveUrl: String, | ||
@SerializedName("assignees_url") | ||
val assigneesUrl: String, | ||
@SerializedName("blobs_url") | ||
val blobsUrl: String, | ||
@SerializedName("branches_url") | ||
val branchesUrl: String, | ||
@SerializedName("collaborators_url") | ||
val collaboratorsUrl: String, | ||
@SerializedName("comments_url") | ||
val commentsUrl: String, | ||
@SerializedName("commits_url") | ||
val commitsUrl: String, | ||
@SerializedName("compare_url") | ||
val compareUrl: String, | ||
@SerializedName("contents_url") | ||
val contentsUrl: String, | ||
@SerializedName("contributors_url") | ||
val contributorsUrl: String, | ||
@SerializedName("deployments_url") | ||
val deploymentsUrl: String, | ||
@SerializedName("description") | ||
val description: String, | ||
@SerializedName("downloads_url") | ||
val downloadsUrl: String, | ||
@SerializedName("events_url") | ||
val eventsUrl: String, | ||
@SerializedName("fork") | ||
val fork: Boolean, | ||
@SerializedName("forks_url") | ||
val forksUrl: String, | ||
@SerializedName("full_name") | ||
val fullName: String, | ||
@SerializedName("git_commits_url") | ||
val gitCommitsUrl: String, | ||
@SerializedName("git_refs_url") | ||
val gitRefsUrl: String, | ||
@SerializedName("git_tags_url") | ||
val gitTagsUrl: String, | ||
@SerializedName("hooks_url") | ||
val hooksUrl: String, | ||
@SerializedName("html_url") | ||
val htmlUrl: String, | ||
@SerializedName("id") | ||
val id: Int, | ||
@SerializedName("issue_comment_url") | ||
val issueCommentUrl: String, | ||
@SerializedName("issue_events_url") | ||
val issueEventsUrl: String, | ||
@SerializedName("issues_url") | ||
val issuesUrl: String, | ||
@SerializedName("keys_url") | ||
val keysUrl: String, | ||
@SerializedName("labels_url") | ||
val labelsUrl: String, | ||
@SerializedName("languages_url") | ||
val languagesUrl: String, | ||
@SerializedName("merges_url") | ||
val mergesUrl: String, | ||
@SerializedName("milestones_url") | ||
val milestonesUrl: String, | ||
@SerializedName("name") | ||
val name: String, | ||
@SerializedName("node_id") | ||
val nodeId: String, | ||
@SerializedName("notifications_url") | ||
val notificationsUrl: String, | ||
@SerializedName("owner") | ||
val owner: Owner, | ||
@SerializedName("private") | ||
val `private`: Boolean, | ||
@SerializedName("pulls_url") | ||
val pullsUrl: String, | ||
@SerializedName("releases_url") | ||
val releasesUrl: String, | ||
@SerializedName("stargazers_url") | ||
val stargazersUrl: String, | ||
@SerializedName("statuses_url") | ||
val statusesUrl: String, | ||
@SerializedName("subscribers_url") | ||
val subscribersUrl: String, | ||
@SerializedName("subscription_url") | ||
val subscriptionUrl: String, | ||
@SerializedName("tags_url") | ||
val tagsUrl: String, | ||
@SerializedName("teams_url") | ||
val teamsUrl: String, | ||
@SerializedName("trees_url") | ||
val treesUrl: String, | ||
@SerializedName("url") | ||
val url: String | ||
) |
3 changes: 1 addition & 2 deletions
3
...example/github_data/room/GithubRepoDao.kt → ...example/github/data/room/GithubRepoDao.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
2 changes: 1 addition & 1 deletion
2
...le/github_data/room/GithubRepoDatabase.kt → ...le/github/data/room/GithubRepoDatabase.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
8 changes: 4 additions & 4 deletions
8
.../com/example/github_data/room/Injector.kt → .../com/example/github/data/room/Injector.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
10 changes: 0 additions & 10 deletions
10
github-data/src/main/java/com/example/github_data/GitHubApi.kt
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
github-data/src/main/java/com/example/github_data/mapper/Mapper.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.