This commit is contained in:
user5 2025-05-27 12:53:45 +03:00
parent a9b847e155
commit ed684fb2e8
7 changed files with 25 additions and 0 deletions

View File

@ -9,6 +9,9 @@ import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.create
/**
* фабрика для создание инстанса интерфейса без внешнего доступа к реализации
* */
object ApiFactory {
fun provideRepository(dataStoreRepository: DataStoreRepository): ApiRepository {

View File

@ -19,6 +19,9 @@ import retrofit2.http.Query
* Дата создания: 27.05.2025
* */
/**
* общий сервис для запросов
* */
internal interface ApiService {
@POST("collections/users/records")

View File

@ -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() }

View File

@ -13,6 +13,9 @@ import java.net.UnknownHostException
* Дата создания: 27.05.2025
* */
/**
* общая структура обработки запросов
* */
internal interface Handle {
suspend fun <T> handle(action: suspend () -> T): FetchResult<T>

View File

@ -12,6 +12,9 @@ import kotlinx.coroutines.flow.map
* Дата создания: 27.05.2025
* */
/**
* Локальное хранение токена
* */
interface DataStoreRepository {
suspend fun saveToken(token: String)

View File

@ -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(

View File

@ -23,6 +23,13 @@ import retrofit2.create
* Дата создания: 27.05.2025
* */
/**
* Общая структура тестов
* фейк ответ
* сверка с dto некоторые параметры
* проверка типа запроса
* проверка пути запроса
* опционально параметры и указание пути*/
class ServiceTest {
private lateinit var mockWebServer: MockWebServer