Добавил работу с сетью и сценарии авторизации

This commit is contained in:
2025-12-25 16:14:55 +03:00
parent b41de4aaf5
commit d8a0237e43
35 changed files with 869 additions and 271 deletions

View File

@@ -1,6 +1,8 @@
package com.novayaplaneta.di
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.novayaplaneta.data.remote.AuthApi
import com.novayaplaneta.data.remote.AuthInterceptor
import com.novayaplaneta.data.remote.BackendApi
import dagger.Module
import dagger.Provides
@@ -17,43 +19,57 @@ import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object NetworkModule {
private val json = Json {
ignoreUnknownKeys = true
isLenient = true
encodeDefaults = false
}
@Provides
@Singleton
fun provideOkHttpClient(): OkHttpClient {
fun provideOkHttpClient(
authInterceptor: AuthInterceptor
): OkHttpClient {
val loggingInterceptor = HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}
return OkHttpClient.Builder()
.addInterceptor(authInterceptor)
.addInterceptor(loggingInterceptor)
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.build()
}
@Provides
@Singleton
fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit {
fun provideRetrofit(
okHttpClient: OkHttpClient
): Retrofit {
val contentType = "application/json".toMediaType()
return Retrofit.Builder()
.baseUrl("https://api.novayaplaneta.ru/")
.baseUrl("http://10.0.2.2:8000/")
.client(okHttpClient)
.addConverterFactory(json.asConverterFactory(contentType))
.build()
}
@Provides
@Singleton
fun provideBackendApi(retrofit: Retrofit): BackendApi {
fun provideAuthApi(
retrofit: Retrofit
): AuthApi {
return retrofit.create(AuthApi::class.java)
}
@Provides
@Singleton
fun provideBackendApi(
retrofit: Retrofit
): BackendApi {
return retrofit.create(BackendApi::class.java)
}
}