diff --git a/app/src/main/java/com/sopt/now/test/data/repository/UserProfileRepository.kt b/app/src/main/java/com/sopt/now/test/data/repository/UserProfileRepository.kt new file mode 100644 index 0000000..c55856f --- /dev/null +++ b/app/src/main/java/com/sopt/now/test/data/repository/UserProfileRepository.kt @@ -0,0 +1,32 @@ +package com.sopt.now.test.data.repository + +import com.sopt.now.test.core.view.UiState +import com.sopt.now.test.data.ServicePool +import com.sopt.now.test.data.dto.response.ResponseFriendDto +import com.sopt.now.test.data.dto.response.ResponseUserInfoDto +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +class UserProfileRepository { + suspend fun getUserProfile(): UiState { + return withContext(Dispatchers.IO) { + runCatching { + ServicePool.userService.getUserInfo() + }.fold( + { UiState.Success(it) }, + { UiState.Failure(it.message.toString()) } + ) + } + } + + suspend fun getFriendProfile(): UiState { + return withContext(Dispatchers.IO) { + runCatching { + ServicePool.friendService.getFriendInfo(1) + }.fold( + { UiState.Success(it) }, + { UiState.Failure(it.message.toString()) } + ) + } + } +} \ No newline at end of file