diff --git a/core/network/src/commonMain/kotlin/club/nito/core/network/SupabaseClient.kt b/core/network/src/commonMain/kotlin/club/nito/core/network/SupabaseClient.kt index 069454a2..27d523de 100644 --- a/core/network/src/commonMain/kotlin/club/nito/core/network/SupabaseClient.kt +++ b/core/network/src/commonMain/kotlin/club/nito/core/network/SupabaseClient.kt @@ -2,7 +2,7 @@ package club.nito.core.network import io.github.jan.supabase.SupabaseClient import io.github.jan.supabase.createSupabaseClient -import io.github.jan.supabase.gotrue.GoTrue +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 @@ -19,7 +19,7 @@ internal fun createNitoSupabaseClient( supabaseKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imd0Zmp1a3JhdXlocmJnbHJ6bHZhIiwicm9sZSI6ImFub24iLCJpYXQiOjE2OTkwMDQ3NTgsImV4cCI6MjAxNDU4MDc1OH0.zRjlzXVyz4vBM8Tb8GcpyPyTkCmOwdV-Xs18Agw2w-E", ) { install(Postgrest) - install(GoTrue) + install(Auth) install(Realtime) defaultSerializer = KotlinXSerializer(json) diff --git a/core/network/src/commonMain/kotlin/club/nito/core/network/auth/SupabaseAuthRemoteDataSource.kt b/core/network/src/commonMain/kotlin/club/nito/core/network/auth/SupabaseAuthRemoteDataSource.kt index 7e104c46..f0a7eb83 100644 --- a/core/network/src/commonMain/kotlin/club/nito/core/network/auth/SupabaseAuthRemoteDataSource.kt +++ b/core/network/src/commonMain/kotlin/club/nito/core/network/auth/SupabaseAuthRemoteDataSource.kt @@ -4,14 +4,14 @@ import club.nito.core.model.AuthStatus import club.nito.core.model.FetchSingleResult import club.nito.core.model.UserInfo import club.nito.core.model.UserSession -import io.github.jan.supabase.gotrue.GoTrue +import io.github.jan.supabase.gotrue.Auth import io.github.jan.supabase.gotrue.SessionStatus import io.github.jan.supabase.gotrue.providers.builtin.Email import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map public class SupabaseAuthRemoteDataSource( - private val goTrue: GoTrue, + private val goTrue: Auth, ) : AuthRemoteDataSource { override val authStatus: Flow> = goTrue.sessionStatus.map { when (it) { @@ -37,12 +37,12 @@ public class SupabaseAuthRemoteDataSource( } } - override suspend fun login(email: String, password: String): Unit = goTrue.loginWith(Email) { + override suspend fun login(email: String, password: String): Unit = goTrue.signInWith(Email) { this.email = email this.password = password } - override suspend fun logout(): Unit = goTrue.logout() + override suspend fun logout(): Unit = goTrue.signOut() override suspend fun modifyAuthUser(email: String?, password: String?): UserInfo = goTrue.modifyUser { this.email = email diff --git a/core/network/src/commonMain/kotlin/club/nito/core/network/di/SupabaseClientModule.kt b/core/network/src/commonMain/kotlin/club/nito/core/network/di/SupabaseClientModule.kt index 95378530..3ae8925c 100644 --- a/core/network/src/commonMain/kotlin/club/nito/core/network/di/SupabaseClientModule.kt +++ b/core/network/src/commonMain/kotlin/club/nito/core/network/di/SupabaseClientModule.kt @@ -3,8 +3,8 @@ package club.nito.core.network.di import club.nito.core.network.createNitoKtorJsonSettings import club.nito.core.network.createNitoSupabaseClient import io.github.jan.supabase.SupabaseClient -import io.github.jan.supabase.gotrue.GoTrue -import io.github.jan.supabase.gotrue.gotrue +import io.github.jan.supabase.gotrue.Auth +import io.github.jan.supabase.gotrue.auth import kotlinx.serialization.json.Json import org.koin.core.module.Module import org.koin.dsl.module @@ -18,7 +18,7 @@ public val supabaseClientModule: Module = module { single { createNitoKtorJsonSettings() } - single { - get().gotrue + single { + get().auth } } diff --git a/core/network/src/commonMain/kotlin/club/nito/core/network/participation/SupabaseParticipantRemoteDataSource.kt b/core/network/src/commonMain/kotlin/club/nito/core/network/participation/SupabaseParticipantRemoteDataSource.kt index 36df2167..1bc690d8 100644 --- a/core/network/src/commonMain/kotlin/club/nito/core/network/participation/SupabaseParticipantRemoteDataSource.kt +++ b/core/network/src/commonMain/kotlin/club/nito/core/network/participation/SupabaseParticipantRemoteDataSource.kt @@ -6,7 +6,7 @@ import club.nito.core.network.participation.model.NetworkParticipant import club.nito.core.network.participation.model.toNetworkModel import io.github.jan.supabase.SupabaseClient import io.github.jan.supabase.postgrest.postgrest -import io.github.jan.supabase.postgrest.query.Returning +import io.github.jan.supabase.postgrest.query.Count public class SupabaseParticipantRemoteDataSource( private val client: SupabaseClient, @@ -14,36 +14,35 @@ public class SupabaseParticipantRemoteDataSource( private val postgrest = client.postgrest["participants"] override suspend fun getParticipants(scheduleId: String): List = postgrest - .select( - filter = { + .select { + filter { and { eq("schedule_id", scheduleId) exact("deleted_at", null) } - }, - ) + } + } .decodeList() .map(NetworkParticipant::toParticipant) override suspend fun getParticipants(scheduleIds: List): List = postgrest - .select( - filter = { + .select { + filter { and { isIn("schedule_id", scheduleIds) exact("deleted_at", null) } - }, - ) + } + } .decodeList() .map(NetworkParticipant::toParticipant) override suspend fun participate(declaration: ParticipantDeclaration): Long { val result = postgrest.insert( value = declaration.toNetworkModel(), - upsert = true, - returning = Returning.MINIMAL, - filter = {}, - ) - return result.count() ?: 0 + ) { + count(Count.EXACT) + } + return result.countOrNull() ?: 0 } } diff --git a/core/network/src/commonMain/kotlin/club/nito/core/network/schedule/SupabaseScheduleRemoteDataSource.kt b/core/network/src/commonMain/kotlin/club/nito/core/network/schedule/SupabaseScheduleRemoteDataSource.kt index 420a4314..bc48ee54 100644 --- a/core/network/src/commonMain/kotlin/club/nito/core/network/schedule/SupabaseScheduleRemoteDataSource.kt +++ b/core/network/src/commonMain/kotlin/club/nito/core/network/schedule/SupabaseScheduleRemoteDataSource.kt @@ -25,24 +25,26 @@ public class SupabaseScheduleRemoteDataSource( order: Order, after: Instant?, ): List = postgrest - .select( - filter = { + .select { + filter { exact(Column.DELETED_AT.columnName, null) after?.let { gte(Column.SCHEDULED_AT.columnName, it) } - order(Column.SCHEDULED_AT.columnName, order = order.toSupabaseOrder()) - limit(count = limit.toLong()) - }, - ) + } + order(Column.SCHEDULED_AT.columnName, order = order.toSupabaseOrder()) + limit(count = limit.toLong()) + } .decodeList() .map(NetworkSchedule::toSchedule) .also { log.d { "getScheduleList: $it" } } override suspend fun getSchedule(id: String): Schedule { return postgrest - .select( - single = true, - filter = { eq("id", id) }, - ) + .select { + single() + filter { + exact(Column.DELETED_AT.columnName, null) + } + } .decodeSingle() .toSchedule() } diff --git a/core/network/src/commonMain/kotlin/club/nito/core/network/user/SupabaseUserRemoteDataSource.kt b/core/network/src/commonMain/kotlin/club/nito/core/network/user/SupabaseUserRemoteDataSource.kt index 726a352a..8661d8f6 100644 --- a/core/network/src/commonMain/kotlin/club/nito/core/network/user/SupabaseUserRemoteDataSource.kt +++ b/core/network/src/commonMain/kotlin/club/nito/core/network/user/SupabaseUserRemoteDataSource.kt @@ -12,22 +12,23 @@ public class SupabaseUserRemoteDataSource( override suspend fun getProfile(userId: String): UserProfile? { return postgrest - .select( - filter = { + .select { + single() + filter { eq("id", userId) - }, - ) + } + } .decodeSingleOrNull() ?.let(NetworkUserProfile::toUserProfile) } override suspend fun getProfiles(userIds: List): List { return postgrest - .select( - filter = { + .select { + filter { isIn("id", userIds) - }, - ) + } + } .decodeList() .map(NetworkUserProfile::toUserProfile) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d528dd41..f24ad1d6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -25,7 +25,7 @@ ossLicenses = "17.0.1" detekt = "1.23.4" twitterComposeRule = "0.0.26" kover = "0.7.4" -supabase = "1.4.5" +supabase = "2.0.0-alpha-2" logback = "1.4.11" graphqlKotlin = "7.0.2" kotest = "5.8.0"