comments
This commit is contained in:
parent
a9b847e155
commit
ed684fb2e8
@ -9,6 +9,9 @@ import okhttp3.logging.HttpLoggingInterceptor
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.create
|
||||
|
||||
/**
|
||||
* фабрика для создание инстанса интерфейса без внешнего доступа к реализации
|
||||
* */
|
||||
object ApiFactory {
|
||||
|
||||
fun provideRepository(dataStoreRepository: DataStoreRepository): ApiRepository {
|
||||
|
@ -19,6 +19,9 @@ import retrofit2.http.Query
|
||||
* Дата создания: 27.05.2025
|
||||
* */
|
||||
|
||||
/**
|
||||
* общий сервис для запросов
|
||||
* */
|
||||
internal interface ApiService {
|
||||
|
||||
@POST("collections/users/records")
|
||||
|
@ -10,6 +10,9 @@ import okhttp3.Response
|
||||
* Дата создания: 27.05.2025
|
||||
* */
|
||||
|
||||
/**
|
||||
* Перехватчик для установки токена в заголовок запроса
|
||||
* */
|
||||
class AuthInterceptor(private val dataStoreRepository: DataStoreRepository) : Interceptor {
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val token = runBlocking { dataStoreRepository.token().first() }
|
||||
|
@ -13,6 +13,9 @@ import java.net.UnknownHostException
|
||||
* Дата создания: 27.05.2025
|
||||
* */
|
||||
|
||||
/**
|
||||
* общая структура обработки запросов
|
||||
* */
|
||||
internal interface Handle {
|
||||
suspend fun <T> handle(action: suspend () -> T): FetchResult<T>
|
||||
|
||||
|
@ -12,6 +12,9 @@ import kotlinx.coroutines.flow.map
|
||||
* Дата создания: 27.05.2025
|
||||
* */
|
||||
|
||||
/**
|
||||
* Локальное хранение токена
|
||||
* */
|
||||
interface DataStoreRepository {
|
||||
|
||||
suspend fun saveToken(token: String)
|
||||
|
@ -17,6 +17,9 @@ import com.example.api.core.domain.SignInUserResponse
|
||||
* Дата создания: 27.05.2025
|
||||
* */
|
||||
|
||||
/**
|
||||
Маппер для преобразования объектов сервера в доменные
|
||||
* */
|
||||
internal abstract class RemoteMapper {
|
||||
protected fun RegisterUser.toRegisterUserDto(): RegisterUserDto {
|
||||
return RegisterUserDto(
|
||||
|
@ -23,6 +23,13 @@ import retrofit2.create
|
||||
* Дата создания: 27.05.2025
|
||||
* */
|
||||
|
||||
/**
|
||||
* Общая структура тестов
|
||||
* фейк ответ
|
||||
* сверка с dto некоторые параметры
|
||||
* проверка типа запроса
|
||||
* проверка пути запроса
|
||||
* опционально параметры и указание пути*/
|
||||
class ServiceTest {
|
||||
|
||||
private lateinit var mockWebServer: MockWebServer
|
||||
|
Loading…
x
Reference in New Issue
Block a user