-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
17 changed files
with
221 additions
and
20 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
20 changes: 20 additions & 0 deletions
20
build-logic/src/main/kotlin/com/droidknights/app2023/CoroutineAndroid.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,20 @@ | ||
package com.droidknights.app2023 | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.dependencies | ||
|
||
internal fun Project.configureCoroutineAndroid() { | ||
val libs = extensions.libs | ||
configureCoroutineKotlin() | ||
dependencies { | ||
"implementation"(libs.findLibrary("coroutines.android").get()) | ||
} | ||
} | ||
|
||
internal fun Project.configureCoroutineKotlin() { | ||
val libs = extensions.libs | ||
dependencies { | ||
"implementation"(libs.findLibrary("coroutines.core").get()) | ||
"testImplementation"(libs.findLibrary("coroutines.test").get()) | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
core/data/src/main/java/com/droidknights/app2023/core/data/di/DataModule.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,18 @@ | ||
package com.droidknights.app2023.core.data.di | ||
|
||
import com.droidknights.app2023.core.data.repository.ContributorRepository | ||
import com.droidknights.app2023.core.data.repository.DefaultContributorRepository | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
internal abstract class DataModule { | ||
|
||
@Binds | ||
abstract fun bindsContributorRepository( | ||
repository: DefaultContributorRepository, | ||
): ContributorRepository | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
plugins { | ||
id("droidknights.kotlin.library") | ||
id("droidknights.android.library") | ||
} | ||
|
||
android { | ||
namespace = "com.droidknights.app2023.core.domain" | ||
} | ||
|
||
dependencies { | ||
implementation(project(":core:data")) | ||
|
||
implementation(libs.inject) | ||
} |
10 changes: 10 additions & 0 deletions
10
core/domain/src/main/java/com/droidknights/app2023/core/domain/mapper/ContributorMapper.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.droidknights.app2023.core.domain.mapper | ||
|
||
import com.droidknights.app2023.core.data.model.ContributorEntity | ||
import com.droidknights.app2023.core.domain.model.Contributor | ||
|
||
internal fun ContributorEntity.toDomain(): Contributor = | ||
Contributor( | ||
name = this.name, | ||
imageUrl = this.imageUrl | ||
) |
6 changes: 6 additions & 0 deletions
6
core/domain/src/main/java/com/droidknights/app2023/core/domain/model/Contributor.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,6 @@ | ||
package com.droidknights.app2023.core.domain.model | ||
|
||
data class Contributor( | ||
val name: String, | ||
val imageUrl: String, | ||
) |
24 changes: 24 additions & 0 deletions
24
...main/src/main/java/com/droidknights/app2023/core/domain/usecase/GetContributorsUseCase.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,24 @@ | ||
package com.droidknights.app2023.core.domain.usecase | ||
|
||
import com.droidknights.app2023.core.data.model.ContributorEntity | ||
import com.droidknights.app2023.core.data.repository.ContributorRepository | ||
import com.droidknights.app2023.core.domain.mapper.toDomain | ||
import com.droidknights.app2023.core.domain.model.Contributor | ||
import javax.inject.Inject | ||
|
||
class GetContributorsUseCase @Inject constructor( | ||
private val repository: ContributorRepository, | ||
) { | ||
suspend operator fun invoke(): List<Contributor> { | ||
return repository.getContributors( | ||
owner = OWNER, | ||
name = NAME, | ||
).map(ContributorEntity::toDomain) | ||
} | ||
|
||
companion object { | ||
private const val OWNER = "droidknights" | ||
// TODO: DroidKnights2023_App로 변경 필요 | ||
private const val NAME = "DroidKnights2021_App" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...n/src/test/java/com/droidknights/app2023/core/domain/usecase/FakeContributorRepository.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,12 @@ | ||
package com.droidknights.app2023.core.domain.usecase | ||
|
||
import com.droidknights.app2023.core.data.model.ContributorEntity | ||
import com.droidknights.app2023.core.data.repository.ContributorRepository | ||
|
||
internal class FakeContributorRepository( | ||
private val contributors: List<ContributorEntity>, | ||
) : ContributorRepository { | ||
override suspend fun getContributors(owner: String, name: String): List<ContributorEntity> { | ||
return contributors | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
.../src/test/java/com/droidknights/app2023/core/domain/usecase/GetContributorsUseCaseTest.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,39 @@ | ||
package com.droidknights.app2023.core.domain.usecase | ||
|
||
import com.droidknights.app2023.core.data.model.ContributorEntity | ||
import com.droidknights.app2023.core.domain.model.Contributor | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
internal class GetContributorsUseCaseTest : BehaviorSpec() { | ||
|
||
private val useCase: GetContributorsUseCase = GetContributorsUseCase( | ||
repository = FakeContributorRepository(contributors) | ||
) | ||
|
||
init { | ||
Given("드로이드나이츠 컨트리뷰터가 존재한다") { | ||
val expected = contributors | ||
|
||
When("드로이드나이츠 컨트리뷰터를 조회한다") { | ||
val contributors: List<Contributor> = useCase.invoke() | ||
|
||
Then("드로이드나이츠 컨트리뷰터를 반환한다") { | ||
contributors.size shouldBe 1 | ||
contributors.all { | ||
it.name == expected[0].name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
private val contributors = listOf( | ||
ContributorEntity( | ||
name = "test name", | ||
imageUrl = "test image url" | ||
) | ||
) | ||
} | ||
} |
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
Empty file.
27 changes: 27 additions & 0 deletions
27
...ibutor/src/main/java/com/droidknights/app2023/feature/contributor/ContributorViewModel.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,27 @@ | ||
package com.droidknights.app2023.feature.contributor | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.droidknights.app2023.core.domain.usecase.GetContributorsUseCase | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.stateIn | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class ContributorViewModel @Inject constructor( | ||
getContributorsUseCase: GetContributorsUseCase, | ||
) : ViewModel() { | ||
|
||
val uiState: StateFlow<ContributorsUiState> = | ||
flow { emit(getContributorsUseCase()) }.map( | ||
ContributorsUiState::Contributors, | ||
).stateIn( | ||
scope = viewModelScope, | ||
started = SharingStarted.WhileSubscribed(5_000), | ||
initialValue = ContributorsUiState.Loading, | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
...ributor/src/main/java/com/droidknights/app2023/feature/contributor/ContributorsUiState.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,11 @@ | ||
package com.droidknights.app2023.feature.contributor | ||
|
||
import com.droidknights.app2023.core.domain.model.Contributor | ||
|
||
sealed interface ContributorsUiState { | ||
object Loading : ContributorsUiState | ||
|
||
data class Contributors( | ||
val contributors: List<Contributor>, | ||
) : ContributorsUiState | ||
} |
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