Skip to content
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
@@ -1,7 +1,5 @@
package com.peto.droidmorning

import com.peto.droidmorning.extentions.composeMultiplatformDependencies
import com.peto.droidmorning.extentions.koinDependencies
import com.peto.droidmorning.extentions.library
import com.peto.droidmorning.extentions.libs
import com.peto.droidmorning.extentions.plugin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.peto.droidmorning

import com.peto.droidmorning.extentions.libs
import com.peto.droidmorning.extentions.plugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply

class KotlinMultiplatformConventionPlugin : Plugin<Project> {
override fun apply(target: Project) = with(target) {
with(pluginManager) {
apply("org.jetbrains.kotlin.multiplatform")
apply(libs.plugin("kotlin-multiplatform").pluginId)
}


apply<AndroidLibraryConventionPlugin>()
apply<KotlinMultiPlatformPlugin>()
apply<KotlinMultiPlatformAndroidPlugin>()
apply<KotlinMultiPlatformiOSPlugin>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ internal fun Project.koinDependencies() {
sourceSets.apply {
commonMain {
dependencies {
implementation(libs.bundle("koin"))
implementation(libs.library("koin-core"))
implementation(libs.library("koin-compose"))
implementation(libs.library("koin-compose-viewmodel"))
}
}
commonTest {
Expand Down
2 changes: 2 additions & 0 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ kotlin {
implementation(project(":domain"))
implementation(project(":data"))
implementation(project(":designsystem"))
implementation(project(":core:network"))
implementation(project(":core:datastore"))

implementation(libs.bundles.compose.multiplatform)
implementation(libs.androidx.navigation.compose)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.peto.droidmorning

import com.peto.droidmorning.core.datastore.di.dataStoreModule
import com.peto.droidmorning.core.network.di.networkModule
import com.peto.droidmorning.data.di.dataModule
import com.peto.droidmorning.di.navigationModule
import com.peto.droidmorning.di.platformModule
Expand All @@ -19,6 +21,8 @@ fun initKoin(
extraModules +
listOf(
platformModule,
networkModule,
dataStoreModule,
dataModule,
viewModelModule,
navigationModule,
Expand Down
2 changes: 2 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
plugins {
}
20 changes: 20 additions & 0 deletions core/datastore/build.gradle.kts
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"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.peto.droidmorning.data.local
package com.peto.droidmorning.core.datastore

import android.content.Context
import androidx.datastore.core.DataStore
Expand Down
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")
}
}
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()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.peto.droidmorning.data.local
package com.peto.droidmorning.core.datastore

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
Expand Down
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()) }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.peto.droidmorning.data.local
package com.peto.droidmorning.core.datastore

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
Expand Down
59 changes: 59 additions & 0 deletions core/network/build.gradle.kts
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"
}
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?
}
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)
}
}
}
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(),
)
}
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,
)
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,
)
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
}
Loading