-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
10 changed files
with
92 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 6 additions & 8 deletions
14
.../festago/app/src/main/java/com/festago/festago/data/repository/SchoolDefaultRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 5 additions & 6 deletions
11
...id/festago/app/src/main/java/com/festago/festago/data/repository/UserDefaultRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
package com.festago.festago.data.repository | ||
|
||
import com.festago.festago.data.service.UserRetrofitService | ||
import com.festago.festago.data.util.runCatchingWithErrorHandler | ||
import com.festago.festago.data.util.onSuccessOrCatch | ||
import com.festago.festago.data.util.runCatchingResponse | ||
import com.festago.festago.model.UserProfile | ||
import com.festago.festago.repository.UserRepository | ||
import javax.inject.Inject | ||
|
||
class UserDefaultRepository @Inject constructor( | ||
private val userProfileService: UserRetrofitService, | ||
) : UserRepository { | ||
override suspend fun loadUserProfile(): Result<UserProfile> { | ||
userProfileService.getUserProfile().runCatchingWithErrorHandler() | ||
.getOrElse { error -> return Result.failure(error) } | ||
.let { return Result.success(it.toDomain()) } | ||
} | ||
override suspend fun loadUserProfile(): Result<UserProfile> = | ||
runCatchingResponse { userProfileService.getUserProfile() } | ||
.onSuccessOrCatch { it.toDomain() } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
android/festago/app/src/main/java/com/festago/festago/data/util/ResultExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.festago.festago.data.util | ||
|
||
suspend fun <T, R> Result<T>.onSuccessOrCatch(block: suspend (T) -> R): Result<R> { | ||
return try { | ||
onSuccess { return Result.success(block(it)) } | ||
onFailure { return Result.failure(it) } | ||
|
||
throw Throwable("This line should not be reached") | ||
} catch (e: Exception) { | ||
Result.failure(e) | ||
} | ||
} |