Skip to content

Commit

Permalink
Replace gotrue with auth
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuwu committed Dec 19, 2023
1 parent 8967dbb commit ee37836
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 28 deletions.
7 changes: 2 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ android {
}

buildFeatures {
dataBinding true
viewBinding true
compose true
}

composeOptions {
kotlinCompilerExtensionVersion "1.2.0"
kotlinCompilerExtensionVersion "1.5.2"
}
namespace 'com.hieuwu.groceriesstore'
}
Expand All @@ -69,7 +67,6 @@ dependencies {
implementation libs.kotlin.stdlib

implementation libs.legacy.support.v4
implementation libs.rxjava

implementation libs.timber

Expand Down Expand Up @@ -97,7 +94,7 @@ dependencies {

// implementation("io.github.jan-tennert.supabase:postgrest-kt:0.2.0")
implementation("io.ktor:ktor-client-cio:1.6.0")
implementation("io.github.jan-tennert.supabase:postgrest-kt-android:0.9.0-alpha-4")
implementation("io.github.jan-tennert.supabase:postgrest-kt-android:2.0.0")
implementation "io.ktor:ktor-client-android:2.2.1"
implementation "io.ktor:ktor-utils-jvm:1.6.0"
implementation "io.ktor:ktor-client-logging-jvm:1.6.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.hieuwu.groceriesstore.data.network.dto.UserDto
import com.hieuwu.groceriesstore.data.repository.UserRepository
import com.hieuwu.groceriesstore.utilities.CollectionNames
import com.hieuwu.groceriesstore.utilities.SupabaseMapper
import io.github.jan.supabase.gotrue.GoTrue
import io.github.jan.supabase.gotrue.Auth
import io.github.jan.supabase.gotrue.providers.builtin.Email
import io.github.jan.supabase.postgrest.Postgrest
import java.util.*
Expand All @@ -17,7 +17,7 @@ import javax.inject.Inject

class UserRepositoryImpl @Inject constructor(
private val userDao: UserDao,
private val authService: GoTrue,
private val authService: Auth,
private val postgrest: Postgrest,
) : UserRepository {

Expand All @@ -37,7 +37,7 @@ class UserRepositoryImpl @Inject constructor(
isPromotionNotiEnabled = false,
isDataRefreshedNotiEnabled = false
)
postgrest[CollectionNames.users].insert(value = userDto, upsert = true)
postgrest[CollectionNames.users].upsert(value = userDto)
val user = SupabaseMapper.mapDtoToEntity(userDto)
userDao.insert(user)
true
Expand All @@ -49,7 +49,7 @@ class UserRepositoryImpl @Inject constructor(

override suspend fun authenticate(email: String, password: String): Boolean {
return try {
authService.loginWith(Email) {
authService.signInWith(Email) {
this.email = email
this.password = password
}
Expand Down Expand Up @@ -85,7 +85,7 @@ class UserRepositoryImpl @Inject constructor(
UserDto::address setTo address
}
) {
UserDto::id eq userId
UserDto::id to userId
}
userDao.insert(dbUser)
} catch (e: Exception) {
Expand All @@ -94,7 +94,7 @@ class UserRepositoryImpl @Inject constructor(
}

override suspend fun clearUser() {
userDao.clear()
userDao.clearUser()
}

override suspend fun updateUserSettings(
Expand All @@ -111,7 +111,9 @@ class UserRepositoryImpl @Inject constructor(
UserDto::isPromotionNotiEnabled setTo isPromotionEnabled
}
) {
UserDto::id eq id
filter {
UserDto::id eq id
}
}
userDao.updateUserSettings(
id,
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/hieuwu/groceriesstore/di/SupabaseModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
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.gotrue
import io.github.jan.supabase.gotrue.Auth
import io.github.jan.supabase.gotrue.auth
import io.github.jan.supabase.postgrest.Postgrest
import io.github.jan.supabase.postgrest.postgrest
import io.ktor.client.plugins.*
Expand All @@ -26,7 +26,7 @@ object SupabaseModule {
supabaseKey = BuildConfig.API_KEY
) {
install(Postgrest)
install(GoTrue)
install(Auth)
}
}

Expand All @@ -38,8 +38,8 @@ object SupabaseModule {

@Provides
@Singleton
fun provideSupabaseGoTrue(client: SupabaseClient): GoTrue {
return client.gotrue
fun provideSupabaseGoTrue(client: SupabaseClient): Auth {
return client.auth
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class ExploreViewModel @Inject constructor(
fun searchProduct(name: String) {
if (name.isNotBlank()) {
viewModelScope.launch {
val res = searchProductUseCase.execute(SearchProductUseCase.Input(name = name.trim()))
val res =
searchProductUseCase.execute(SearchProductUseCase.Input(name = name.trim()))
res.result.collect {
_productList.value = it
}
Expand Down Expand Up @@ -96,7 +97,10 @@ class ExploreViewModel @Inject constructor(
val cartId = _currentCart.value!!.id
viewModelScope.launch {
val lineItem = LineItem(
product.id, cartId, 1, product.price!!
productId = product.id,
orderId = cartId,
quantity = 1,
subtotal = product.price!!
)
addToCartUseCase.execute(AddToCartUseCase.Input(lineItem = lineItem))
}
Expand All @@ -106,7 +110,10 @@ class ExploreViewModel @Inject constructor(
viewModelScope.launch {
createNewOrderUseCase.execute(CreateNewOrderUseCase.Input(order = newOrder))
val lineItem = LineItem(
product.id, id, 1, product.price!!
productId = product.id,
orderId = id,
quantity = 1,
subtotal = product.price!!
)
addToCartUseCase.execute(AddToCartUseCase.Input(lineItem = lineItem))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ShopViewModel @Inject constructor(
currentCart.collect {}
}
}

fun displayProductDetails(product: ProductModel) {
_navigateToSelectedProperty.value = product
}
Expand Down Expand Up @@ -82,10 +83,10 @@ class ShopViewModel @Inject constructor(
addToCartUseCase.execute(
AddToCartUseCase.Input(
LineItem(
product.id,
cartId,
1,
product.price!!
productId = product.id,
orderId = cartId,
quantity = 1,
subtotal = product.price!!
)
)
)
Expand All @@ -96,15 +97,20 @@ class ShopViewModel @Inject constructor(
createNewOrderUseCase.execute(
CreateNewOrderUseCase.Input(
Order(
id,
OrderStatus.IN_CART.value,
""
id = id,
status = OrderStatus.IN_CART.value,
address = ""
)
)
)
addToCartUseCase.execute(
AddToCartUseCase.Input(
LineItem(product.id, id, 1, product.price!!)
LineItem(
productId = product.id,
orderId = id,
quantity = 1,
subtotal = product.price!!
)
)
)
}
Expand Down

0 comments on commit ee37836

Please sign in to comment.