Fix: Handle missing 'color', 'isArchived' and 'value' fields in DTOs and mappers to prevent JsonDataException
This commit is contained in:
@@ -21,7 +21,7 @@ sealed class Result<out T> {
|
||||
* @summary Представляет собой неуспешный результат операции.
|
||||
* @param exception Исключение, которое произошло во время операции.
|
||||
*/
|
||||
data class Error(val exception: Exception) : Result<Nothing>()
|
||||
data class Error(val exception: kotlin.Exception) : Result<Nothing>()
|
||||
// [END_ENTITY: DataClass('Error')]
|
||||
}
|
||||
// [END_ENTITY: SealedClass('Result')]
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// [FILE] ResultExtensions.kt
|
||||
// [SEMANTICS] domain, model, result, extensions
|
||||
package com.homebox.lens.domain.model
|
||||
|
||||
// [ENTITY: Function('fold')]
|
||||
/**
|
||||
* @summary Extension function to handle success and failure cases of a Result.
|
||||
* @param onSuccess The function to be called if the Result is Success.
|
||||
* @param onFailure The function to be called if the Result is Error.
|
||||
* @return The result of either onSuccess or onFailure.
|
||||
* @param R The return type of the fold operation.
|
||||
*/
|
||||
inline fun <T, R> Result<T>.fold(
|
||||
onSuccess: (value: T) -> R,
|
||||
onFailure: (exception: Exception) -> R
|
||||
): R {
|
||||
return when (this) {
|
||||
is Result.Success -> onSuccess(data)
|
||||
is Result.Error -> onFailure(exception)
|
||||
}
|
||||
}
|
||||
// [END_ENTITY: Function('fold')]
|
||||
// [END_FILE_ResultExtensions.kt]
|
||||
@@ -6,6 +6,7 @@ package com.homebox.lens.domain.usecase
|
||||
// [IMPORTS]
|
||||
import com.homebox.lens.domain.model.ItemSummary
|
||||
import com.homebox.lens.domain.model.PaginationResult
|
||||
import com.homebox.lens.domain.model.Result
|
||||
import com.homebox.lens.domain.repository.ItemRepository
|
||||
import javax.inject.Inject
|
||||
// [END_IMPORTS]
|
||||
@@ -23,10 +24,14 @@ class SearchItemsUseCase @Inject constructor(
|
||||
/**
|
||||
* @summary Executes the search operation.
|
||||
* @param query The search query.
|
||||
* @return A pagination result object.
|
||||
* @return A Result object encapsulating either a successful PaginationResult or an Error.
|
||||
*/
|
||||
suspend operator fun invoke(query: String): PaginationResult<ItemSummary> {
|
||||
return itemRepository.searchItems(query)
|
||||
suspend operator fun invoke(query: String): Result<PaginationResult<ItemSummary>> {
|
||||
return try {
|
||||
Result.Success(itemRepository.searchItems(query))
|
||||
} catch (e: Exception) {
|
||||
Result.Error(e)
|
||||
}
|
||||
}
|
||||
// [END_ENTITY: Function('invoke')]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user