Skip to content
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

✨ DataStore モジュールを追加 #110

Merged
merged 5 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import club.nito.app.shared.di.featureModules
import club.nito.app.shared.di.nitoDateFormatterModule
import club.nito.app.shared.di.userMessageStateHolderModule
import club.nito.core.data.di.dataModule
import club.nito.core.datastore.di.dataStoreModule
import club.nito.core.domain.di.useCaseModule
import club.nito.core.network.di.remoteDataSourceModule
import club.nito.core.network.di.supabaseClientModule
Expand All @@ -30,6 +31,7 @@ class KmpEntryPoint {
supabaseClientModule,
remoteDataSourceModule,
// fakeRemoteDataSourceModule,
dataStoreModule,
dataModule,
useCaseModule,

Expand Down
1 change: 1 addition & 0 deletions app/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ kotlin {
dependencies {
implementation(projects.core.common)
implementation(projects.core.model)
implementation(projects.core.datastore)
implementation(projects.core.data)
implementation(projects.core.network)
implementation(projects.core.domain)
Comment on lines 15 to 21
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 NOTE
Codebase verification is a beta feature.

projects.core.datastore モジュールが commonMain 依存関係に追加されましたが、core.datastore モジュールの build.gradle.kts ファイルに関する情報が見つかりませんでした。バージョン競合や追加の設定が必要かどうかを確認するためには、このファイルの内容を確認する必要があります。プロジェクトの設定ファイルを全体的に見直して、この変更が他のモジュールとの競合を引き起こさないことを確認してください。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import club.nito.app.shared.di.featureModules
import club.nito.app.shared.di.nitoDateFormatterModule
import club.nito.app.shared.di.userMessageStateHolderModule
import club.nito.core.data.di.dataModule
import club.nito.core.datastore.di.dataStoreModule
import club.nito.core.designsystem.theme.NitoTheme
import club.nito.core.domain.di.useCaseModule
import club.nito.core.network.di.remoteDataSourceModule
Expand Down Expand Up @@ -41,6 +42,7 @@ fun NitoApp(
supabaseClientModule,
remoteDataSourceModule,
// fakeRemoteDataSourceModule,
dataStoreModule,
dataModule,
useCaseModule,

Expand Down
1 change: 1 addition & 0 deletions core/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ kotlin {
dependencies {
implementation(libs.kotlinxCoroutinesCore)
implementation(libs.kotlinxDatetime)
implementation(libs.kotlinSerializationJson)
Comment on lines 16 to +19
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 NOTE
Codebase verification is a beta feature.

kotlinSerializationJsonライブラリがプロジェクトの依存関係に追加されたことを確認しました。既存のコードでJSONシリアライズに関連する複数の箇所が使用されていることが確認されています。この新しい依存関係が既存のシリアライズ設定や実装に影響を与えないか、詳細なレビューが必要です。

}
}
iosMain {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package club.nito.core.common

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonNamingStrategy

public val nitoJsonSettings: Json = Json {
encodeDefaults = true
isLenient = true
allowSpecialFloatingPointValues = true
allowStructuredMapKeys = true
prettyPrint = false
useArrayPolymorphism = false
ignoreUnknownKeys = true
coerceInputValues = true
useAlternativeNames = false

@OptIn(ExperimentalSerializationApi::class)
namingStrategy = JsonNamingStrategy.SnakeCase
}
Comment on lines +3 to +20
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitoJsonSettingsの設定にExperimentalSerializationApiが使用されています。将来的にAPIが変更された場合に備えて、この実験的APIの使用に関するリスクをプロジェクトチームと共有し、必要に応じてフォールバックメカニズムを検討することをお勧めします。

1 change: 1 addition & 0 deletions core/data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ kotlin {
implementation(projects.core.common)
implementation(projects.core.model)
implementation(projects.core.database)
implementation(projects.core.datastore)
implementation(projects.core.network)

implementation(libs.kotlinxCoroutinesCore)
Expand Down
31 changes: 31 additions & 0 deletions core/datastore/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
plugins {
id("nito.primitive.kmp")
id("nito.primitive.kmp.android")
id("nito.primitive.kmp.ios")
id("nito.primitive.kmp.js")
id("nito.primitive.detekt")
}

android.namespace = "club.nito.core.datastore"

kotlin {
explicitApi()

sourceSets {
commonMain {
dependencies {
implementation(projects.core.common)
implementation(projects.core.model)

implementation(libs.kotlinxCoroutinesCore)
implementation(libs.kotlinSerializationJson)

implementation(libs.koin)
implementation(libs.kermit)

implementation(libs.multiplatformSettingsNoArg)
implementation(libs.multiplatformSettingsCoroutines)
}
}
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package club.nito.core.datastore

public sealed interface DataStore
Comment on lines +1 to +3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

パッケージレベルのドキュメンテーションやコメントがないため、このインターフェースの目的や使い方についての説明があると、保守性や明確性が向上します。

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package club.nito.core.datastore

import com.russhwolf.settings.ExperimentalSettingsApi
import com.russhwolf.settings.Settings
import com.russhwolf.settings.coroutines.SuspendSettings
import com.russhwolf.settings.coroutines.toSuspendSettings
import kotlinx.serialization.json.Json

public class SettingsDataStore(
private val settings: Settings,
@OptIn(ExperimentalSettingsApi::class)
private val suspendSettings: SuspendSettings = settings.toSuspendSettings(),
Comment on lines +11 to +12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

実験的なAPI ExperimentalSettingsApi を使用しています。このAPIの使用にはリスクが伴う可能性があるため、その使用理由をコメントで説明することをお勧めします。

+    // Experimental API is used here. Ensure that the risks are understood and acceptable.
    @OptIn(ExperimentalSettingsApi::class)

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
@OptIn(ExperimentalSettingsApi::class)
private val suspendSettings: SuspendSettings = settings.toSuspendSettings(),
// Experimental API is used here. Ensure that the risks are understood and acceptable.
@OptIn(ExperimentalSettingsApi::class)
private val suspendSettings: SuspendSettings = settings.toSuspendSettings(),

private val json: Json,
) : DataStore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package club.nito.core.datastore

import com.russhwolf.settings.Settings

internal fun createSettings() = try {
Settings()
} catch (e: Exception) {
error("Failed to create default settings")
}
Comment on lines +5 to +9
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

エラーメッセージに例外の詳細を含めることで、デバッグ時に役立つ情報を提供することができます。例外のスタックトレースをログに記録することも検討してください。

-    error("Failed to create default settings")
+    error("Failed to create default settings", e)

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
internal fun createSettings() = try {
Settings()
} catch (e: Exception) {
error("Failed to create default settings")
}
internal fun createSettings() = try {
Settings()
} catch (e: Exception) {
error("Failed to create default settings", e)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package club.nito.core.datastore.di

import club.nito.core.common.nitoJsonSettings
import club.nito.core.datastore.DataStore
import club.nito.core.datastore.SettingsDataStore
import club.nito.core.datastore.createSettings
import com.russhwolf.settings.ExperimentalSettingsApi
import org.koin.core.module.Module
import org.koin.dsl.module

public val dataStoreModule: Module = module {
single<DataStore> {
@OptIn(ExperimentalSettingsApi::class)
SettingsDataStore(
settings = createSettings(),
json = nitoJsonSettings
)
}
}
Empty file.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import io.github.jan.supabase.gotrue.Auth
import io.github.jan.supabase.postgrest.Postgrest
import io.github.jan.supabase.realtime.Realtime
import io.github.jan.supabase.serializer.KotlinXSerializer
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonNamingStrategy
import kotlinx.serialization.modules.SerializersModule
import kotlinx.serialization.modules.contextual

internal fun createNitoSupabaseClient(
json: Json,
Expand All @@ -24,22 +20,3 @@ internal fun createNitoSupabaseClient(

defaultSerializer = KotlinXSerializer(json)
}
Comment on lines 20 to 22
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [11-22]

セキュリティ上の懸念があります。SupabaseのURLとキーがハードコードされており、これが機密情報である場合、コード内に直接含めるべきではありません。これらの値は環境変数や設定ファイルから読み込むように変更することをお勧めします。

-    supabaseUrl = "https://gtfjukrauyhrbglrzlva.supabase.co",
-    supabaseKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imd0Zmp1a3JhdXlocmJnbHJ6bHZhIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTkwMDQ3NTgsImV4cCI6MjAxNDU4MDc1OH0.zRjlzXVyz4vBM8Tb8GcpyPyTkCmOwdV-Xs18Agw2w-E",
+    supabaseUrl = System.getenv("SUPABASE_URL"),
+    supabaseKey = System.getenv("SUPABASE_KEY"),


internal fun createNitoKtorJsonSettings(): Json = Json {
encodeDefaults = true
isLenient = true
allowSpecialFloatingPointValues = true
allowStructuredMapKeys = true
prettyPrint = false
useArrayPolymorphism = false
ignoreUnknownKeys = true
coerceInputValues = true
useAlternativeNames = false

@OptIn(ExperimentalSerializationApi::class)
namingStrategy = JsonNamingStrategy.SnakeCase

serializersModule = SerializersModule {
contextual(InstantSerializer)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package club.nito.core.network.di

import club.nito.core.network.createNitoKtorJsonSettings
import club.nito.core.common.nitoJsonSettings
import club.nito.core.network.createNitoSupabaseClient
import io.github.jan.supabase.SupabaseClient
import io.github.jan.supabase.gotrue.Auth
Expand All @@ -16,7 +16,7 @@ public val supabaseClientModule: Module = module {
)
}
single<Json> {
createNitoKtorJsonSettings()
nitoJsonSettings
}
single<Auth> {
get<SupabaseClient>().auth
Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ktor = "2.3.6"
ksp = "1.9.21-1.0.15"
firebaseBom = "32.2.3"
multiplatformFirebase = "1.10.4"
multiplatformSettings = "1.1.1"
kermit = "2.0.2"
okHttp = "4.12.0"
ossLicensesPlugin = "0.10.6"
Expand Down Expand Up @@ -68,6 +69,8 @@ androidxWindow = { module = "androidx.window:window", version = "1.1.0" }
androidxSplashScreen = { module = "androidx.core:core-splashscreen", version.ref = "androidxSplashScreen" }
javaPoet = { module = "com.squareup:javapoet", version = "1.13.0" }

multiplatformSettingsNoArg = { module = "com.russhwolf:multiplatform-settings-no-arg", version.ref = "multiplatformSettings" }
multiplatformSettingsCoroutines = { module = "com.russhwolf:multiplatform-settings-coroutines", version.ref = "multiplatformSettings" }
kotlinSerializationJson = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerialization" }

ktorClientCore = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ include(
":app:backend",
":core:common",
":core:database",
":core:datastore",
":core:network",
":core:data",
":core:model",
Expand Down