From 7ab8315719733f795a1b0a1ba125d4b384819727 Mon Sep 17 00:00:00 2001 From: b1urrrr Date: Fri, 21 Apr 2023 22:41:39 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT/#3]=20Repo=20=EA=B0=80=EC=A0=B8=EC=98=A4?= =?UTF-8?q?=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EB=A0=88=EC=9D=B4=EC=96=B4=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../go/sopt/data/entity/MockRepoDto.kt | 194 ++++++++++++++++++ .../org/android/go/sopt/data/entity/Repo.kt | 9 - .../data/repository/AuthRepositoryImpl.kt | 2 +- .../data/repository/RepoRepositoryImpl.kt | 14 ++ .../go/sopt/data/service/RepoService.kt | 9 + .../go/sopt/data/source/RepoDataSource.kt | 11 + .../android/go/sopt/di/RepositoryModule.kt | 2 +- .../org/android/go/sopt/domain/model/Repo.kt | 8 + .../domain/{ => repository}/AuthRepository.kt | 2 +- .../sopt/domain/repository/RepoRepository.kt | 7 + .../sopt/presentation/login/LoginViewModel.kt | 2 +- .../sopt/presentation/main/MainViewModel.kt | 2 +- .../presentation/main/home/HomeViewModel.kt | 45 +--- .../presentation/main/home/RepoItemAdapter.kt | 10 +- .../presentation/signup/SignupViewModel.kt | 2 +- app/src/main/res/layout/item_home_repo.xml | 2 +- 16 files changed, 260 insertions(+), 61 deletions(-) create mode 100644 app/src/main/java/org/android/go/sopt/data/entity/MockRepoDto.kt delete mode 100644 app/src/main/java/org/android/go/sopt/data/entity/Repo.kt create mode 100644 app/src/main/java/org/android/go/sopt/data/repository/RepoRepositoryImpl.kt create mode 100644 app/src/main/java/org/android/go/sopt/data/service/RepoService.kt create mode 100644 app/src/main/java/org/android/go/sopt/data/source/RepoDataSource.kt create mode 100644 app/src/main/java/org/android/go/sopt/domain/model/Repo.kt rename app/src/main/java/org/android/go/sopt/domain/{ => repository}/AuthRepository.kt (84%) create mode 100644 app/src/main/java/org/android/go/sopt/domain/repository/RepoRepository.kt diff --git a/app/src/main/java/org/android/go/sopt/data/entity/MockRepoDto.kt b/app/src/main/java/org/android/go/sopt/data/entity/MockRepoDto.kt new file mode 100644 index 0000000..016073a --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/data/entity/MockRepoDto.kt @@ -0,0 +1,194 @@ +package org.android.go.sopt.data.entity + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import org.android.go.sopt.domain.model.Repo + +@Serializable +data class MockRepoDto( + @SerialName("allow_forking") + val allowForking: Boolean, + @SerialName("archive_url") + val archiveUrl: String, + val archived: Boolean, + @SerialName("assignees_url") + val assigneesUrl: String, + @SerialName("blobs_url") + val blobsUrl: String, + @SerialName("branches_url") + val branchesUrl: String, + @SerialName("clone_url") + val cloneUrl: String, + @SerialName("collaborators_url") + val collaboratorsUrl: String, + @SerialName("comments_url") + val commentsUrl: String, + @SerialName("commits_url") + val commitsUrl: String, + @SerialName("compare_url") + val compareUrl: String, + @SerialName("contents_url") + val contentsUrl: String, + @SerialName("contributors_url") + val contributorsUrl: String, + @SerialName("created_at") + val createdAt: String, + @SerialName("default_branch") + val defaultBranch: String, + @SerialName("deployments_url") + val deploymentsUrl: String, + val description: String, + val disabled: Boolean, + @SerialName("downloads_url") + val downloadsUrl: String, + @SerialName("events_url") + val eventsUrl: String, + val fork: Boolean, + val forks: Int, + @SerialName("forks_count") + val forksCount: Int, + @SerialName("forks_url") + val forksUrl: String, + @SerialName("full_name") + val fullName: String, + @SerialName("git_commits_url") + val gitCommitsUrl: String, + @SerialName("git_refs_url") + val gitRefsUrl: String, + @SerialName("git_tags_url") + val gitTagsUrl: String, + @SerialName("git_url") + val gitUrl: String, + @SerialName("has_discussions") + val hasDiscussions: Boolean, + @SerialName("has_downloads") + val hasDownloads: Boolean, + @SerialName("has_issues") + val hasIssues: Boolean, + @SerialName("has_pages") + val hasPages: Boolean, + @SerialName("has_projects") + val hasProjects: Boolean, + @SerialName("has_wiki") + val hasWiki: Boolean, + val homepage: String, + @SerialName("hooks_url") + val hooksUrl: String, + @SerialName("html_url") + val htmlUrl: String, + val id: Int, + @SerialName("is_template") + val isTemplate: Boolean, + @SerialName("issue_comment_url") + val issueCommentUrl: String, + @SerialName("issue_events_url") + val issueEventsUrl: String, + @SerialName("issues_url") + val issuesUrl: String, + @SerialName("keys_url") + val keysUrl: String, + @SerialName("labels_url") + val labelsUrl: String, + val language: String, + @SerialName("languages_url") + val languagesUrl: String, + val license: Any, + @SerialName("merges_url") + val mergesUrl: String, + @SerialName("milestones_url") + val milestonesUrl: String, + @SerialName("mirror_url") + val mirrorUrl: Any, + val name: String, + @SerialName("node_id") + val nodeId: String, + @SerialName("notifications_url") + val notificationsUrl: String, + @SerialName("open_issues") + val openIssues: Int, + @SerialName("open_issues_count") + val openIssuesCount: Int, + val owner: Owner, + @SerialName("`private`") + val isPrivate: Boolean, + @SerialName("pulls_url") + val pullsUrl: String, + @SerialName("pushed_at") + val pushedAt: String, + @SerialName("releases_url") + val releasesUrl: String, + val size: Int, + @SerialName("ssh_url") + val sshUrl: String, + @SerialName("stargazers_count") + val stargazersCount: Int, + @SerialName("stargazers_url") + val stargazersUrl: String, + @SerialName("statuses_url") + val statusesUrl: String, + @SerialName("subscribers_url") + val subscribersUrl: String, + @SerialName("subscription_url") + val subscriptionUrl: String, + @SerialName("svn_url") + val svnUrl: String, + @SerialName("tags_url") + val tagsUrl: String, + @SerialName("teams_url") + val teamsUrl: String, + val topics: List, + @SerialName("trees_url") + val treesUrl: String, + @SerialName("updated_at") + val updatedAt: String, + val url: String, + val visibility: String, + val watchers: Int, + @SerialName("watchers_count") + val watchersCount: Int, + @SerialName("web_commit_signoff_required") + val webCommitSignoffRequired: Boolean, +) { + @Serializable + data class Owner( + @SerialName("avatar_url") + val avatarUrl: String, + @SerialName("events_url") + val eventsUrl: String, + @SerialName("followers_url") + val followersUrl: String, + @SerialName("following_url") + val followingUrl: String, + @SerialName("gists_url") + val gistsUrl: String, + @SerialName("gravatar_id") + val gravatarId: String, + @SerialName("html_url") + val htmlUrl: String, + val id: Int, + val login: String, + @SerialName("node_id") + val nodeId: String, + @SerialName("organizations_url") + val organizationsUrl: String, + @SerialName("received_events_url") + val receivedEventsUrl: String, + @SerialName("repos_url") + val reposUrl: String, + @SerialName("site_admin") + val siteAdmin: Boolean, + @SerialName("starred_url") + val starredUrl: String, + @SerialName("subscriptions_url") + val subscriptionsUrl: String, + val type: String, + val url: String, + ) + + fun toRepo() = Repo( + id = id, + image = owner.avatarUrl, + name = name, + owner = owner.login, + ) +} diff --git a/app/src/main/java/org/android/go/sopt/data/entity/Repo.kt b/app/src/main/java/org/android/go/sopt/data/entity/Repo.kt deleted file mode 100644 index 218b970..0000000 --- a/app/src/main/java/org/android/go/sopt/data/entity/Repo.kt +++ /dev/null @@ -1,9 +0,0 @@ -package org.android.go.sopt.data.entity - -import androidx.annotation.DrawableRes - -data class Repo( - @DrawableRes val image: Int, - val name: String, - val author: String, -) diff --git a/app/src/main/java/org/android/go/sopt/data/repository/AuthRepositoryImpl.kt b/app/src/main/java/org/android/go/sopt/data/repository/AuthRepositoryImpl.kt index da979be..cae0002 100644 --- a/app/src/main/java/org/android/go/sopt/data/repository/AuthRepositoryImpl.kt +++ b/app/src/main/java/org/android/go/sopt/data/repository/AuthRepositoryImpl.kt @@ -2,7 +2,7 @@ package org.android.go.sopt.data.repository import org.android.go.sopt.data.entity.User import org.android.go.sopt.data.source.LocalPrefDataSource -import org.android.go.sopt.domain.AuthRepository +import org.android.go.sopt.domain.repository.AuthRepository import javax.inject.Inject class AuthRepositoryImpl @Inject constructor( diff --git a/app/src/main/java/org/android/go/sopt/data/repository/RepoRepositoryImpl.kt b/app/src/main/java/org/android/go/sopt/data/repository/RepoRepositoryImpl.kt new file mode 100644 index 0000000..d3bdbfc --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/data/repository/RepoRepositoryImpl.kt @@ -0,0 +1,14 @@ +package org.android.go.sopt.data.repository + +import org.android.go.sopt.data.source.RepoDataSource +import org.android.go.sopt.domain.model.Repo +import org.android.go.sopt.domain.repository.RepoRepository +import javax.inject.Inject + +class RepoRepositoryImpl @Inject constructor( + private val repoDataSource: RepoDataSource, +) : RepoRepository { + override suspend fun getRepoList(): Result = runCatching { + repoDataSource.getRepoList().toRepo() + } +} diff --git a/app/src/main/java/org/android/go/sopt/data/service/RepoService.kt b/app/src/main/java/org/android/go/sopt/data/service/RepoService.kt new file mode 100644 index 0000000..b1a653f --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/data/service/RepoService.kt @@ -0,0 +1,9 @@ +package org.android.go.sopt.data.service + +import org.android.go.sopt.data.entity.MockRepoDto +import retrofit2.http.GET + +interface RepoService { + @GET("fake_repo_list.json") + suspend fun getRepoList(): MockRepoDto +} diff --git a/app/src/main/java/org/android/go/sopt/data/source/RepoDataSource.kt b/app/src/main/java/org/android/go/sopt/data/source/RepoDataSource.kt new file mode 100644 index 0000000..9301a91 --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/data/source/RepoDataSource.kt @@ -0,0 +1,11 @@ +package org.android.go.sopt.data.source + +import org.android.go.sopt.data.entity.MockRepoDto +import org.android.go.sopt.data.service.RepoService +import javax.inject.Inject + +class RepoDataSource @Inject constructor( + private val repoService: RepoService, +) { + suspend fun getRepoList(): MockRepoDto = repoService.getRepoList() +} diff --git a/app/src/main/java/org/android/go/sopt/di/RepositoryModule.kt b/app/src/main/java/org/android/go/sopt/di/RepositoryModule.kt index 201752f..3d5d20d 100644 --- a/app/src/main/java/org/android/go/sopt/di/RepositoryModule.kt +++ b/app/src/main/java/org/android/go/sopt/di/RepositoryModule.kt @@ -5,7 +5,7 @@ import dagger.Module import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import org.android.go.sopt.data.repository.AuthRepositoryImpl -import org.android.go.sopt.domain.AuthRepository +import org.android.go.sopt.domain.repository.AuthRepository import javax.inject.Singleton @Module diff --git a/app/src/main/java/org/android/go/sopt/domain/model/Repo.kt b/app/src/main/java/org/android/go/sopt/domain/model/Repo.kt new file mode 100644 index 0000000..a9ed518 --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/domain/model/Repo.kt @@ -0,0 +1,8 @@ +package org.android.go.sopt.domain.model + +data class Repo( + val id: Int, + val image: String, + val name: String, + val owner: String, +) diff --git a/app/src/main/java/org/android/go/sopt/domain/AuthRepository.kt b/app/src/main/java/org/android/go/sopt/domain/repository/AuthRepository.kt similarity index 84% rename from app/src/main/java/org/android/go/sopt/domain/AuthRepository.kt rename to app/src/main/java/org/android/go/sopt/domain/repository/AuthRepository.kt index e909efb..49ef5a0 100644 --- a/app/src/main/java/org/android/go/sopt/domain/AuthRepository.kt +++ b/app/src/main/java/org/android/go/sopt/domain/repository/AuthRepository.kt @@ -1,4 +1,4 @@ -package org.android.go.sopt.domain +package org.android.go.sopt.domain.repository import org.android.go.sopt.data.entity.User diff --git a/app/src/main/java/org/android/go/sopt/domain/repository/RepoRepository.kt b/app/src/main/java/org/android/go/sopt/domain/repository/RepoRepository.kt new file mode 100644 index 0000000..9b6d030 --- /dev/null +++ b/app/src/main/java/org/android/go/sopt/domain/repository/RepoRepository.kt @@ -0,0 +1,7 @@ +package org.android.go.sopt.domain.repository + +import org.android.go.sopt.domain.model.Repo + +interface RepoRepository { + suspend fun getRepoList(): Result +} diff --git a/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt b/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt index e5deb6a..b6ea258 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/login/LoginViewModel.kt @@ -5,7 +5,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import dagger.hilt.android.lifecycle.HiltViewModel import org.android.go.sopt.data.entity.User -import org.android.go.sopt.domain.AuthRepository +import org.android.go.sopt.domain.repository.AuthRepository import org.android.go.sopt.util.UiState import org.android.go.sopt.util.UiState.Failure import org.android.go.sopt.util.UiState.Success diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/MainViewModel.kt b/app/src/main/java/org/android/go/sopt/presentation/main/MainViewModel.kt index 7a75295..4fbe58e 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/main/MainViewModel.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/main/MainViewModel.kt @@ -4,7 +4,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import dagger.hilt.android.lifecycle.HiltViewModel import org.android.go.sopt.data.entity.User -import org.android.go.sopt.domain.AuthRepository +import org.android.go.sopt.domain.repository.AuthRepository import javax.inject.Inject @HiltViewModel diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeViewModel.kt b/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeViewModel.kt index f08f475..d120935 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeViewModel.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/main/home/HomeViewModel.kt @@ -2,47 +2,12 @@ package org.android.go.sopt.presentation.main.home import androidx.lifecycle.ViewModel import dagger.hilt.android.lifecycle.HiltViewModel -import org.android.go.sopt.R -import org.android.go.sopt.data.entity.Repo +import org.android.go.sopt.domain.repository.RepoRepository import javax.inject.Inject @HiltViewModel -class HomeViewModel @Inject constructor() : ViewModel() { - val mockRepoList = listOf( - Repo( - image = R.drawable.img_main_profile, - name = "Keyneez", - author = "Chaeyeon", - ), - Repo( - image = R.drawable.img_main_profile, - name = "Keyneez-Release", - author = "Chaeyeon", - ), - Repo( - image = R.drawable.img_main_profile, - name = "Algorithm-Study", - author = "Chaeyeon", - ), - Repo( - image = R.drawable.img_main_profile, - name = "Kotlin-Study", - author = "Chaeyeon", - ), - Repo( - image = R.drawable.img_main_profile, - name = "Aladin-AOS", - author = "2zerozu", - ), - Repo( - image = R.drawable.img_main_profile, - name = "Book-Nuts", - author = "Nuts", - ), - Repo( - image = R.drawable.img_main_profile, - name = "SujungVillage", - author = "Chaeyeon", - ), - ) +class HomeViewModel @Inject constructor( + private val repoRepository: RepoRepository, +) : ViewModel() { + // TODO : getRepoList 호출 및 UI 보여주는 로직 작성 } diff --git a/app/src/main/java/org/android/go/sopt/presentation/main/home/RepoItemAdapter.kt b/app/src/main/java/org/android/go/sopt/presentation/main/home/RepoItemAdapter.kt index 3c699c9..9803e90 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/main/home/RepoItemAdapter.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/main/home/RepoItemAdapter.kt @@ -4,12 +4,12 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView -import org.android.go.sopt.data.entity.Repo +import org.android.go.sopt.data.entity.MockRepoDto import org.android.go.sopt.databinding.ItemHomeRepoBinding import org.android.go.sopt.util.DiffCallback class RepoItemAdapter : - ListAdapter(diffUtil) { + ListAdapter(diffUtil) { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { return RepoViewHolder( ItemHomeRepoBinding.inflate( @@ -26,14 +26,14 @@ class RepoItemAdapter : class RepoViewHolder(private val binding: ItemHomeRepoBinding) : RecyclerView.ViewHolder(binding.root) { - fun setRepo(repo: Repo) { + fun setRepo(repo: MockRepoDto) { binding.data = repo } } companion object { - private val diffUtil = DiffCallback( - onItemsTheSame = { old, new -> old.name == new.name && old.author == new.author }, + private val diffUtil = DiffCallback( + onItemsTheSame = { old, new -> old.name == new.name }, onContentsTheSame = { old, new -> old == new }, ) } diff --git a/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt b/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt index 5835ee6..0a5f134 100644 --- a/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt +++ b/app/src/main/java/org/android/go/sopt/presentation/signup/SignupViewModel.kt @@ -5,7 +5,7 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import dagger.hilt.android.lifecycle.HiltViewModel import org.android.go.sopt.data.entity.User -import org.android.go.sopt.domain.AuthRepository +import org.android.go.sopt.domain.repository.AuthRepository import org.android.go.sopt.util.UiState import org.android.go.sopt.util.UiState.Failure import org.android.go.sopt.util.UiState.Success diff --git a/app/src/main/res/layout/item_home_repo.xml b/app/src/main/res/layout/item_home_repo.xml index b748307..111958f 100644 --- a/app/src/main/res/layout/item_home_repo.xml +++ b/app/src/main/res/layout/item_home_repo.xml @@ -6,7 +6,7 @@ + type="org.android.go.sopt.data.entity.MockRepoDto" />