From 7bd80bd9db9a5a2e4397665dacfc7e51f0d899ec Mon Sep 17 00:00:00 2001 From: youjin09222 Date: Fri, 7 Jun 2024 17:44:33 +0900 Subject: [PATCH] =?UTF-8?q?FEAT/#17:=20UserProfileRepository=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/repository/UserProfileRepository.kt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 app/src/main/java/com/sopt/now/test/data/repository/UserProfileRepository.kt 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