move all ui-related classes and files to ui module
This commit is contained in:
@@ -2,10 +2,8 @@ package com.meloda.app.fast.data
|
||||
|
||||
import com.meloda.app.fast.network.OAuthErrorDomain
|
||||
import com.meloda.app.fast.network.RestApiErrorDomain
|
||||
import com.meloda.app.fast.network.VkErrorCode
|
||||
import com.slack.eithernet.ApiResult
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.filterIsInstance
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
sealed class State<out T> {
|
||||
|
||||
@@ -16,7 +14,7 @@ sealed class State<out T> {
|
||||
sealed class Error : State<Nothing>() {
|
||||
|
||||
data class ApiError(
|
||||
val errorCode: Int,
|
||||
val errorCode: VkErrorCode,
|
||||
val errorMessage: String,
|
||||
) : Error()
|
||||
|
||||
@@ -61,19 +59,9 @@ inline fun <T> State<T>.processState(
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T, R> Flow<State<T>>.mapSuccess(
|
||||
crossinline transform: suspend (value: T) -> R
|
||||
): Flow<R> = filterIsInstance<State.Success<T>>()
|
||||
.map { state -> transform.invoke(state.data) }
|
||||
|
||||
fun RestApiErrorDomain?.toStateApiError(): State.Error = when (this) {
|
||||
null -> State.Error.ConnectionError
|
||||
else -> State.Error.ApiError(code, message)
|
||||
}
|
||||
|
||||
fun OAuthErrorDomain?.toStateApiError(): State.Error = when (this) {
|
||||
null -> State.Error.ConnectionError
|
||||
else -> State.Error.OAuthError(this)
|
||||
else -> State.Error.ApiError(VkErrorCode.parse(code), message)
|
||||
}
|
||||
|
||||
fun <T : Any> ApiResult<T, RestApiErrorDomain>.mapToState() = when (this) {
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
package com.meloda.app.fast.data.api.auth
|
||||
|
||||
import com.meloda.app.fast.model.api.requests.AuthDirectRequest
|
||||
import com.meloda.app.fast.model.api.responses.AuthDirectResponse
|
||||
import com.meloda.app.fast.model.api.responses.SendSmsResponse
|
||||
import com.meloda.app.fast.network.OAuthErrorDomain
|
||||
import com.meloda.app.fast.model.api.responses.ValidatePhoneResponse
|
||||
import com.meloda.app.fast.network.RestApiErrorDomain
|
||||
import com.slack.eithernet.ApiResult
|
||||
|
||||
interface AuthRepository {
|
||||
|
||||
// suspend fun auth(
|
||||
// params: AuthDirectRequest
|
||||
// ): ApiResult<AuthDirectResponse, OAuthErrorDomain>
|
||||
|
||||
suspend fun sendSms(
|
||||
suspend fun validatePhone(
|
||||
validationSid: String
|
||||
): SendSmsResponse
|
||||
): ApiResult<ValidatePhoneResponse, RestApiErrorDomain>
|
||||
}
|
||||
|
||||
@@ -1,35 +1,20 @@
|
||||
package com.meloda.app.fast.data.api.auth
|
||||
|
||||
import com.meloda.app.fast.model.api.requests.AuthDirectRequest
|
||||
import com.meloda.app.fast.model.api.responses.AuthDirectResponse
|
||||
import com.meloda.app.fast.model.api.responses.SendSmsResponse
|
||||
import com.meloda.app.fast.network.OAuthErrorDomain
|
||||
import com.meloda.app.fast.model.api.responses.ValidatePhoneResponse
|
||||
import com.meloda.app.fast.network.RestApiErrorDomain
|
||||
import com.meloda.app.fast.network.mapApiDefault
|
||||
import com.meloda.app.fast.network.service.auth.AuthService
|
||||
import com.slack.eithernet.ApiResult
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class AuthRepositoryImpl(
|
||||
private val authService: AuthService
|
||||
private val service: AuthService
|
||||
) : AuthRepository {
|
||||
|
||||
// override suspend fun auth(
|
||||
// params: AuthDirectRequest
|
||||
// ): ApiResult<AuthDirectResponse, OAuthErrorDomain> {
|
||||
//
|
||||
// }
|
||||
|
||||
// TODO: 05/05/2024, Danil Nikolaev: implement
|
||||
override suspend fun sendSms(
|
||||
override suspend fun validatePhone(
|
||||
validationSid: String
|
||||
): SendSmsResponse = withContext(Dispatchers.IO) {
|
||||
SendSmsResponse(
|
||||
validationSid = null, delay = null, validationType = null, validationResend = null
|
||||
|
||||
)
|
||||
// authService.sendSms(validationSid).mapResult(
|
||||
// successMapper = { response -> response.requireResponse() },
|
||||
// errorMapper = { error -> error?.toDomain() }
|
||||
// )
|
||||
): ApiResult<ValidatePhoneResponse, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||
service.validatePhone(validationSid).mapApiDefault()
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -6,7 +6,7 @@ import com.meloda.app.fast.model.api.requests.LongPollGetUpdatesRequest
|
||||
import com.meloda.app.fast.model.api.requests.MessagesGetLongPollServerRequest
|
||||
import com.meloda.app.fast.network.RestApiErrorDomain
|
||||
import com.meloda.app.fast.network.mapApiResult
|
||||
import com.meloda.app.fast.network.mapResult
|
||||
import com.meloda.app.fast.network.mapDefault
|
||||
import com.meloda.app.fast.network.service.longpoll.LongPollService
|
||||
import com.meloda.app.fast.network.service.messages.MessagesService
|
||||
import com.slack.eithernet.ApiResult
|
||||
@@ -49,9 +49,7 @@ class LongPollRepositoryImpl(
|
||||
mode = mode,
|
||||
version = version
|
||||
)
|
||||
longPollService.getResponse(serverUrl, requestModel.map).mapResult(
|
||||
successMapper = { response -> response },
|
||||
errorMapper = { error -> error?.toDomain() }
|
||||
)
|
||||
|
||||
longPollService.getResponse(serverUrl, requestModel.map).mapDefault()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user