From d3f8a7a7c49cbde3be26a15c30cfae5ae07ef547 Mon Sep 17 00:00:00 2001 From: Youngjik Yoon Date: Sun, 16 Jul 2023 14:56:39 +0900 Subject: [PATCH 01/12] =?UTF-8?q?#50=20Github=20Raw=20api=EB=A5=BC=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=9C=20?= =?UTF-8?q?=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app2023/core/data/api/GithubRawApi.kt | 3 +++ .../app2023/core/data/di/ApiModule.kt | 20 +++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 core/data/src/main/java/com/droidknights/app2023/core/data/api/GithubRawApi.kt diff --git a/core/data/src/main/java/com/droidknights/app2023/core/data/api/GithubRawApi.kt b/core/data/src/main/java/com/droidknights/app2023/core/data/api/GithubRawApi.kt new file mode 100644 index 00000000..7c6d749d --- /dev/null +++ b/core/data/src/main/java/com/droidknights/app2023/core/data/api/GithubRawApi.kt @@ -0,0 +1,3 @@ +package com.droidknights.app2023.core.data.api + +internal interface GithubRawApi diff --git a/core/data/src/main/java/com/droidknights/app2023/core/data/di/ApiModule.kt b/core/data/src/main/java/com/droidknights/app2023/core/data/di/ApiModule.kt index 8e399eb1..0818a89c 100644 --- a/core/data/src/main/java/com/droidknights/app2023/core/data/di/ApiModule.kt +++ b/core/data/src/main/java/com/droidknights/app2023/core/data/di/ApiModule.kt @@ -1,6 +1,7 @@ package com.droidknights.app2023.core.data.di import com.droidknights.app2023.core.data.api.GithubApi +import com.droidknights.app2023.core.data.api.GithubRawApi import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory import dagger.Module import dagger.Provides @@ -16,11 +17,11 @@ import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) internal object ApiModule { - + @Provides @Singleton fun provideOkhttpClient(): OkHttpClient = OkHttpClient.Builder().build() - + @Provides @Singleton fun provideConverterFactory( @@ -28,7 +29,7 @@ internal object ApiModule { ): Converter.Factory { return json.asConverterFactory("application/json".toMediaType()) } - + @Provides @Singleton fun provideGithubApi( @@ -41,7 +42,18 @@ internal object ApiModule { .client(okHttpClient).build() .create(GithubApi::class.java) } - + + @Provides + @Singleton + fun provideGitRawApi( + okHttpClient: OkHttpClient, + converterFactory: Converter.Factory, + ): GithubRawApi = Retrofit.Builder() + .baseUrl("https://raw.githubusercontent.com/") + .addConverterFactory(converterFactory) + .client(okHttpClient).build() + .create(GithubRawApi::class.java) + @Provides @Singleton fun provideJson(): Json = Json { From 1a33af9ae2cf9dc005c554b882e31caa8910bc69 Mon Sep 17 00:00:00 2001 From: Youngjik Yoon Date: Sun, 16 Jul 2023 16:42:05 +0900 Subject: [PATCH 02/12] =?UTF-8?q?#50=20Sponsor=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=EB=AA=A8=EB=8D=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/data/api/model/SponsorResponse.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 core/data/src/main/java/com/droidknights/app2023/core/data/api/model/SponsorResponse.kt diff --git a/core/data/src/main/java/com/droidknights/app2023/core/data/api/model/SponsorResponse.kt b/core/data/src/main/java/com/droidknights/app2023/core/data/api/model/SponsorResponse.kt new file mode 100644 index 00000000..2333019e --- /dev/null +++ b/core/data/src/main/java/com/droidknights/app2023/core/data/api/model/SponsorResponse.kt @@ -0,0 +1,21 @@ +package com.droidknights.app2023.core.data.api.model + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +internal data class SponsorResponse( + @SerialName("name") val name: String, + @SerialName("imageUrl") val imageUrl: String, + @SerialName("homepage") val homepage: String, + @SerialName("grade") val grade: Grade, +) { + + enum class Grade { + @SerialName("platinum") + PLATINUM, + + @SerialName("gold") + GOLD, + } +} From 14ce11f5f119e972a95db125a0c2592d7f6b079f Mon Sep 17 00:00:00 2001 From: Youngjik Yoon Date: Sun, 16 Jul 2023 16:42:12 +0900 Subject: [PATCH 03/12] =?UTF-8?q?#50=20Sponsor=20=EC=97=94=ED=84=B0?= =?UTF-8?q?=ED=8B=B0=20=EB=AA=A8=EB=8D=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app2023/core/data/model/SponsorEntity.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 core/data/src/main/java/com/droidknights/app2023/core/data/model/SponsorEntity.kt diff --git a/core/data/src/main/java/com/droidknights/app2023/core/data/model/SponsorEntity.kt b/core/data/src/main/java/com/droidknights/app2023/core/data/model/SponsorEntity.kt new file mode 100644 index 00000000..690da57b --- /dev/null +++ b/core/data/src/main/java/com/droidknights/app2023/core/data/model/SponsorEntity.kt @@ -0,0 +1,10 @@ +package com.droidknights.app2023.core.data.model + +data class SponsorEntity( + val name: String, + val imageUrl: String, + val homepage: String, + val grade: Grade, +) { + enum class Grade { PLATINUM, GOLD, } +} From c6d7ee1a12fc53251e9d95f3971536fceae26ee0 Mon Sep 17 00:00:00 2001 From: Youngjik Yoon Date: Sun, 16 Jul 2023 16:43:23 +0900 Subject: [PATCH 04/12] =?UTF-8?q?#50=20SponsorResponse=20->=20Sponsor=20Ma?= =?UTF-8?q?pper=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app2023/core/data/mapper/SponsorMapper.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 core/data/src/main/java/com/droidknights/app2023/core/data/mapper/SponsorMapper.kt diff --git a/core/data/src/main/java/com/droidknights/app2023/core/data/mapper/SponsorMapper.kt b/core/data/src/main/java/com/droidknights/app2023/core/data/mapper/SponsorMapper.kt new file mode 100644 index 00000000..9a6b46c1 --- /dev/null +++ b/core/data/src/main/java/com/droidknights/app2023/core/data/mapper/SponsorMapper.kt @@ -0,0 +1,14 @@ +package com.droidknights.app2023.core.data.mapper + +import com.droidknights.app2023.core.data.api.model.SponsorResponse +import com.droidknights.app2023.core.data.model.SponsorEntity + +internal fun SponsorResponse.toData(): SponsorEntity = SponsorEntity( + name = name, + imageUrl = imageUrl, + homepage = homepage, + grade = when (grade) { + SponsorResponse.Grade.PLATINUM -> SponsorEntity.Grade.PLATINUM + SponsorResponse.Grade.GOLD -> SponsorEntity.Grade.GOLD + } +) From 4b997ecc949303f96e1efeb97c63be01072b2fea Mon Sep 17 00:00:00 2001 From: Youngjik Yoon Date: Sun, 16 Jul 2023 16:43:57 +0900 Subject: [PATCH 05/12] =?UTF-8?q?#50=20/sponsors=20API=20=EC=9D=B8?= =?UTF-8?q?=ED=84=B0=ED=8E=98=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../droidknights/app2023/core/data/api/GithubRawApi.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/data/src/main/java/com/droidknights/app2023/core/data/api/GithubRawApi.kt b/core/data/src/main/java/com/droidknights/app2023/core/data/api/GithubRawApi.kt index 7c6d749d..c3666ab5 100644 --- a/core/data/src/main/java/com/droidknights/app2023/core/data/api/GithubRawApi.kt +++ b/core/data/src/main/java/com/droidknights/app2023/core/data/api/GithubRawApi.kt @@ -1,3 +1,10 @@ package com.droidknights.app2023.core.data.api -internal interface GithubRawApi +import com.droidknights.app2023.core.data.api.model.SponsorResponse +import retrofit2.http.GET + +internal interface GithubRawApi { + + @GET("/droidknights/DroidKnights2023_App/main/data/src/main/assets/sponsors.json") + suspend fun getSponsors(): List +} From 492f08228fc77237093d1aad4d0d7d94bbf7bd67 Mon Sep 17 00:00:00 2001 From: Youngjik Yoon Date: Sun, 16 Jul 2023 16:44:47 +0900 Subject: [PATCH 06/12] =?UTF-8?q?#50=20SponsorRepository=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/data/src/main/assets/sponsors.json | 8 ++++++ .../app2023/core/data/di/DataModule.kt | 9 +++++- .../repository/DefaultSponsorRepository.kt | 15 ++++++++++ .../core/data/repository/SponsorRepository.kt | 8 ++++++ .../core/data/fake/FakeGithubRawApi.kt | 17 +++++++++++ .../DefaultSponsorRepositoryTest.kt | 28 +++++++++++++++++++ 6 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 core/data/src/main/assets/sponsors.json create mode 100644 core/data/src/main/java/com/droidknights/app2023/core/data/repository/DefaultSponsorRepository.kt create mode 100644 core/data/src/main/java/com/droidknights/app2023/core/data/repository/SponsorRepository.kt create mode 100644 core/data/src/test/java/com/droidknights/app2023/core/data/fake/FakeGithubRawApi.kt create mode 100644 core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultSponsorRepositoryTest.kt diff --git a/core/data/src/main/assets/sponsors.json b/core/data/src/main/assets/sponsors.json new file mode 100644 index 00000000..7052ec20 --- /dev/null +++ b/core/data/src/main/assets/sponsors.json @@ -0,0 +1,8 @@ +[ + { + "name": "헤이딜러", + "imageUrl": "https://raw.githubusercontent.com/droidknights/DroidKnights2020_App/master/androidapp/app/src/main/res/drawable-xxxhdpi/ic_sponsor_heydealer.png", + "homepage": "https://heydealer.co.kr/", + "grade": "gold" + } +] diff --git a/core/data/src/main/java/com/droidknights/app2023/core/data/di/DataModule.kt b/core/data/src/main/java/com/droidknights/app2023/core/data/di/DataModule.kt index 3e1d796f..63c0c19c 100644 --- a/core/data/src/main/java/com/droidknights/app2023/core/data/di/DataModule.kt +++ b/core/data/src/main/java/com/droidknights/app2023/core/data/di/DataModule.kt @@ -2,6 +2,8 @@ package com.droidknights.app2023.core.data.di import com.droidknights.app2023.core.data.repository.ContributorRepository import com.droidknights.app2023.core.data.repository.DefaultContributorRepository +import com.droidknights.app2023.core.data.repository.DefaultSponsorRepository +import com.droidknights.app2023.core.data.repository.SponsorRepository import dagger.Binds import dagger.Module import dagger.hilt.InstallIn @@ -10,9 +12,14 @@ import dagger.hilt.components.SingletonComponent @InstallIn(SingletonComponent::class) @Module internal abstract class DataModule { - + @Binds abstract fun bindsContributorRepository( repository: DefaultContributorRepository, ): ContributorRepository + + @Binds + abstract fun bindsSponsorRepository( + repository: DefaultSponsorRepository, + ): SponsorRepository } diff --git a/core/data/src/main/java/com/droidknights/app2023/core/data/repository/DefaultSponsorRepository.kt b/core/data/src/main/java/com/droidknights/app2023/core/data/repository/DefaultSponsorRepository.kt new file mode 100644 index 00000000..7f870db8 --- /dev/null +++ b/core/data/src/main/java/com/droidknights/app2023/core/data/repository/DefaultSponsorRepository.kt @@ -0,0 +1,15 @@ +package com.droidknights.app2023.core.data.repository + +import com.droidknights.app2023.core.data.api.GithubRawApi +import com.droidknights.app2023.core.data.mapper.toData +import com.droidknights.app2023.core.data.model.SponsorEntity +import javax.inject.Inject + +internal class DefaultSponsorRepository @Inject constructor( + private val githubRawApi: GithubRawApi, +) : SponsorRepository { + + override suspend fun getSponsors(): List { + return githubRawApi.getSponsors().map { it.toData() } + } +} diff --git a/core/data/src/main/java/com/droidknights/app2023/core/data/repository/SponsorRepository.kt b/core/data/src/main/java/com/droidknights/app2023/core/data/repository/SponsorRepository.kt new file mode 100644 index 00000000..36c771aa --- /dev/null +++ b/core/data/src/main/java/com/droidknights/app2023/core/data/repository/SponsorRepository.kt @@ -0,0 +1,8 @@ +package com.droidknights.app2023.core.data.repository + +import com.droidknights.app2023.core.data.model.SponsorEntity + +interface SponsorRepository { + + suspend fun getSponsors(): List +} diff --git a/core/data/src/test/java/com/droidknights/app2023/core/data/fake/FakeGithubRawApi.kt b/core/data/src/test/java/com/droidknights/app2023/core/data/fake/FakeGithubRawApi.kt new file mode 100644 index 00000000..891101ad --- /dev/null +++ b/core/data/src/test/java/com/droidknights/app2023/core/data/fake/FakeGithubRawApi.kt @@ -0,0 +1,17 @@ +package com.droidknights.app2023.core.data.fake + +import com.droidknights.app2023.core.data.api.GithubRawApi +import com.droidknights.app2023.core.data.api.model.SponsorResponse +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.decodeFromStream +import java.io.File + +internal class FakeGithubRawApi( + private val json: Json = Json { ignoreUnknownKeys = true }, +) : GithubRawApi { + private val assets = File("src/main/assets/sponsors.json") + + override suspend fun getSponsors(): List { + return json.decodeFromStream(assets.inputStream()) + } +} diff --git a/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultSponsorRepositoryTest.kt b/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultSponsorRepositoryTest.kt new file mode 100644 index 00000000..e72ade7d --- /dev/null +++ b/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultSponsorRepositoryTest.kt @@ -0,0 +1,28 @@ +package com.droidknights.app2023.core.data.repository + +import com.droidknights.app2023.core.data.fake.FakeGithubRawApi +import com.droidknights.app2023.core.data.model.SponsorEntity +import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.shouldBe +import kotlinx.serialization.json.Json + +internal class DefaultSponsorRepositoryTest : StringSpec() { + + init { + val repository: SponsorRepository = DefaultSponsorRepository( + githubRawApi = FakeGithubRawApi( + json = Json { ignoreUnknownKeys = true }, + ) + ) + "역직렬화 테스트" { + val expected = SponsorEntity( + name = "헤이딜러", + imageUrl = "https://raw.githubusercontent.com/droidknights/DroidKnights2020_App/master/androidapp/app/src/main/res/drawable-xxxhdpi/ic_sponsor_heydealer.png", + homepage = "https://heydealer.co.kr/", + grade = SponsorEntity.Grade.GOLD, + ) + val actual = repository.getSponsors().first() + actual shouldBe expected + } + } +} From d69f89b2d245f1c1eb563fdd47bccf7749c3df02 Mon Sep 17 00:00:00 2001 From: Youngjik Yoon Date: Sun, 16 Jul 2023 16:46:29 +0900 Subject: [PATCH 07/12] =?UTF-8?q?#50=20Fake=20=EA=B5=AC=ED=98=84=EC=B2=B4?= =?UTF-8?q?=20=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/data/{repository => fake}/FakeGithubApi.kt | 2 +- .../data/repository/DefaultContributorRepositoryTest.kt | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) rename core/data/src/test/java/com/droidknights/app2023/core/data/{repository => fake}/FakeGithubApi.kt (86%) diff --git a/core/data/src/test/java/com/droidknights/app2023/core/data/repository/FakeGithubApi.kt b/core/data/src/test/java/com/droidknights/app2023/core/data/fake/FakeGithubApi.kt similarity index 86% rename from core/data/src/test/java/com/droidknights/app2023/core/data/repository/FakeGithubApi.kt rename to core/data/src/test/java/com/droidknights/app2023/core/data/fake/FakeGithubApi.kt index f1c32fab..e341d731 100644 --- a/core/data/src/test/java/com/droidknights/app2023/core/data/repository/FakeGithubApi.kt +++ b/core/data/src/test/java/com/droidknights/app2023/core/data/fake/FakeGithubApi.kt @@ -1,4 +1,4 @@ -package com.droidknights.app2023.core.data.repository +package com.droidknights.app2023.core.data.fake import com.droidknights.app2023.core.data.api.model.ContributorResponse import com.droidknights.app2023.core.data.api.GithubApi diff --git a/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultContributorRepositoryTest.kt b/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultContributorRepositoryTest.kt index 7cf856b0..b69e1b4f 100644 --- a/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultContributorRepositoryTest.kt +++ b/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultContributorRepositoryTest.kt @@ -1,21 +1,22 @@ package com.droidknights.app2023.core.data.repository import com.droidknights.app2023.core.data.api.model.ContributorResponse +import com.droidknights.app2023.core.data.fake.FakeGithubApi import com.droidknights.app2023.core.data.model.ContributorEntity import io.kotest.core.spec.style.BehaviorSpec import io.kotest.matchers.shouldBe internal class DefaultContributorRepositoryTest : BehaviorSpec() { - + private val repository: DefaultContributorRepository = DefaultContributorRepository( githubApi = FakeGithubApi(contributors) ) - + init { Given("기여자가 존재한다") { val expected = contributors - + When("기여자를 조회한다") { val contributors: List = repository.getContributors( owner = "droidknights", @@ -30,7 +31,7 @@ internal class DefaultContributorRepositoryTest : BehaviorSpec() { } } } - + companion object { private val contributors = listOf( ContributorResponse( From 07903ece5fa252d2e9391c9275760e7a6b71e4c5 Mon Sep 17 00:00:00 2001 From: Youngjik Yoon Date: Sun, 16 Jul 2023 16:48:03 +0900 Subject: [PATCH 08/12] =?UTF-8?q?#50=20Sponsor=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EB=AA=A8=EB=8D=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app2023/core/domain/mapper/SponsorMapper.kt | 14 ++++++++++++++ .../app2023/core/domain/model/Sponsor.kt | 10 ++++++++++ 2 files changed, 24 insertions(+) create mode 100644 core/domain/src/main/java/com/droidknights/app2023/core/domain/mapper/SponsorMapper.kt create mode 100644 core/domain/src/main/java/com/droidknights/app2023/core/domain/model/Sponsor.kt diff --git a/core/domain/src/main/java/com/droidknights/app2023/core/domain/mapper/SponsorMapper.kt b/core/domain/src/main/java/com/droidknights/app2023/core/domain/mapper/SponsorMapper.kt new file mode 100644 index 00000000..0ea562fd --- /dev/null +++ b/core/domain/src/main/java/com/droidknights/app2023/core/domain/mapper/SponsorMapper.kt @@ -0,0 +1,14 @@ +package com.droidknights.app2023.core.domain.mapper + +import com.droidknights.app2023.core.data.model.SponsorEntity +import com.droidknights.app2023.core.domain.model.Sponsor + +internal fun SponsorEntity.toDomain(): Sponsor = Sponsor( + name = name, + imageUrl = imageUrl, + homepage = homepage, + grade = when (grade) { + SponsorEntity.Grade.PLATINUM -> Sponsor.Grade.PLATINUM + SponsorEntity.Grade.GOLD -> Sponsor.Grade.GOLD + } +) diff --git a/core/domain/src/main/java/com/droidknights/app2023/core/domain/model/Sponsor.kt b/core/domain/src/main/java/com/droidknights/app2023/core/domain/model/Sponsor.kt new file mode 100644 index 00000000..c3568309 --- /dev/null +++ b/core/domain/src/main/java/com/droidknights/app2023/core/domain/model/Sponsor.kt @@ -0,0 +1,10 @@ +package com.droidknights.app2023.core.domain.model + +data class Sponsor( + val name: String, + val imageUrl: String, + val homepage: String, + val grade: Grade, +) { + enum class Grade { PLATINUM, GOLD, } +} From d78f3b55a16ee4f248ffd26e9a30a3e340e10c40 Mon Sep 17 00:00:00 2001 From: Youngjik Yoon Date: Sun, 16 Jul 2023 16:48:49 +0900 Subject: [PATCH 09/12] =?UTF-8?q?#50=20GetSponsorsUseCase=20=EC=9C=A0?= =?UTF-8?q?=EC=A6=88=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/domain/usecase/GetSponsorsUseCase.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 core/domain/src/main/java/com/droidknights/app2023/core/domain/usecase/GetSponsorsUseCase.kt diff --git a/core/domain/src/main/java/com/droidknights/app2023/core/domain/usecase/GetSponsorsUseCase.kt b/core/domain/src/main/java/com/droidknights/app2023/core/domain/usecase/GetSponsorsUseCase.kt new file mode 100644 index 00000000..00f895cb --- /dev/null +++ b/core/domain/src/main/java/com/droidknights/app2023/core/domain/usecase/GetSponsorsUseCase.kt @@ -0,0 +1,15 @@ +package com.droidknights.app2023.core.domain.usecase + +import com.droidknights.app2023.core.data.repository.SponsorRepository +import com.droidknights.app2023.core.domain.mapper.toDomain +import com.droidknights.app2023.core.domain.model.Sponsor +import javax.inject.Inject + +class GetSponsorsUseCase @Inject constructor( + private val sponsorRepository: SponsorRepository, +) { + + suspend operator fun invoke(): List { + return sponsorRepository.getSponsors().map { it.toDomain() } + } +} From e89a4192e54b220d86dbb4d4de13c8766b1534e4 Mon Sep 17 00:00:00 2001 From: Youngjik Yoon Date: Sun, 16 Jul 2023 17:25:39 +0900 Subject: [PATCH 10/12] =?UTF-8?q?#50=20=EC=8B=A4=ED=96=89=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=EC=97=90=EC=84=9C=20=EB=84=A4=ED=8A=B8=EC=9B=8C?= =?UTF-8?q?=ED=81=AC=EB=A5=BC=20=EC=82=AC=EC=9A=A9=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EA=B3=A0=20assets=EC=9D=84=20=EC=A0=91=EA=B7=BC?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app2023/core/data/api/GithubRawApi.kt | 2 +- .../core/data/api/fake/AssetsGithubRawApi.kt | 18 ++++++++++++++++ .../app2023/core/data/di/DataModule.kt | 21 +++++++++++++++---- .../core/data/{ => api}/fake/FakeGithubApi.kt | 2 +- .../data/{ => api}/fake/FakeGithubRawApi.kt | 2 +- .../DefaultContributorRepositoryTest.kt | 2 +- .../DefaultSponsorRepositoryTest.kt | 2 +- 7 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 core/data/src/main/java/com/droidknights/app2023/core/data/api/fake/AssetsGithubRawApi.kt rename core/data/src/test/java/com/droidknights/app2023/core/data/{ => api}/fake/FakeGithubApi.kt (87%) rename core/data/src/test/java/com/droidknights/app2023/core/data/{ => api}/fake/FakeGithubRawApi.kt (91%) diff --git a/core/data/src/main/java/com/droidknights/app2023/core/data/api/GithubRawApi.kt b/core/data/src/main/java/com/droidknights/app2023/core/data/api/GithubRawApi.kt index c3666ab5..bd6db8ff 100644 --- a/core/data/src/main/java/com/droidknights/app2023/core/data/api/GithubRawApi.kt +++ b/core/data/src/main/java/com/droidknights/app2023/core/data/api/GithubRawApi.kt @@ -5,6 +5,6 @@ import retrofit2.http.GET internal interface GithubRawApi { - @GET("/droidknights/DroidKnights2023_App/main/data/src/main/assets/sponsors.json") + @GET("/droidknights/DroidKnights2023_App/feature/#50/data/src/main/assets/sponsors.json") suspend fun getSponsors(): List } diff --git a/core/data/src/main/java/com/droidknights/app2023/core/data/api/fake/AssetsGithubRawApi.kt b/core/data/src/main/java/com/droidknights/app2023/core/data/api/fake/AssetsGithubRawApi.kt new file mode 100644 index 00000000..aa804ecc --- /dev/null +++ b/core/data/src/main/java/com/droidknights/app2023/core/data/api/fake/AssetsGithubRawApi.kt @@ -0,0 +1,18 @@ +package com.droidknights.app2023.core.data.api.fake + +import android.content.Context +import com.droidknights.app2023.core.data.api.GithubRawApi +import com.droidknights.app2023.core.data.api.model.SponsorResponse +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.decodeFromStream + +internal class AssetsGithubRawApi( + context: Context, + private val json: Json = Json { ignoreUnknownKeys = true }, +) : GithubRawApi { + private val assets = context.assets.open("sponsors.json") + + override suspend fun getSponsors(): List { + return json.decodeFromStream(assets) + } +} diff --git a/core/data/src/main/java/com/droidknights/app2023/core/data/di/DataModule.kt b/core/data/src/main/java/com/droidknights/app2023/core/data/di/DataModule.kt index 63c0c19c..e40ddd75 100644 --- a/core/data/src/main/java/com/droidknights/app2023/core/data/di/DataModule.kt +++ b/core/data/src/main/java/com/droidknights/app2023/core/data/di/DataModule.kt @@ -1,13 +1,18 @@ package com.droidknights.app2023.core.data.di +import android.content.Context +import com.droidknights.app2023.core.data.api.fake.AssetsGithubRawApi import com.droidknights.app2023.core.data.repository.ContributorRepository import com.droidknights.app2023.core.data.repository.DefaultContributorRepository import com.droidknights.app2023.core.data.repository.DefaultSponsorRepository import com.droidknights.app2023.core.data.repository.SponsorRepository import dagger.Binds import dagger.Module +import dagger.Provides import dagger.hilt.InstallIn +import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton @InstallIn(SingletonComponent::class) @Module @@ -18,8 +23,16 @@ internal abstract class DataModule { repository: DefaultContributorRepository, ): ContributorRepository - @Binds - abstract fun bindsSponsorRepository( - repository: DefaultSponsorRepository, - ): SponsorRepository + @InstallIn(SingletonComponent::class) + @Module + internal object FakeModule { + + @Provides + @Singleton + fun provideSponsorRepository( + @ApplicationContext context: Context, + ): SponsorRepository { + return DefaultSponsorRepository(AssetsGithubRawApi(context)) + } + } } diff --git a/core/data/src/test/java/com/droidknights/app2023/core/data/fake/FakeGithubApi.kt b/core/data/src/test/java/com/droidknights/app2023/core/data/api/fake/FakeGithubApi.kt similarity index 87% rename from core/data/src/test/java/com/droidknights/app2023/core/data/fake/FakeGithubApi.kt rename to core/data/src/test/java/com/droidknights/app2023/core/data/api/fake/FakeGithubApi.kt index e341d731..83473c33 100644 --- a/core/data/src/test/java/com/droidknights/app2023/core/data/fake/FakeGithubApi.kt +++ b/core/data/src/test/java/com/droidknights/app2023/core/data/api/fake/FakeGithubApi.kt @@ -1,4 +1,4 @@ -package com.droidknights.app2023.core.data.fake +package com.droidknights.app2023.core.data.api.fake import com.droidknights.app2023.core.data.api.model.ContributorResponse import com.droidknights.app2023.core.data.api.GithubApi diff --git a/core/data/src/test/java/com/droidknights/app2023/core/data/fake/FakeGithubRawApi.kt b/core/data/src/test/java/com/droidknights/app2023/core/data/api/fake/FakeGithubRawApi.kt similarity index 91% rename from core/data/src/test/java/com/droidknights/app2023/core/data/fake/FakeGithubRawApi.kt rename to core/data/src/test/java/com/droidknights/app2023/core/data/api/fake/FakeGithubRawApi.kt index 891101ad..3bae236c 100644 --- a/core/data/src/test/java/com/droidknights/app2023/core/data/fake/FakeGithubRawApi.kt +++ b/core/data/src/test/java/com/droidknights/app2023/core/data/api/fake/FakeGithubRawApi.kt @@ -1,4 +1,4 @@ -package com.droidknights.app2023.core.data.fake +package com.droidknights.app2023.core.data.api.fake import com.droidknights.app2023.core.data.api.GithubRawApi import com.droidknights.app2023.core.data.api.model.SponsorResponse diff --git a/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultContributorRepositoryTest.kt b/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultContributorRepositoryTest.kt index b69e1b4f..9dba2b21 100644 --- a/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultContributorRepositoryTest.kt +++ b/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultContributorRepositoryTest.kt @@ -1,7 +1,7 @@ package com.droidknights.app2023.core.data.repository +import com.droidknights.app2023.core.data.api.fake.FakeGithubApi import com.droidknights.app2023.core.data.api.model.ContributorResponse -import com.droidknights.app2023.core.data.fake.FakeGithubApi import com.droidknights.app2023.core.data.model.ContributorEntity import io.kotest.core.spec.style.BehaviorSpec import io.kotest.matchers.shouldBe diff --git a/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultSponsorRepositoryTest.kt b/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultSponsorRepositoryTest.kt index e72ade7d..8098301d 100644 --- a/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultSponsorRepositoryTest.kt +++ b/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultSponsorRepositoryTest.kt @@ -1,6 +1,6 @@ package com.droidknights.app2023.core.data.repository -import com.droidknights.app2023.core.data.fake.FakeGithubRawApi +import com.droidknights.app2023.core.data.api.fake.FakeGithubRawApi import com.droidknights.app2023.core.data.model.SponsorEntity import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe From 7e0bc7c76795156091b9dd9e62459b0a898d5a80 Mon Sep 17 00:00:00 2001 From: Youngjik Yoon Date: Sun, 16 Jul 2023 17:28:36 +0900 Subject: [PATCH 11/12] =?UTF-8?q?#50=20=EC=9E=98=EB=AA=BB=20=EB=93=A4?= =?UTF-8?q?=EC=96=B4=EA=B0=84=20=EB=93=A4=EC=97=AC=EC=93=B0=EA=B8=B0=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/droidknights/app2023/core/data/di/ApiModule.kt | 6 +++--- .../com/droidknights/app2023/core/data/di/DataModule.kt | 2 +- .../data/repository/DefaultContributorRepositoryTest.kt | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/data/src/main/java/com/droidknights/app2023/core/data/di/ApiModule.kt b/core/data/src/main/java/com/droidknights/app2023/core/data/di/ApiModule.kt index 0818a89c..7850239f 100644 --- a/core/data/src/main/java/com/droidknights/app2023/core/data/di/ApiModule.kt +++ b/core/data/src/main/java/com/droidknights/app2023/core/data/di/ApiModule.kt @@ -17,11 +17,11 @@ import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) internal object ApiModule { - + @Provides @Singleton fun provideOkhttpClient(): OkHttpClient = OkHttpClient.Builder().build() - + @Provides @Singleton fun provideConverterFactory( @@ -29,7 +29,7 @@ internal object ApiModule { ): Converter.Factory { return json.asConverterFactory("application/json".toMediaType()) } - + @Provides @Singleton fun provideGithubApi( diff --git a/core/data/src/main/java/com/droidknights/app2023/core/data/di/DataModule.kt b/core/data/src/main/java/com/droidknights/app2023/core/data/di/DataModule.kt index e40ddd75..5ef1d0c3 100644 --- a/core/data/src/main/java/com/droidknights/app2023/core/data/di/DataModule.kt +++ b/core/data/src/main/java/com/droidknights/app2023/core/data/di/DataModule.kt @@ -17,7 +17,7 @@ import javax.inject.Singleton @InstallIn(SingletonComponent::class) @Module internal abstract class DataModule { - + @Binds abstract fun bindsContributorRepository( repository: DefaultContributorRepository, diff --git a/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultContributorRepositoryTest.kt b/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultContributorRepositoryTest.kt index 9dba2b21..7a5a944f 100644 --- a/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultContributorRepositoryTest.kt +++ b/core/data/src/test/java/com/droidknights/app2023/core/data/repository/DefaultContributorRepositoryTest.kt @@ -8,15 +8,15 @@ import io.kotest.matchers.shouldBe internal class DefaultContributorRepositoryTest : BehaviorSpec() { - + private val repository: DefaultContributorRepository = DefaultContributorRepository( githubApi = FakeGithubApi(contributors) ) - + init { Given("기여자가 존재한다") { val expected = contributors - + When("기여자를 조회한다") { val contributors: List = repository.getContributors( owner = "droidknights", @@ -31,7 +31,7 @@ internal class DefaultContributorRepositoryTest : BehaviorSpec() { } } } - + companion object { private val contributors = listOf( ContributorResponse( From 98780d7796938b944def5863e09f14f04d5bb7fc Mon Sep 17 00:00:00 2001 From: Youngjik Yoon Date: Sun, 16 Jul 2023 17:40:00 +0900 Subject: [PATCH 12/12] =?UTF-8?q?#50=20=EC=9E=98=EB=AA=BB=20=EB=93=A4?= =?UTF-8?q?=EC=96=B4=EA=B0=84=20=EB=B8=8C=EB=9E=9C=EC=B9=98=20=EA=B2=BD?= =?UTF-8?q?=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/droidknights/app2023/core/data/api/GithubRawApi.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/data/src/main/java/com/droidknights/app2023/core/data/api/GithubRawApi.kt b/core/data/src/main/java/com/droidknights/app2023/core/data/api/GithubRawApi.kt index bd6db8ff..c3666ab5 100644 --- a/core/data/src/main/java/com/droidknights/app2023/core/data/api/GithubRawApi.kt +++ b/core/data/src/main/java/com/droidknights/app2023/core/data/api/GithubRawApi.kt @@ -5,6 +5,6 @@ import retrofit2.http.GET internal interface GithubRawApi { - @GET("/droidknights/DroidKnights2023_App/feature/#50/data/src/main/assets/sponsors.json") + @GET("/droidknights/DroidKnights2023_App/main/data/src/main/assets/sponsors.json") suspend fun getSponsors(): List }