Update Kotlin tutorials to be aligned with supabase-kt v2.0.0 (#19998)

* Update Kotlin tutorials with supabase 2.0.0

* Update build gradle

* Update with-kotlin.mdx

* Update with-kotlin.mdx

---------

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>
This commit is contained in:
Hieu Vu
2024-01-04 01:27:57 +07:00
committed by GitHub
parent 247de3b4e2
commit c09caa317a
5 changed files with 34 additions and 20 deletions

View File

@@ -269,7 +269,9 @@ class ProductRepositoryImpl @Inject constructor(
override suspend fun getProduct(id: String): ProductDto {
return withContext(Dispatchers.IO) {
postgrest.from("products").select {
eq("id", id)
filter {
eq("id", id)
}
}.decodeSingle<ProductDto>()
}
}
@@ -277,7 +279,9 @@ class ProductRepositoryImpl @Inject constructor(
override suspend fun deleteProduct(id: String) {
return withContext(Dispatchers.IO) {
postgrest.from("products").delete {
eq("id", id)
filter {
eq("id", id)
}
}
}
}

View File

@@ -74,12 +74,12 @@ dependencies {
implementation "androidx.compose.material:material:1.1.1"
// Supabase setup
implementation "io.github.jan-tennert.supabase:gotrue-kt:1.0.0"
implementation "io.github.jan-tennert.supabase:postgrest-kt:1.0.0"
implementation "io.github.jan-tennert.supabase:storage-kt:1.0.0"
implementation "io.ktor:ktor-client-android:2.3.0"
implementation "io.ktor:ktor-utils:2.3.0"
implementation "io.ktor:ktor-client-core:2.3.0"
implementation "io.github.jan-tennert.supabase:gotrue-kt:$supabase_version"
implementation "io.github.jan-tennert.supabase:postgrest-kt:$supabase_version"
implementation "io.github.jan-tennert.supabase:storage-kt:$supabase_version"
implementation "io.ktor:ktor-client-android:$ktor_version"
implementation "io.ktor:ktor-utils:$ktor_version"
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.coil-kt:coil-compose:1.3.2"

View File

@@ -1,16 +1,17 @@
package com.example.manageproducts.data.repository.impl
import com.example.manageproducts.data.repository.AuthenticationRepository
import io.github.jan.supabase.gotrue.GoTrue
import io.github.jan.supabase.gotrue.Auth
import io.github.jan.supabase.gotrue.providers.Google
import io.github.jan.supabase.gotrue.providers.builtin.Email
import javax.inject.Inject
class AuthenticationRepositoryImpl @Inject constructor(
private val goTrue: GoTrue
private val auth: Auth,
) : AuthenticationRepository {
override suspend fun signIn(email: String, password: String): Boolean {
return try {
goTrue.loginWith(Email) {
auth.signInWith(Email) {
this.email = email
this.password = password
}
@@ -22,7 +23,7 @@ class AuthenticationRepositoryImpl @Inject constructor(
override suspend fun signUp(email: String, password: String): Boolean {
return try {
goTrue.signUpWith(Email) {
auth.signUpWith(Email) {
this.email = email
this.password = password
}
@@ -34,7 +35,7 @@ class AuthenticationRepositoryImpl @Inject constructor(
override suspend fun signInWithGoogle(): Boolean {
return try {
goTrue.loginWith(Google)
auth.signInWith(Google)
true
} catch (e: Exception) {
false

View File

@@ -34,13 +34,17 @@ class ProductRepositoryImpl @Inject constructor(
override suspend fun getProduct(id: String): ProductDto {
return postgrest["products"].select {
eq("id", id)
filter {
eq("id", id)
}
}.decodeSingle<ProductDto>()
}
override suspend fun deleteProduct(id: String) {
postgrest["products"].delete {
eq("id", id)
filter {
eq("id", id)
}
}
}
@@ -63,14 +67,18 @@ class ProductRepositoryImpl @Inject constructor(
set("price", price)
set("image", buildImageUrl(imageFileName = imageUrl))
}) {
eq("id", id)
filter {
eq("id", id)
}
}
} else {
postgrest["products"].update({
set("name", name)
set("price", price)
}) {
eq("id", id)
filter {
eq("id", id)
}
}
}
}

View File

@@ -1,13 +1,14 @@
buildscript {
ext {
compose_version = '1.2.0'
hilt_version = '2.44.2'
compose_version = '1.3.0'
hilt_version = '2.48'
ktor_version = '2.3.0'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
id 'org.jetbrains.kotlin.android' version '1.9.0' apply false
id("com.google.dagger.hilt.android") version "2.44" apply false
id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.0'
}