Skip to content

Commit

Permalink
πŸ”— :: (#384) μ„œλ²„ 점검 λͺ¨λ‹¬ μ•ˆ 뜸
Browse files Browse the repository at this point in the history
  • Loading branch information
parkuiery authored Oct 15, 2024
2 parents 67f1742 + 4b323b0 commit 652499a
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ data object NotFoundException : RuntimeException()
data object MethodNotAllowedException : RuntimeException()
data object ConflictException : RuntimeException()
data object TooManyRequestException : RuntimeException()
data object CheckServerException : RuntimeException()
data object ServerException : RuntimeException()
data object OfflineException : RuntimeException()
data object ConnectionTimeOutException : RuntimeException()
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import team.retum.data.repository.ServerStatusCheckRepository
import team.retum.data.repository.ServerStatusCheckRepositoryImpl
import team.retum.data.repository.application.ApplicationRepository
import team.retum.data.repository.application.ApplicationRepositoryImpl
import team.retum.data.repository.auth.AuthRepository
Expand Down Expand Up @@ -98,4 +100,8 @@ abstract class RepositoryModule {
@Binds
@Singleton
abstract fun bindWinterInternRepository(winterInternRepositoryImpl: WinterInternRepositoryImpl): WinterInterRepository

@Binds
@Singleton
abstract fun bindServerStatusCheckRepository(serverStatusCheckRepositoryImpl: ServerStatusCheckRepositoryImpl): ServerStatusCheckRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package team.retum.data.repository

interface ServerStatusCheckRepository {
suspend fun serverStatusCheck()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package team.retum.data.repository

import team.retum.network.datasource.RemoteServerStatusCheckDataSource
import javax.inject.Inject

class ServerStatusCheckRepositoryImpl @Inject constructor(
private val remoteServerStatusCheckDataSource: RemoteServerStatusCheckDataSource,
) : ServerStatusCheckRepository {
override suspend fun serverStatusCheck() {
remoteServerStatusCheckDataSource.serverStatusCheck()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package team.retum.usecase.usecase

import team.retum.data.repository.ServerStatusCheckRepository
import javax.inject.Inject

class ServerStatusCheckUseCase @Inject constructor(
private val serverStatusCheckRepository: ServerStatusCheckRepository,
) {
suspend operator fun invoke() = runCatching {
serverStatusCheckRepository.serverStatusCheck()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package team.retum.network.api

import retrofit2.http.GET
import team.retum.network.di.RequestUrls

interface ServerStatusCheckApi {
@GET(RequestUrls.CheckServerStatus.checkServerStatus)
suspend fun serverStatusCheck()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package team.retum.network.datasource

interface RemoteServerStatusCheckDataSource {
suspend fun serverStatusCheck()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package team.retum.network.datasource

import team.retum.network.api.ServerStatusCheckApi
import team.retum.network.util.RequestHandler
import javax.inject.Inject

class RemoteServerStatusCheckDataSourceImpl @Inject constructor(
private val serverStatusCheckApi: ServerStatusCheckApi,
) : RemoteServerStatusCheckDataSource {
override suspend fun serverStatusCheck() {
RequestHandler<Unit>().request {
serverStatusCheckApi.serverStatusCheck()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import team.retum.network.api.NoticeApi
import team.retum.network.api.NotificationApi
import team.retum.network.api.RecruitmentApi
import team.retum.network.api.ReviewApi
import team.retum.network.api.ServerStatusCheckApi
import team.retum.network.api.StudentApi
import team.retum.network.api.UserApi
import team.retum.network.api.WinterInternApi
Expand Down Expand Up @@ -177,4 +178,10 @@ object NetworkModule {
fun provideWinterInternApi(retrofit: Retrofit): WinterInternApi {
return retrofit.create(WinterInternApi::class.java)
}

@Provides
@Singleton
fun provideServerStatusCheckApi(retrofit: Retrofit): ServerStatusCheckApi {
return retrofit.create(ServerStatusCheckApi::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import team.retum.network.datasource.RemoteServerStatusCheckDataSource
import team.retum.network.datasource.RemoteServerStatusCheckDataSourceImpl
import team.retum.network.datasource.application.RemoteApplicationDataSource
import team.retum.network.datasource.application.RemoteApplicationDataSourceImpl
import team.retum.network.datasource.auth.RemoteAuthDataSource
Expand Down Expand Up @@ -98,4 +100,8 @@ abstract class RemoteDataSourceModule {
@Binds
@Singleton
abstract fun bindWinterInternDataSource(winterInternDataSourceImpl: WinterInternDataSourceImpl): WinterInternDataSource

@Binds
@Singleton
abstract fun bindServerStatusCheckDataSource(serverStatusCheckDataSourceImpl: RemoteServerStatusCheckDataSourceImpl): RemoteServerStatusCheckDataSource
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,10 @@ internal object RequestUrls {

const val winterIntern = path
}

data object CheckServerStatus {
private const val path = "/"

const val checkServerStatus = path
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package team.retum.network.util

import retrofit2.HttpException
import team.retum.common.exception.BadRequestException
import team.retum.common.exception.CheckServerException
import team.retum.common.exception.ConflictException
import team.retum.common.exception.ConnectionTimeOutException
import team.retum.common.exception.ForbiddenException
Expand Down Expand Up @@ -56,7 +55,6 @@ class RequestHandler<T> {
405 -> MethodNotAllowedException
409 -> ConflictException
429 -> TooManyRequestException
502 -> CheckServerException
in 500..599 -> ServerException
else -> e
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class TokenInterceptor @Inject constructor(
RequestUrls.Files.delete,
RequestUrls.Files.post,
RequestUrls.Files.presignedUrl,
RequestUrls.CheckServerStatus.checkServerStatus,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ internal fun Splash(

LaunchedEffect(Unit) {
with(splashViewModel) {
getAccessToken()
splashViewModel.sideEffect.collect {
checkServerStatus()
sideEffect.collect {
when (it) {
is SplashSideEffect.MoveToLanding -> {
navigateToLanding()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import team.retum.common.base.BaseViewModel
import team.retum.common.exception.CheckServerException
import team.retum.common.exception.ConnectionTimeOutException
import team.retum.common.exception.NotFoundException
import team.retum.common.exception.OfflineException
import team.retum.common.exception.ServerException
import team.retum.usecase.usecase.ServerStatusCheckUseCase
import team.retum.usecase.usecase.auth.ReissueTokenUseCase
import team.retum.usecase.usecase.user.GetAccessTokenUseCase
import team.retum.usecase.usecase.user.GetRefreshExpiresAtUseCase
Expand All @@ -22,9 +23,24 @@ internal class SplashViewModel @Inject constructor(
private val getRefreshExpiresAtUseCase: GetRefreshExpiresAtUseCase,
private val getRefreshTokenUseCase: GetRefreshTokenUseCase,
private val reissueTokenUseCase: ReissueTokenUseCase,
private val serverStatusCheckUseCase: ServerStatusCheckUseCase,
) : BaseViewModel<SplashState, SplashSideEffect>(SplashState.getInitialState()) {

internal fun getAccessToken() {
internal fun checkServerStatus() {
viewModelScope.launch(Dispatchers.IO) {
serverStatusCheckUseCase().onSuccess {
getAccessToken()
}.onFailure {
when (it) {
is ServerException -> {
postSideEffect(SplashSideEffect.ShowCheckServerDialog)
}
}
}
}
}

private fun getAccessToken() {
viewModelScope.launch(Dispatchers.IO) {
getAccessTokenUseCase().onSuccess {
if (it.isBlank()) {
Expand All @@ -37,10 +53,6 @@ internal class SplashViewModel @Inject constructor(
is NullPointerException -> {
postSideEffect(SplashSideEffect.MoveToLanding)
}

is CheckServerException -> {
postSideEffect(SplashSideEffect.ShowCheckServerDialog)
}
}
}
}
Expand Down

0 comments on commit 652499a

Please sign in to comment.