-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature/fix-dependencies] 뷰모델/도메인단 코드 리팩토링 (#394)
* remove services in authrepository * remove datastore dependency in authrepository * firebase token 가져오는 로직 suspend 하게 변경 * mypage viewmodel에서 repository만 참조하게 변경
- Loading branch information
Showing
11 changed files
with
138 additions
and
49 deletions.
There are no files selected for viewing
30 changes: 13 additions & 17 deletions
30
app/src/main/java/org/sopt/official/data/repository/AuthRepositoryImpl.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,51 +1,47 @@ | ||
package org.sopt.official.data.repository | ||
|
||
import org.sopt.official.common.di.Auth | ||
import org.sopt.official.data.model.request.LogOutRequest | ||
import org.sopt.official.data.model.request.RefreshRequest | ||
import org.sopt.official.data.model.response.LogOutResponse | ||
import org.sopt.official.data.persistence.SoptDataStore | ||
import org.sopt.official.data.service.AuthService | ||
import org.sopt.official.data.source.api.auth.LocalAuthDataSource | ||
import org.sopt.official.data.source.api.auth.RemoteAuthDataSource | ||
import org.sopt.official.domain.entity.auth.Token | ||
import org.sopt.official.domain.entity.auth.UserStatus | ||
import org.sopt.official.domain.repository.AuthRepository | ||
import javax.inject.Inject | ||
|
||
class AuthRepositoryImpl @Inject constructor( | ||
@Auth private val service: AuthService, | ||
@Auth(false) private val noneAuthService: AuthService, | ||
private val dataStore: SoptDataStore | ||
private val remoteAuthDataSource: RemoteAuthDataSource, | ||
private val localAuthDataSource: LocalAuthDataSource, | ||
) : AuthRepository { | ||
override suspend fun refresh(token: String) = runCatching { | ||
noneAuthService.refresh(RefreshRequest(token)).toEntity() | ||
remoteAuthDataSource.refresh(RefreshRequest(token)).toEntity() | ||
} | ||
|
||
override fun save(token: Token) { | ||
dataStore.apply { | ||
accessToken = token.accessToken | ||
refreshToken = token.refreshToken | ||
playgroundToken = token.playgroundToken | ||
} | ||
localAuthDataSource.save(token) | ||
} | ||
|
||
override fun save(status: UserStatus) { | ||
dataStore.apply { | ||
userStatus = status.value | ||
} | ||
localAuthDataSource.save(status) | ||
} | ||
|
||
override suspend fun withdraw() = runCatching { | ||
service.withdraw() | ||
remoteAuthDataSource.withdraw() | ||
} | ||
|
||
override suspend fun logout( | ||
pushToken: String | ||
): Result<LogOutResponse> = runCatching { | ||
service.logOut( | ||
remoteAuthDataSource.logout( | ||
LogOutRequest( | ||
platform = "Android", | ||
pushToken = pushToken | ||
) | ||
) | ||
} | ||
|
||
override suspend fun clearLocalData() { | ||
localAuthDataSource.clear() | ||
} | ||
} |
Empty file.
10 changes: 10 additions & 0 deletions
10
app/src/main/java/org/sopt/official/data/source/api/auth/LocalAuthDataSource.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,10 @@ | ||
package org.sopt.official.data.source.api.auth | ||
|
||
import org.sopt.official.domain.entity.auth.Token | ||
import org.sopt.official.domain.entity.auth.UserStatus | ||
|
||
interface LocalAuthDataSource { | ||
fun save(token: Token) | ||
fun save(status: UserStatus) | ||
fun clear() | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/org/sopt/official/data/source/api/auth/RemoteAuthDataSource.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 org.sopt.official.data.source.api.auth | ||
|
||
import org.sopt.official.data.model.request.LogOutRequest | ||
import org.sopt.official.data.model.request.RefreshRequest | ||
import org.sopt.official.data.model.response.AuthResponse | ||
import org.sopt.official.data.model.response.LogOutResponse | ||
|
||
interface RemoteAuthDataSource { | ||
suspend fun refresh(token: RefreshRequest): AuthResponse | ||
suspend fun withdraw() | ||
suspend fun logout(request: LogOutRequest): LogOutResponse | ||
} |
Empty file.
29 changes: 29 additions & 0 deletions
29
app/src/main/java/org/sopt/official/data/source/impl/DefaultLocalAuthDataSource.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,29 @@ | ||
package org.sopt.official.data.source.impl | ||
|
||
import org.sopt.official.data.persistence.SoptDataStore | ||
import org.sopt.official.data.source.api.auth.LocalAuthDataSource | ||
import org.sopt.official.domain.entity.auth.Token | ||
import org.sopt.official.domain.entity.auth.UserStatus | ||
import javax.inject.Inject | ||
|
||
class DefaultLocalAuthDataSource @Inject constructor( | ||
private val dataStore: SoptDataStore | ||
) : LocalAuthDataSource { | ||
override fun save(token: Token) { | ||
dataStore.apply { | ||
accessToken = token.accessToken | ||
refreshToken = token.refreshToken | ||
playgroundToken = token.playgroundToken | ||
} | ||
} | ||
|
||
override fun save(status: UserStatus) { | ||
dataStore.apply { | ||
userStatus = status.value | ||
} | ||
} | ||
|
||
override fun clear() { | ||
dataStore.clear() | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/org/sopt/official/data/source/impl/DefaultRemoteAuthDataSource.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,27 @@ | ||
package org.sopt.official.data.source.impl | ||
|
||
import org.sopt.official.common.di.Auth | ||
import org.sopt.official.data.model.request.LogOutRequest | ||
import org.sopt.official.data.model.request.RefreshRequest | ||
import org.sopt.official.data.model.response.AuthResponse | ||
import org.sopt.official.data.model.response.LogOutResponse | ||
import org.sopt.official.data.service.AuthService | ||
import org.sopt.official.data.source.api.auth.RemoteAuthDataSource | ||
import javax.inject.Inject | ||
|
||
class DefaultRemoteAuthDataSource @Inject constructor( | ||
@Auth private val service: AuthService, | ||
@Auth(false) private val noneAuthService: AuthService, | ||
) : RemoteAuthDataSource { | ||
override suspend fun refresh(token: RefreshRequest): AuthResponse { | ||
return noneAuthService.refresh(token) | ||
} | ||
|
||
override suspend fun withdraw() { | ||
service.withdraw() | ||
} | ||
|
||
override suspend fun logout(request: LogOutRequest): LogOutResponse { | ||
return service.logOut(request) | ||
} | ||
} |
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