TokenResponse rework

This commit is contained in:
2025-10-05 14:46:02 +03:00
parent 556b7f7c7d
commit 9286e041da
12 changed files with 32 additions and 167 deletions

View File

@@ -8,9 +8,15 @@ package com.homebox.lens.domain.model
/**
* @summary Data model representing a response from the server with an authentication token.
* @param token A string containing a JWT or other access token.
* @param attachmentToken A token for accessing attachments.
* @param expiresAt The expiration date of the token.
* @invariant `token` must not be blank.
*/
data class TokenResponse(val token: String) {
data class TokenResponse(
val token: String,
val attachmentToken: String,
val expiresAt: String
) {
init {
require(token.isNotBlank()) { "Token cannot be blank." }
}

View File

@@ -31,17 +31,19 @@ class LoginUseCase @Inject constructor(
"Server URL and username must not be blank."
}
val loginResult: com.homebox.lens.domain.model.Result<TokenResponse> = authRepository.login(credentials)
return loginResult.fold(
onSuccess = {
authRepository.saveToken(it.token)
com.homebox.lens.domain.model.Result.Success(Unit)
},
onFailure = {
com.homebox.lens.domain.model.Result.Error(it as Exception)
return try {
when (val loginResult = authRepository.login(credentials)) {
is com.homebox.lens.domain.model.Result.Success -> {
authRepository.saveToken(loginResult.data.token)
Result.success(Unit)
}
is com.homebox.lens.domain.model.Result.Error -> {
Result.failure(loginResult.exception)
}
}
)
} catch (e: Exception) {
Result.failure(e)
}
}
// [END_ENTITY: Function('invoke')]
}