Skip to content

Commit 44beac5

Browse files
committed
[IDLE-000] 불필요한 컨텍스트 스위칭 제거 및 로그인, 회원가입 시 로컬에 케싱하도록 변경
1 parent 193a6cc commit 44beac5

File tree

6 files changed

+48
-27
lines changed

6 files changed

+48
-27
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
.gradle
33
/local.properties
44
/.idea/
5-
.DS_Store
5+
**/.idea/
6+
**/.DS_Store
67
/build
8+
**/build/
79
/captures
810
.externalNativeBuild
911
.cxx
1012
local.properties
1113
keystore.properties
1214
/.kotlin/
1315
/app/upload-keystore.jks
14-
/keystore.properties
16+
/keystore.properties

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ plugins {
77
alias(libs.plugins.ksp) apply false
88
alias(libs.plugins.compose.compiler) apply false
99
alias(libs.plugins.android.test) apply false
10-
alias(libs.plugins.google.services) apply false
1110
alias(libs.plugins.ktlint)
1211
alias(libs.plugins.android.library) apply false
1312
alias(libs.plugins.androidx.navigation.safeargs) apply false
13+
alias(libs.plugins.google.services) apply false
1414
alias(libs.plugins.firebase.crashlytics) apply false
1515
}

core/data/src/main/java/com/idle/data/repository/auth/AuthRepositoryImpl.kt

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.idle.domain.model.auth.BusinessRegistrationInfo
66
import com.idle.domain.model.auth.UserType
77
import com.idle.domain.repositorry.auth.AuthRepository
88
import com.idle.domain.repositorry.auth.TokenRepository
9+
import com.idle.domain.repositorry.profile.ProfileRepository
910
import com.idle.network.model.auth.ConfirmAuthCodeRequest
1011
import com.idle.network.model.auth.GenerateNewPasswordRequest
1112
import com.idle.network.model.auth.SendPhoneRequest
@@ -17,12 +18,12 @@ import com.idle.network.model.auth.WithdrawalCenterRequest
1718
import com.idle.network.model.auth.WithdrawalWorkerRequest
1819
import com.idle.network.model.token.TokenResponse
1920
import com.idle.network.source.auth.AuthDataSource
20-
import kotlinx.coroutines.Dispatchers
21+
import kotlinx.coroutines.coroutineScope
2122
import kotlinx.coroutines.launch
22-
import kotlinx.coroutines.withContext
2323
import javax.inject.Inject
2424

2525
class AuthRepositoryImpl @Inject constructor(
26+
private val profileRepository: ProfileRepository,
2627
private val authDataSource: AuthDataSource,
2728
private val tokenDataSource: TokenDataSource,
2829
private val userInfoDataSource: UserInfoDataSource,
@@ -62,8 +63,16 @@ class AuthRepositoryImpl @Inject constructor(
6263
SignInCenterRequest(identifier = identifier, password = password)
6364
).fold(
6465
onSuccess = { tokenResponse ->
65-
handleSignInSuccess(tokenResponse, UserType.CENTER.apiValue)
66-
Result.success(Unit)
66+
coroutineScope {
67+
handleSignInSuccess(tokenResponse, UserType.CENTER.apiValue)
68+
69+
val profile = profileRepository.getMyCenterProfile().getOrNull()
70+
if (profile != null) {
71+
userInfoDataSource.setUserInfo(profile.toString())
72+
}
73+
74+
Result.success(Unit)
75+
}
6776
},
6877
onFailure = { Result.failure(it) }
6978
)
@@ -95,8 +104,16 @@ class AuthRepositoryImpl @Inject constructor(
95104
)
96105
).fold(
97106
onSuccess = { tokenResponse ->
98-
handleSignInSuccess(tokenResponse, UserType.WORKER.apiValue)
99-
Result.success(Unit)
107+
coroutineScope {
108+
handleSignInSuccess(tokenResponse, UserType.WORKER.apiValue)
109+
110+
val profile = profileRepository.getMyWorkerProfile().getOrNull()
111+
if (profile != null) {
112+
userInfoDataSource.setUserInfo(profile.toString())
113+
}
114+
115+
Result.success(Unit)
116+
}
100117
},
101118
onFailure = { Result.failure(it) }
102119
)
@@ -108,8 +125,16 @@ class AuthRepositoryImpl @Inject constructor(
108125
SignInWorkerRequest(phoneNumber = phoneNumber, authCode = authCode)
109126
).fold(
110127
onSuccess = { tokenResponse ->
111-
handleSignInSuccess(tokenResponse, UserType.WORKER.apiValue)
112-
Result.success(Unit)
128+
coroutineScope {
129+
handleSignInSuccess(tokenResponse, UserType.WORKER.apiValue)
130+
131+
val updatedProfile = profileRepository.getMyWorkerProfile().getOrNull()
132+
if (updatedProfile != null) {
133+
userInfoDataSource.setUserInfo(updatedProfile.toString())
134+
}
135+
136+
Result.success(Unit)
137+
}
113138
},
114139
onFailure = { Result.failure(it) }
115140
)
@@ -159,7 +184,7 @@ class AuthRepositoryImpl @Inject constructor(
159184
private suspend fun handleSignInSuccess(
160185
tokenResponse: TokenResponse,
161186
userType: String,
162-
) = withContext(Dispatchers.IO) {
187+
) = coroutineScope {
163188
launch { tokenDataSource.setRefreshToken(tokenResponse.refreshToken) }
164189
launch { userInfoDataSource.setUserType(userType) }
165190
launch { tokenDataSource.setAccessToken(tokenResponse.accessToken) }.join()
@@ -168,7 +193,7 @@ class AuthRepositoryImpl @Inject constructor(
168193
tokenRepository.postDeviceToken(deviceToken, userType = userType)
169194
}
170195

171-
private suspend fun clearUserData() = withContext(Dispatchers.IO) {
196+
private suspend fun clearUserData() = coroutineScope {
172197
launch { userInfoDataSource.clearUserType() }
173198
launch { userInfoDataSource.clearUserInfo() }
174199
tokenDataSource.clearToken()

core/data/src/main/java/com/idle/data/repository/profile/ProfileRepositoryImpl.kt

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ import com.idle.network.model.profile.UpdateWorkerProfileRequest
2222
import com.idle.network.model.profile.UploadProfileImageUrlResponse
2323
import com.idle.network.source.profile.ProfileDataSource
2424
import dagger.hilt.android.qualifiers.ApplicationContext
25-
import kotlinx.coroutines.Dispatchers
2625
import kotlinx.coroutines.flow.first
27-
import kotlinx.coroutines.withContext
2826
import java.io.ByteArrayInputStream
2927
import java.io.ByteArrayOutputStream
3028
import java.io.InputStream
@@ -35,9 +33,7 @@ class ProfileRepositoryImpl @Inject constructor(
3533
private val userInfoDataSource: UserInfoDataSource,
3634
@ApplicationContext private val context: Context,
3735
) : ProfileRepository {
38-
override suspend fun getMyUserType() = withContext(Dispatchers.IO) {
39-
userInfoDataSource.userType.first()
40-
}
36+
override suspend fun getMyUserType() = userInfoDataSource.userType.first()
4137

4238
override suspend fun getMyCenterProfile(): Result<CenterProfile> =
4339
profileDataSource.getMyCenterProfile()
@@ -48,10 +44,8 @@ class ProfileRepositoryImpl @Inject constructor(
4844
}
4945

5046
override suspend fun getLocalMyCenterProfile(): Result<CenterProfile> = runCatching {
51-
val userInfoString = withContext(Dispatchers.IO) {
52-
userInfoDataSource.userInfo.first()
53-
.takeIf { it.isNotBlank() } ?: throw IllegalArgumentException("Missing UserInfo")
54-
}
47+
val userInfoString = userInfoDataSource.userInfo.first()
48+
.takeIf { it.isNotBlank() } ?: throw IllegalArgumentException("Missing UserInfo")
5549

5650
val properties = userInfoString.removePrefix("CenterProfile(").removeSuffix(")")
5751
.split(", ")
@@ -91,10 +85,8 @@ class ProfileRepositoryImpl @Inject constructor(
9185
}
9286

9387
override suspend fun getLocalMyWorkerProfile(): Result<WorkerProfile> = runCatching {
94-
val userInfoString = withContext(Dispatchers.IO) {
95-
userInfoDataSource.userInfo.first()
96-
.takeIf { it.isNotBlank() } ?: throw IllegalArgumentException("Missing UserInfo")
97-
}
88+
val userInfoString = userInfoDataSource.userInfo.first()
89+
.takeIf { it.isNotBlank() } ?: throw IllegalArgumentException("Missing UserInfo")
9890

9991
val properties = userInfoString.removePrefix("WorkerProfile(").removeSuffix(")")
10092
.split(", ")
@@ -330,4 +322,4 @@ class ProfileRepositoryImpl @Inject constructor(
330322
imageFileExtension = imageFileExtension,
331323
)
332324
)
333-
}
325+
}

core/network/src/main/java/com/idle/network/model/jobposting/GetJobPostingsResponse.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ data class WorkerJobPostingResponse(
4949
applyDeadline = LocalDate.parse(applyDeadline, DateTimeFormatter.ofPattern("yyyy-MM-dd")),
5050
applyDeadlineType = ApplyDeadlineType.create(applyDeadlineType),
5151
careLevel = careLevel,
52+
centerId = centerId,
5253
distance = distance,
5354
endTime = endTime,
5455
gender = Gender.create(gender),

presentation/src/main/java/com/idle/presentation/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.Manifest
44
import android.animation.Animator
55
import android.animation.ValueAnimator
66
import android.content.ActivityNotFoundException
7+
import android.content.Context
78
import android.content.Intent
89
import android.content.pm.PackageManager
910
import android.net.Uri

0 commit comments

Comments
 (0)