Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

docs: refactor sample

Hieu Vu3a21fc93fab4
diff --git a/examples/product-sample-supabase-kt/LICENSE b/examples/product-sample-supabase-kt/LICENSE
deleted file mode 100644
index 4651f913ec3..00000000000
--- a/examples/product-sample-supabase-kt/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2023 Hieu Vu
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/examples/product-sample-supabase-kt/README.md b/examples/product-sample-supabase-kt/README.md
deleted file mode 100644
index 5e3d0c88cc5..00000000000
--- a/examples/product-sample-supabase-kt/README.md
+++ /dev/null
@@ -1,20 +0,0 @@
-# product-sample-supabase-kt
-Demonstration and best practices of how to use Supabase database for CRUD operation
-
-[![Android CI](https://github.com/hieuwu/product-sample-supabase-kt/actions/workflows/app-build.yml/badge.svg)](https://github.com/hieuwu/product-sample-supabase-kt/actions/workflows/app-build.yml)
-
-<!-- <img width="964" alt="Screen Shot 2023-06-02 at 21 33 16" src="https://github.com/hieuwu/product-sample-supabase-kt/assets/43868345/288eef97-d8fe-422f-8bb3-1c8424bab08e">
-
-<img width="1092" alt="Screen Shot 2023-06-05 at 21 39 24" src="https://github.com/hieuwu/product-sample-supabase-kt/assets/43868345/3f154fda-aa9e-4baa-81f2-5b744c7ad2fe"> -->
-
-![manage-product-cover](https://github.com/hieuwu/product-sample-supabase-kt/assets/43868345/1bed0c84-208a-4266-a2ec-2bac50ddf80c)
-
-### Setup
-Android Studio with SDK 30 or above
-Open `local.properties` file, add these
-```kotlin
-API_KEY=YOUR_SUPABASE_API_KEY
-SECRET=YOUR_SUPABASE_SECRET
-SUPABASE_URL=YOUR_SUPABASE_URL
-
-```
diff --git a/examples/product-sample-supabase-kt/app/build.gradle b/examples/product-sample-supabase-kt/app/build.gradle
index 81be04636da..4cbbf0294bb 100644
--- a/examples/product-sample-supabase-kt/app/build.gradle
+++ b/examples/product-sample-supabase-kt/app/build.gradle
@@ -4,7 +4,7 @@ plugins {
id 'com.google.dagger.hilt.android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
- id 'org.jetbrains.kotlin.plugin.serialization' version '1.6.21'
+ id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.0'
}
android {
@@ -87,7 +87,7 @@ dependencies {
implementation "com.google.dagger:hilt-android:$hilt_version"
annotationProcessor "com.google.dagger:hilt-compiler:$hilt_version"
- implementation("androidx.hilt:hilt-navigation-compose:1.0.0")
+ implementation "androidx.hilt:hilt-navigation-compose:1.0.0"
// For instrumentation tests
androidTestImplementation "com.google.dagger:hilt-android-testing:$hilt_version"
diff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/ImageRepository.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/ImageRepository.kt
deleted file mode 100644
index 4a84ebce96e..00000000000
--- a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/ImageRepository.kt
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.example.manageproducts.data.repository
-
-interface ImageRepository {
- suspend fun uploadImage(fileName: String, image: ByteArray): String
- suspend fun getImage()
-}
\ No newline at end of file
diff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/impl/ImageRepositoryImpl.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/impl/ImageRepositoryImpl.kt
deleted file mode 100644
index 348c40ec667..00000000000
--- a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/data/repository/impl/ImageRepositoryImpl.kt
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.example.manageproducts.data.repository.impl
-
-import com.example.manageproducts.BuildConfig
-import com.example.manageproducts.data.repository.ImageRepository
-import io.github.jan.supabase.storage.Storage
-import javax.inject.Inject
-
-class ImageRepositoryImpl @Inject constructor(
- private val storage: Storage
-) : ImageRepository {
- override suspend fun uploadImage(fileName: String, image: ByteArray): String {
- val result =
- storage["Product%20Image"].upload(path = "$fileName.png", data = image, upsert = false)
- return result
- }
-
- override suspend fun getImage() {
- TODO("Not yet implemented")
- }
-
- private fun buildImageUrl(imageFileName: String) =
- "${BuildConfig.SUPABASE_URL}/storage/v1/object/public/"
-
-}
\ No newline at end of file
diff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/di/RepositoryModule.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/di/RepositoryModule.kt
index fac3c1deea3..4988621fa08 100644
--- a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/di/RepositoryModule.kt
+++ b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/di/RepositoryModule.kt
@@ -1,10 +1,8 @@
package com.example.manageproducts.di
import com.example.manageproducts.data.repository.AuthenticationRepository
-import com.example.manageproducts.data.repository.ImageRepository
import com.example.manageproducts.data.repository.ProductRepository
import com.example.manageproducts.data.repository.impl.AuthenticationRepositoryImpl
-import com.example.manageproducts.data.repository.impl.ImageRepositoryImpl
import com.example.manageproducts.data.repository.impl.ProductRepositoryImpl
import dagger.Binds
import dagger.Module
@@ -18,9 +16,6 @@ abstract class RepositoryModule {
@Binds
abstract fun bindProductRepository(impl: ProductRepositoryImpl): ProductRepository
- @Binds
- abstract fun bindImageRepository(impl: ImageRepositoryImpl): ImageRepository
-
@Binds
abstract fun bindAuthenticateRepository(impl: AuthenticationRepositoryImpl): AuthenticationRepository
diff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/di/UseCaseModule.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/di/UseCaseModule.kt
index 05a246c50d8..52c6bae49f4 100644
--- a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/di/UseCaseModule.kt
+++ b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/di/UseCaseModule.kt
@@ -26,9 +26,6 @@ abstract class UseCaseModule {
@Binds
abstract fun bindUpdateProductUseCase(impl: UpdateProductUseCaseImpl): UpdateProductUseCase
- @Binds
- abstract fun bindUploadImageUseCaseImpl(impl: UploadImageUseCaseImpl): UploadImageUseCase
-
@Binds
abstract fun bindAuthenticateUseCase(impl: SignInUseCaseImpl): SignInUseCase
diff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/domain/usecase/UploadImageUseCase.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/domain/usecase/UploadImageUseCase.kt
deleted file mode 100644
index 83a7eb11e01..00000000000
--- a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/domain/usecase/UploadImageUseCase.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.example.manageproducts.domain.usecase
-
-interface UploadImageUseCase : UseCase<UploadImageUseCase.Input, UploadImageUseCase.Output> {
- class Input(val fileName: String, val imageByteArray: ByteArray)
- sealed class Output {
- class Success(val image: String? = null) : Output()
- }
-}
\ No newline at end of file
diff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/domain/usecase/impl/UploadImageUseCaseImpl.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/domain/usecase/impl/UploadImageUseCaseImpl.kt
deleted file mode 100644
index b12eb7af3c4..00000000000
--- a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/domain/usecase/impl/UploadImageUseCaseImpl.kt
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.example.manageproducts.domain.usecase.impl
-
-import android.util.Log
-import com.example.manageproducts.data.repository.ImageRepository
-import com.example.manageproducts.domain.usecase.UploadImageUseCase
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.withContext
-import javax.inject.Inject
-
-class UploadImageUseCaseImpl @Inject constructor(
- private val imageRepository: ImageRepository
-) : UploadImageUseCase {
- override suspend fun execute(input: UploadImageUseCase.Input): UploadImageUseCase.Output {
- return withContext(Dispatchers.IO) {
- val url = imageRepository.uploadImage(input.fileName, input.imageByteArray)
- Log.d("UploadImageUseCase", url)
- UploadImageUseCase.Output.Success()
- }
- }
-}
\ No newline at end of file
diff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/productdetails/ProductDetailsViewModel.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/productdetails/ProductDetailsViewModel.kt
index 3347cf9b00d..4e25ec8fe62 100644
--- a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/productdetails/ProductDetailsViewModel.kt
+++ b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/productdetails/ProductDetailsViewModel.kt
@@ -6,7 +6,6 @@ import androidx.lifecycle.viewModelScope
import com.example.manageproducts.domain.model.Product
import com.example.manageproducts.domain.usecase.GetProductDetailsUseCase
import com.example.manageproducts.domain.usecase.UpdateProductUseCase
-import com.example.manageproducts.domain.usecase.UploadImageUseCase
import com.example.manageproducts.presentation.navigation.ProductDetailsDestination
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
@@ -18,9 +17,7 @@ import javax.inject.Inject
class ProductDetailsViewModel @Inject constructor(
private val getProductDetailsUseCase: GetProductDetailsUseCase,
private val updateProductUseCase: UpdateProductUseCase,
- private val uploadImageUseCase: UploadImageUseCase,
savedStateHandle: SavedStateHandle,
-
) : ViewModel(), ProductDetailsContract {
private val _product = MutableStateFlow<Product?>(null)
override val product: Flow<Product?> = _product
@@ -81,14 +78,6 @@ class ProductDetailsViewModel @Inject constructor(
imageName = "image_${_product.value?.id}",
)
)
- if (image.isNotEmpty()) {
-// uploadImageUseCase.execute(
-// UploadImageUseCase.Input(
-// "image_${_product.value?.id}",
-// imageByteArray = image
-// )
-// )
- }
}
}
diff --git a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/signin/SignInScreen.kt b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/signin/SignInScreen.kt
index 20843fb0979..8de22f49135 100644
--- a/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/signin/SignInScreen.kt
+++ b/examples/product-sample-supabase-kt/app/src/main/java/com/example/manageproducts/presentation/feature/signin/SignInScreen.kt
@@ -28,7 +28,6 @@ fun SignInScreen(
navController: NavController,
viewModel: SignInViewModel = hiltViewModel()
) {
-
val snackBarHostState = remember { SnackbarHostState() }
val coroutineScope = rememberCoroutineScope()
Scaffold(
diff --git a/examples/product-sample-supabase-kt/build.gradle b/examples/product-sample-supabase-kt/build.gradle
index 323f0e263c1..6a13fa6f511 100644
--- a/examples/product-sample-supabase-kt/build.gradle
+++ b/examples/product-sample-supabase-kt/build.gradle
@@ -9,5 +9,5 @@ plugins {
id 'com.android.library' version '7.4.2' apply false
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
id("com.google.dagger.hilt.android") version "2.44" apply false
- id 'org.jetbrains.kotlin.plugin.serialization' version '1.6.21'
+ id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.0'
}
\ No newline at end of file