-
Notifications
You must be signed in to change notification settings - Fork 0
core 모듈 분리 및 data 리팩터링 #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 0 additions & 2 deletions
2
build-logic/convention/src/main/kotlin/com/peto/droidmorning/DroidMorningFeaturePlugin.kt
This file contains hidden or 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
7 changes: 5 additions & 2 deletions
7
...c/convention/src/main/kotlin/com/peto/droidmorning/KotlinMultiplatformConventionPlugin.kt
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,2 @@ | ||
| plugins { | ||
| } |
This file contains hidden or 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 @@ | ||
| plugins { | ||
| alias(libs.plugins.droidmorning.kotlin.multiplatform) | ||
| alias(libs.plugins.droidmorning.android.library) | ||
| alias(libs.plugins.droidmorning.koin) | ||
| } | ||
|
|
||
| kotlin { | ||
| sourceSets { | ||
| commonMain.dependencies { | ||
| implementation(libs.bundles.datastore) | ||
| } | ||
| iosMain.dependencies { | ||
| implementation(libs.okio) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| android { | ||
| namespace = "com.peto.droidmorning.core.datastore" | ||
| } |
2 changes: 1 addition & 1 deletion
2
...ng/data/local/DataStoreFactory.android.kt → ...ore/datastore/DataStoreFactory.android.kt
This file contains hidden or 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
33 changes: 33 additions & 0 deletions
33
...store/src/commonMain/kotlin/com/peto/droidmorning/core/datastore/DefaultTokenDataStore.kt
This file contains hidden or 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.peto.droidmorning.core.datastore | ||
|
|
||
| import androidx.datastore.core.DataStore | ||
| import androidx.datastore.preferences.core.Preferences | ||
| import androidx.datastore.preferences.core.edit | ||
| import androidx.datastore.preferences.core.stringPreferencesKey | ||
| import kotlinx.coroutines.flow.first | ||
|
|
||
| class DefaultTokenDataStore( | ||
| private val dataStore: DataStore<Preferences>, | ||
| ) : TokenDataStore { | ||
| override suspend fun userId(): String? = preferences()[KEY_USER_ID] | ||
|
|
||
| override suspend fun hasUserId(): Boolean = preferences()[KEY_USER_ID] != null | ||
|
|
||
| override suspend fun save(userId: String) { | ||
| dataStore.edit { preferences -> | ||
| preferences[KEY_USER_ID] = userId | ||
| } | ||
| } | ||
|
|
||
| override suspend fun clear() { | ||
| dataStore.edit { preferences -> | ||
| preferences.remove(KEY_USER_ID) | ||
| } | ||
| } | ||
|
|
||
| private suspend fun preferences(): Preferences = dataStore.data.first() | ||
|
|
||
| private companion object { | ||
| private val KEY_USER_ID = stringPreferencesKey("user_id") | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
core/datastore/src/commonMain/kotlin/com/peto/droidmorning/core/datastore/TokenDataStore.kt
This file contains hidden or 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.peto.droidmorning.core.datastore | ||
|
|
||
| interface TokenDataStore { | ||
| suspend fun userId(): String? | ||
|
|
||
| suspend fun hasUserId(): Boolean | ||
|
|
||
| suspend fun save(userId: String) | ||
|
|
||
| suspend fun clear() | ||
| } |
2 changes: 1 addition & 1 deletion
2
...rning/data/local/TokenDataStoreFactory.kt → ...g/core/datastore/TokenDataStoreFactory.kt
This file contains hidden or 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
12 changes: 12 additions & 0 deletions
12
...atastore/src/commonMain/kotlin/com/peto/droidmorning/core/datastore/di/DataStoreModule.kt
This file contains hidden or 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.peto.droidmorning.core.datastore.di | ||
|
|
||
| import com.peto.droidmorning.core.datastore.DefaultTokenDataStore | ||
| import com.peto.droidmorning.core.datastore.TokenDataStore | ||
| import com.peto.droidmorning.core.datastore.createTokenDataStore | ||
| import org.koin.dsl.module | ||
|
|
||
| val dataStoreModule = | ||
| module { | ||
| single { createTokenDataStore() } | ||
| single<TokenDataStore> { DefaultTokenDataStore(get()) } | ||
| } |
2 changes: 1 addition & 1 deletion
2
...orning/data/local/DataStoreFactory.ios.kt → ...ng/core/datastore/DataStoreFactory.ios.kt
This file contains hidden or 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 hidden or 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,59 @@ | ||
| import com.codingfeline.buildkonfig.compiler.FieldSpec.Type | ||
| import java.util.Properties | ||
|
|
||
| plugins { | ||
| alias(libs.plugins.droidmorning.kotlin.multiplatform) | ||
| alias(libs.plugins.droidmorning.android.library) | ||
| alias(libs.plugins.droidmorning.koin) | ||
| alias(libs.plugins.buildkonfig) | ||
| } | ||
|
|
||
| kotlin { | ||
| sourceSets { | ||
| androidMain.dependencies { | ||
| implementation(libs.ktor.client.okhttp) | ||
| } | ||
| commonMain.dependencies { | ||
| implementation(libs.bundles.ktor.common) | ||
|
|
||
| implementation(project.dependencies.platform(libs.supabase.bom)) | ||
| implementation(libs.bundles.supabase) | ||
| } | ||
| iosMain.dependencies { | ||
| implementation(libs.ktor.client.darwin) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| buildkonfig { | ||
| packageName = "com.peto.droidmorning" | ||
| exposeObjectWithName = "BuildKonfig" | ||
|
|
||
| val props = | ||
| Properties().apply { | ||
| val file = rootProject.file("local.properties") | ||
| if (file.exists()) file.inputStream().use { load(it) } | ||
| } | ||
|
|
||
| defaultConfigs { | ||
| buildConfigField( | ||
| Type.STRING, | ||
| "GOOGLE_CLIENT_ID", | ||
| props.getProperty("GOOGLE_CLIENT_ID"), | ||
| ) | ||
| buildConfigField( | ||
| Type.STRING, | ||
| "SUPABASE_URL", | ||
| props.getProperty("SUPABASE_URL"), | ||
| ) | ||
| buildConfigField( | ||
| Type.STRING, | ||
| "SUPABASE_KEY", | ||
| props.getProperty("SUPABASE_KEY"), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| android { | ||
| namespace = "com.peto.droidmorning.core.network" | ||
| } | ||
9 changes: 9 additions & 0 deletions
9
core/network/src/commonMain/kotlin/com/peto/droidmorning/core/network/AuthClient.kt
This file contains hidden or 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,9 @@ | ||
| package com.peto.droidmorning.core.network | ||
|
|
||
| interface AuthClient { | ||
| suspend fun signInWithGoogleIdToken(idToken: String): String? | ||
|
|
||
| suspend fun signOut() | ||
|
|
||
| fun currentUserId(): String? | ||
| } |
18 changes: 18 additions & 0 deletions
18
core/network/src/commonMain/kotlin/com/peto/droidmorning/core/network/HttpClient.kt
This file contains hidden or 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.peto.droidmorning.core.network | ||
|
|
||
| import com.peto.droidmorning.BuildKonfig | ||
| import io.github.jan.supabase.auth.Auth | ||
| import io.github.jan.supabase.createSupabaseClient | ||
| import io.github.jan.supabase.postgrest.Postgrest | ||
|
|
||
| object HttpClient { | ||
| val client by lazy { | ||
| createSupabaseClient( | ||
| supabaseUrl = BuildKonfig.SUPABASE_URL, | ||
| supabaseKey = BuildKonfig.SUPABASE_KEY, | ||
| ) { | ||
| install(Auth) | ||
| install(Postgrest) | ||
| } | ||
chanho0908 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
core/network/src/commonMain/kotlin/com/peto/droidmorning/core/network/PostgrestClient.kt
This file contains hidden or 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.peto.droidmorning.core.network | ||
|
|
||
| import kotlinx.serialization.json.JsonElement | ||
| import kotlinx.serialization.json.JsonObject | ||
|
|
||
| interface PostgrestClient { | ||
| suspend fun select( | ||
| table: String, | ||
| filters: List<PostgrestFilter> = emptyList(), | ||
| order: PostgrestOrder? = null, | ||
| ): String | ||
|
|
||
| suspend fun rpc( | ||
| function: String, | ||
| parameters: JsonObject? = null, | ||
| ): String | ||
|
|
||
| suspend fun insert( | ||
| table: String, | ||
| body: JsonObject, | ||
| ) | ||
|
|
||
| suspend fun update( | ||
| table: String, | ||
| body: JsonElement, | ||
| filters: List<PostgrestFilter> = emptyList(), | ||
| ) | ||
|
|
||
| suspend fun delete( | ||
| table: String, | ||
| filters: List<PostgrestFilter> = emptyList(), | ||
| ) | ||
| } |
6 changes: 6 additions & 0 deletions
6
core/network/src/commonMain/kotlin/com/peto/droidmorning/core/network/PostgrestFilter.kt
This file contains hidden or 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.peto.droidmorning.core.network | ||
|
|
||
| data class PostgrestFilter( | ||
| val column: String, | ||
| val value: Any, | ||
| ) |
6 changes: 6 additions & 0 deletions
6
core/network/src/commonMain/kotlin/com/peto/droidmorning/core/network/PostgrestOrder.kt
This file contains hidden or 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.peto.droidmorning.core.network | ||
|
|
||
| data class PostgrestOrder( | ||
| val column: String, | ||
| val descending: Boolean = false, | ||
| ) |
23 changes: 23 additions & 0 deletions
23
core/network/src/commonMain/kotlin/com/peto/droidmorning/core/network/SupabaseAuthClient.kt
This file contains hidden or 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,23 @@ | ||
| package com.peto.droidmorning.core.network | ||
|
|
||
| import io.github.jan.supabase.auth.Auth | ||
| import io.github.jan.supabase.auth.providers.Google | ||
| import io.github.jan.supabase.auth.providers.builtin.IDToken | ||
|
|
||
| class SupabaseAuthClient( | ||
| private val auth: Auth, | ||
| ) : AuthClient { | ||
| override suspend fun signInWithGoogleIdToken(idToken: String): String? { | ||
| auth.signInWith(IDToken) { | ||
| this.idToken = idToken | ||
| provider = Google | ||
| } | ||
| return currentUserId() | ||
| } | ||
|
|
||
| override suspend fun signOut() { | ||
| auth.signOut() | ||
| } | ||
|
|
||
| override fun currentUserId(): String? = auth.currentSessionOrNull()?.user?.id | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.