TokenResponse rework
This commit is contained in:
@@ -28,7 +28,9 @@ data class TokenResponseDto(
|
||||
*/
|
||||
fun TokenResponseDto.toDomain(): TokenResponse {
|
||||
return TokenResponse(
|
||||
token = this.token
|
||||
token = this.token,
|
||||
attachmentToken = this.attachmentToken,
|
||||
expiresAt = this.expiresAt
|
||||
)
|
||||
}
|
||||
// [END_ENTITY: Function('toDomain')]
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
|
||||
package com.homebox.lens.data.api.model
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
// [IMPORTS]
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.homebox.lens.domain.model.LocationOut as DomainLocationOut
|
||||
import com.homebox.lens.domain.model.LocationOutCount as DomainLocationOutCount
|
||||
import com.homebox.lens.domain.model.MaintenanceEntry as DomainMaintenanceEntry
|
||||
import com.homebox.lens.domain.model.PaginationResult as DomainPaginationResult
|
||||
import com.homebox.lens.domain.model.TokenResponse as DomainTokenResponse
|
||||
// [END_IMPORTS]
|
||||
|
||||
// [ENTITY: Function('ItemOutDto.toDomain')]
|
||||
@@ -265,4 +266,5 @@ fun LabelSummaryDto.toDomain(): DomainLabelSummary {
|
||||
}
|
||||
// [END_ENTITY: Function('LabelSummaryDto.toDomain')]
|
||||
|
||||
|
||||
// [END_FILE_DtoToDomain.kt]
|
||||
@@ -8,8 +8,9 @@ package com.homebox.lens.data.repository
|
||||
import android.content.SharedPreferences
|
||||
import com.homebox.lens.data.api.HomeboxApiService
|
||||
import com.homebox.lens.data.api.dto.LoginFormDto
|
||||
import com.homebox.lens.data.api.mapper.toDomain
|
||||
import com.homebox.lens.data.api.dto.toDomain
|
||||
import com.homebox.lens.domain.model.Credentials
|
||||
import com.homebox.lens.domain.model.Result
|
||||
import com.homebox.lens.domain.model.TokenResponse
|
||||
import com.homebox.lens.domain.repository.AuthRepository
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -56,7 +57,7 @@ class AuthRepositoryImpl @Inject constructor(
|
||||
require(credentials.serverUrl.isNotBlank()) { "Server URL cannot be blank." }
|
||||
|
||||
return withContext(Dispatchers.IO) {
|
||||
runCatching {
|
||||
try {
|
||||
Timber.d("[DEBUG][ACTION][creating_retrofit_client] Creating temporary Retrofit client for URL: ${credentials.serverUrl}")
|
||||
val tempApiService = Retrofit.Builder()
|
||||
.baseUrl(credentials.serverUrl)
|
||||
@@ -70,7 +71,10 @@ class AuthRepositoryImpl @Inject constructor(
|
||||
val tokenResponseDto = tempApiService.login(loginForm)
|
||||
|
||||
Timber.d("[DEBUG][ACTION][mapping_to_domain] Mapping token response to domain model.")
|
||||
tokenResponseDto.toDomain()
|
||||
Result.Success(tokenResponseDto.toDomain())
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "[ERROR][FAILURE][login_failed] Login failed.")
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user