Skip to content

Commit

Permalink
[FEAT/#3] Repo 가져오는 로직 레이어 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
b1urrrr committed Apr 21, 2023
1 parent 9b20609 commit 7ab8315
Show file tree
Hide file tree
Showing 16 changed files with 260 additions and 61 deletions.
194 changes: 194 additions & 0 deletions app/src/main/java/org/android/go/sopt/data/entity/MockRepoDto.kt
Original file line number Diff line number Diff line change
@@ -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<String>,
@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,
)
}
9 changes: 0 additions & 9 deletions app/src/main/java/org/android/go/sopt/data/entity/Repo.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Repo> = runCatching {
repoDataSource.getRepoList().toRepo()
}
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/org/android/go/sopt/domain/model/Repo.kt
Original file line number Diff line number Diff line change
@@ -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,
)
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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<Repo>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 보여주는 로직 작성
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Repo, RecyclerView.ViewHolder>(diffUtil) {
ListAdapter<MockRepoDto, RecyclerView.ViewHolder>(diffUtil) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return RepoViewHolder(
ItemHomeRepoBinding.inflate(
Expand All @@ -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<Repo>(
onItemsTheSame = { old, new -> old.name == new.name && old.author == new.author },
private val diffUtil = DiffCallback<MockRepoDto>(
onItemsTheSame = { old, new -> old.name == new.name },
onContentsTheSame = { old, new -> old == new },
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 7ab8315

Please sign in to comment.