di_notfull
This commit is contained in:
parent
88d33fa255
commit
cd2dd395a4
@ -42,13 +42,15 @@ android {
|
||||
|
||||
dependencies {
|
||||
|
||||
|
||||
implementation("io.insert-koin:koin-compose:4.1.0-Beta5")
|
||||
implementation("io.insert-koin:koin-compose-viewmodel:4.1.0-Beta5")
|
||||
implementation(libs.androidx.core.ktx)
|
||||
implementation("androidx.datastore:datastore-preferences:1.1.3")
|
||||
implementation("com.squareup.okhttp3:okhttp:4.12.0")
|
||||
implementation("com.squareup.retrofit2:retrofit:2.11.0")
|
||||
implementation(libs.androidx.datastore.preferences)
|
||||
implementation(libs.okhttp)
|
||||
implementation(libs.retrofit)
|
||||
//noinspection UseTomlInstead
|
||||
implementation("com.squareup.retrofit2:converter-kotlinx-serialization:2.11.0")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0")
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||
implementation(libs.androidx.activity.compose)
|
||||
implementation(platform(libs.androidx.compose.bom))
|
||||
|
@ -3,6 +3,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<application
|
||||
android:name=".MainApplication"
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
|
@ -0,0 +1,17 @@
|
||||
package com.example.shoesapptest
|
||||
|
||||
import android.app.Application
|
||||
import com.example.shoesapptest.di.appModules
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.core.context.startKoin
|
||||
|
||||
|
||||
class MainApplication: Application() {
|
||||
override fun onCreate(){
|
||||
super.onCreate()
|
||||
startKoin{
|
||||
androidContext(applicationContext)
|
||||
modules(appModules)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.example.shoesapptest.data.remote.network
|
||||
|
||||
sealed class NetworkResponse<out T> {
|
||||
data class Success<out T>(val data: T) : NetworkResponse<T>()
|
||||
data object Loading : NetworkResponse<Nothing>()
|
||||
data class Error(val errorMessage: String) : NetworkResponse<Nothing>()
|
||||
}
|
@ -8,7 +8,7 @@ import retrofit2.converter.kotlinx.serialization.asConverterFactory
|
||||
|
||||
|
||||
object RetrofitClient {
|
||||
private const val URL = "http://26.197.138.194:8080"
|
||||
private const val URL = "http://192.168.4.56:8080"
|
||||
private val retrofit = Retrofit.Builder()
|
||||
.baseUrl(URL)
|
||||
.addConverterFactory(Json.asConverterFactory("application/json; charset=UTF8".toMediaType()))
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.example.shoesapptest.data.remote.network.auth
|
||||
|
||||
import com.example.shoesapptest.data.remote.network.dto.RegistrationRequest
|
||||
import com.example.shoesapptest.data.remote.network.dto.RegistrationResponse
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.POST
|
||||
|
||||
interface AuthRemoteSource {
|
||||
@POST("/registration")
|
||||
suspend fun registration(@Body registrationRequest: RegistrationRequest):RegistrationResponse
|
||||
suspend fun registration(@Body registrationRequest: RegistrationRequest): RegistrationResponse
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.example.shoesapptest.data.remote.network.auth
|
||||
package com.example.shoesapptest.data.remote.network.dto
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.example.shoesapptest.data.remote.network.auth
|
||||
package com.example.shoesapptest.data.remote.network.dto
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
@ -1,12 +1,13 @@
|
||||
package com.example.shoesapptest.data.repository
|
||||
|
||||
import com.example.shoesapptest.data.local.DataStore
|
||||
import com.example.shoesapptest.data.remote.network.NetworkResponse
|
||||
import com.example.shoesapptest.data.remote.network.auth.AuthRemoteSource
|
||||
import com.example.shoesapptest.data.remote.network.auth.RegistrationRequest
|
||||
import com.example.shoesapptest.data.remote.network.dto.RegistrationRequest
|
||||
import com.example.shoesapptest.data.remote.network.dto.RegistrationResponse
|
||||
|
||||
class AuthRepository(val dataStore: DataStore, val authRemoteSource: AuthRemoteSource) {
|
||||
suspend fun registration(registrationRequest: RegistrationRequest){
|
||||
val result = authRemoteSource.registration(registrationRequest)
|
||||
dataStore.setToken(result.second)
|
||||
class AuthRepository(val authRemoteSource: AuthRemoteSource) {
|
||||
suspend fun registration(registrationRequest: RegistrationRequest): RegistrationResponse {
|
||||
return authRemoteSource.registration(registrationRequest)
|
||||
}
|
||||
}
|
16
app/src/main/java/com/example/shoesapptest/di/appModules.kt
Normal file
16
app/src/main/java/com/example/shoesapptest/di/appModules.kt
Normal file
@ -0,0 +1,16 @@
|
||||
package com.example.shoesapptest.di
|
||||
|
||||
import com.example.shoesapptest.data.local.DataStore
|
||||
import com.example.shoesapptest.data.remote.network.RetrofitClient
|
||||
import com.example.shoesapptest.data.remote.network.auth.AuthRemoteSource
|
||||
import com.example.shoesapptest.data.repository.AuthRepository
|
||||
import com.example.shoesapptest.screen.regscreen.RegistrationViewModel
|
||||
import org.koin.core.module.dsl.viewModel
|
||||
import org.koin.dsl.module
|
||||
|
||||
val appModules = module {
|
||||
single{ DataStore(get())}
|
||||
single <AuthRemoteSource> {RetrofitClient.auth}
|
||||
single <AuthRepository> {AuthRepository(get()) }
|
||||
viewModel { RegistrationViewModel(get()) }
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.example.shoesapptest.domain.usecase
|
||||
|
||||
import com.example.shoesapptest.data.local.DataStore
|
||||
import com.example.shoesapptest.data.remote.network.NetworkResponse
|
||||
import com.example.shoesapptest.data.remote.network.dto.RegistrationRequest
|
||||
import com.example.shoesapptest.data.remote.network.dto.RegistrationResponse
|
||||
import com.example.shoesapptest.data.repository.AuthRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
|
||||
class AuthUseCase(private val dataStore: DataStore, private val authRepository: AuthRepository) {
|
||||
val token: Flow<String> = dataStore.tokenFlow
|
||||
|
||||
suspend fun registration(registrationRequest: RegistrationRequest): Flow<NetworkResponse<RegistrationResponse>> = flow {
|
||||
try {
|
||||
emit(NetworkResponse.Loading)
|
||||
val result = authRepository.registration(registrationRequest)
|
||||
dataStore.setToken(result.second)
|
||||
emit(NetworkResponse.Success(result))
|
||||
} catch (e: Exception) {
|
||||
e.message?.let {
|
||||
emit(NetworkResponse.Error(it))
|
||||
return@flow
|
||||
}
|
||||
emit(NetworkResponse.Error("Unknown Error"))
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,9 @@
|
||||
package com.example.shoesapptest.screen.regscreen
|
||||
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.example.shoesapptest.data.remote.network.auth.RegistrationRequest
|
||||
import com.example.shoesapptest.data.remote.network.dto.RegistrationRequest
|
||||
import com.example.shoesapptest.data.repository.AuthRepository
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@ -40,7 +38,6 @@ class RegistrationViewModel(
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
onSuccess()
|
||||
} catch (e: Exception) {
|
||||
_registration.value = _registration.value.copy(errorMessage = "Ошибка регистрации: ${e.message}")
|
||||
|
@ -1,16 +1,21 @@
|
||||
[versions]
|
||||
agp = "8.8.0"
|
||||
datastorePreferences = "1.1.3"
|
||||
kotlin = "2.0.0"
|
||||
coreKtx = "1.15.0"
|
||||
junit = "4.13.2"
|
||||
junitVersion = "1.2.1"
|
||||
espressoCore = "3.6.1"
|
||||
kotlinxSerializationJson = "1.8.0"
|
||||
lifecycleRuntimeKtx = "2.6.1"
|
||||
activityCompose = "1.10.0"
|
||||
composeBom = "2024.04.01"
|
||||
okhttp = "4.12.0"
|
||||
retrofit = "2.11.0"
|
||||
|
||||
[libraries]
|
||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||
androidx-datastore-preferences = { module = "androidx.datastore:datastore-preferences", version.ref = "datastorePreferences" }
|
||||
junit = { group = "junit", name = "junit", version.ref = "junit" }
|
||||
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
|
||||
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
|
||||
@ -24,6 +29,9 @@ androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-toolin
|
||||
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
|
||||
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
|
||||
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
|
||||
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }
|
||||
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
|
||||
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
|
||||
|
||||
[plugins]
|
||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||
|
Loading…
Reference in New Issue
Block a user