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

Uplift Supabase version #232

Merged
merged 7 commits into from
Dec 19, 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
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 @@ -14,7 +14,7 @@ interface CategoryDao {
fun insert(category: Category)

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(category: List<Category>)
fun insertAll(category: List<Category>)

@Query("SELECT * FROM $CATEGORY_TABLE")
fun getAll(): Flow<List<Category>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import kotlinx.coroutines.flow.Flow
@Dao
interface LineItemDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(lineItem: LineItem)
fun insert(lineItem: LineItem)

@Query("SELECT * FROM $LINE_ITEM_TABLE WHERE lineItemId = :id")
fun getById(id: Long): Flow<LineItem>
Expand All @@ -24,10 +24,10 @@ interface LineItemDao {
fun updateQuantityById(quantity: Int, id: Long)

@Delete
suspend fun remove(lineItem: LineItem)
fun remove(lineItem: LineItem)

@Update
suspend fun update(lineItem: LineItem)
fun update(lineItem: LineItem)

@Transaction
@Query("SELECT * FROM $LINE_ITEM_TABLE ")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.hieuwu.groceriesstore.data.database.dao

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
Expand All @@ -20,7 +19,7 @@ interface OrderDao {
fun update(order: Order)

@Query("DELETE FROM `$ORDER_TABLE`")
suspend fun clear()
fun clear()

@Transaction
@Query("SELECT * FROM `$ORDER_TABLE` WHERE orderId = :id")
Expand All @@ -38,4 +37,4 @@ interface OrderDao {
@Transaction
@Query("SELECT * FROM `$ORDER_TABLE` WHERE status = :status LIMIT 1 ")
fun getCartWithLineItems(status: String): Flow<OrderWithLineItems?>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import kotlinx.coroutines.flow.Flow

@Dao
interface ProductDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(product: Product)

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(products: List<Product>)
fun insertAll(products: List<Product>)

@Update
fun update(product: Product)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotlinx.coroutines.flow.Flow
@Dao
interface RecipeDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(recipes: List<Recipe>)
fun insertAll(recipes: List<Recipe>)

@Query("SELECT * FROM $RECIPE_TABLE")
fun getAll(): Flow<List<Recipe>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlinx.coroutines.flow.Flow
interface UserDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(user: User)
fun insert(user: User)

@Query("SELECT * FROM $USER_TABLE WHERE id = :id")
fun getById(id: String): Flow<User>
Expand All @@ -21,10 +21,10 @@ interface UserDao {
fun getCurrentUser(): Flow<User?>

@Query("DELETE FROM $USER_TABLE")
suspend fun clear()
fun clearUser()

@Query("UPDATE $USER_TABLE SET isOrderCreatedNotiEnabled = :isOrderCreatedEnabled, isDataRefreshedNotiEnabled =:isDatabaseRefreshedEnabled, isPromotionNotiEnabled =:isPromotionEnabled WHERE id = :id")
suspend fun updateUserSettings(
fun updateUserSettings(
id: String,
isOrderCreatedEnabled: Boolean,
isDatabaseRefreshedEnabled: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.hieuwu.groceriesstore.utilities.LINE_ITEM_TABLE
data class LineItem(
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "lineItemId")
val id: Long,
val id: Long = 0,

@ColumnInfo(name = "productId")
val productId: String,
Expand All @@ -23,12 +23,4 @@ data class LineItem(
@ColumnInfo(name = "subtotal")
var subtotal: Double

) {
constructor(productId: String, orderId: String, quantity: Int, subtotal: Double) : this(
0,
productId,
orderId,
quantity,
subtotal
)
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.hieuwu.groceriesstore.utilities.PRODUCT_TABLE
@Entity(tableName = PRODUCT_TABLE)
data class Product(
@PrimaryKey
@NonNull
@ColumnInfo(name = "productId")
val id: String,

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 @@ -4,24 +4,19 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import com.hieuwu.groceriesstore.R
import com.hieuwu.groceriesstore.databinding.FragmentMainBinding

class MainFragment : Fragment() {
private lateinit var binding: FragmentMainBinding

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {

binding = DataBindingUtil.inflate<FragmentMainBinding>(
inflater, R.layout.fragment_main, container, false
return inflater.inflate(
R.layout.fragment_main, container, false
)

return binding.root
}
}
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
Loading
Loading