Skip to content

Commit

Permalink
Refactor/#416 core network (#423)
Browse files Browse the repository at this point in the history
* [ADD]: init core module #416

* [ADD]: core network logic #416

* [ADD]: core network logic data store #416

* [REFACTOR]: app 로직 수정 #416

* [ADD]: flipper release/debug set #416

* [DELETE]: Delete Network File #416
cause Move Core Net

* [CHORE]: Code Formating #416

* [FEAT]: Intent Provider #416
core network need Intent(auth activity)

* [REFACTOR]: Naming & Navigator #416
core/network AuthService -> RefreshService
Navigator 분리

* [DELETE]: 불필요 파일 제거 #416
proguard-rules.pro , ExampleInstrumentedTest.kt
,ExampleUnitTest.kt

* [FEAT]: domain auth mapper #416

* [MOVE]: MOVE #416
OAuthToken,AuthResponse into core/network

* [CHORE]: Git Ignore #416

* [CHORE]: name set #416

* [Refactor]: service 구분 #416

* [Refactor]: @Auth Annotation 제거 #416

* [CHORE]: 변수 이름 수정 #416

* [CHORE]: 변수 이름 수정 #416

* [CHORE]: 변수 이름 수정 #416

* [CHORE]: 변수 이름 수정 #416

* Spotless Apply

* Fix runtime error

---------

Co-authored-by: HyunWoo Lee <[email protected]>
  • Loading branch information
lsakee and l2hyunwoo committed Nov 7, 2023
1 parent 36de603 commit fdcaff6
Show file tree
Hide file tree
Showing 40 changed files with 395 additions and 98 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ dependencies {
implementation(projects.data.soptamp)
implementation(projects.core.common)
implementation(projects.core.analytics)
implementation(projects.core.network)
implementation(projects.feature.auth)
implementation(libs.kotlin.coroutines.google.play)
implementation(platform(libs.compose.bom))
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/org/sopt/official/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import com.google.firebase.messaging.FirebaseMessaging
import dagger.hilt.android.HiltAndroidApp
import kotlinx.coroutines.launch
import kotlinx.coroutines.tasks.await
import org.sopt.official.data.persistence.SoptDataStore
import org.sopt.official.network.FlipperInitializer
import org.sopt.official.network.persistence.SoptDataStore
import timber.log.Timber
import javax.inject.Inject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import org.sopt.official.R
import org.sopt.official.data.persistence.SoptDataStore
import org.sopt.official.network.persistence.SoptDataStore
import org.sopt.official.domain.entity.auth.UserStatus
import org.sopt.official.domain.usecase.notification.RegisterPushTokenUseCase
import org.sopt.official.feature.auth.AuthActivity
Expand Down
41 changes: 41 additions & 0 deletions app/src/main/java/org/sopt/official/data/mapper/AuthMapper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* MIT License
* Copyright 2023 SOPT - Shout Our Passion Together
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.sopt.official.data.mapper

import org.sopt.official.domain.entity.auth.Auth
import org.sopt.official.domain.entity.auth.Token
import org.sopt.official.domain.entity.auth.UserStatus
import org.sopt.official.network.model.response.AuthResponse

class AuthMapper {
fun toEntity(responseItem:AuthResponse) = Auth(
Token(
accessToken = responseItem.accessToken,
refreshToken = responseItem.refreshToken,
playgroundToken = responseItem.playgroundToken
),
UserStatus.of(responseItem.status)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,23 @@
*/
package org.sopt.official.data.repository

import org.sopt.official.data.mapper.AuthMapper
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.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 org.sopt.official.network.model.request.RefreshRequest
import javax.inject.Inject

class AuthRepositoryImpl @Inject constructor(
private val remoteAuthDataSource: RemoteAuthDataSource,
private val localAuthDataSource: LocalAuthDataSource,
) : AuthRepository {
override suspend fun refresh(token: String) = runCatching {
remoteAuthDataSource.refresh(RefreshRequest(token)).toEntity()
AuthMapper().toEntity(remoteAuthDataSource.refresh(RefreshRequest(token)))
}

override fun save(token: Token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ package org.sopt.official.data.service

import org.sopt.official.data.model.request.AuthRequest
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.network.model.response.AuthResponse
import org.sopt.official.data.model.response.LogOutResponse
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.HTTP
import retrofit2.http.PATCH
import retrofit2.http.POST

interface AuthService {
Expand All @@ -41,11 +39,6 @@ interface AuthService {
@Body body: AuthRequest
): AuthResponse

@PATCH("auth/refresh")
suspend fun refresh(
@Body body: RefreshRequest
): AuthResponse

@DELETE("user")
suspend fun withdraw()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
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.network.model.response.AuthResponse
import org.sopt.official.data.model.response.LogOutResponse
import org.sopt.official.network.model.request.RefreshRequest

interface RemoteAuthDataSource {
suspend fun refresh(token: RefreshRequest): AuthResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
package org.sopt.official.data.source.impl

import org.sopt.official.data.persistence.SoptDataStore
import org.sopt.official.network.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,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.network.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 org.sopt.official.network.model.request.RefreshRequest
import org.sopt.official.network.service.RefreshService
import javax.inject.Inject

class DefaultRemoteAuthDataSource @Inject constructor(
@Auth private val service: AuthService,
@Auth(false) private val noneAuthService: AuthService,
@Auth private val authService: AuthService,
private val refreshService: RefreshService,
) : RemoteAuthDataSource {
override suspend fun refresh(token: RefreshRequest): AuthResponse {
return noneAuthService.refresh(token)
return refreshService.refresh(token)
}

override suspend fun withdraw() {
service.withdraw()
authService.withdraw()
}

override suspend fun logout(request: LogOutRequest): LogOutResponse {
return service.logOut(request)
return authService.logOut(request)
}
}
12 changes: 0 additions & 12 deletions app/src/main/java/org/sopt/official/di/AuthModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.Interceptor
import org.sopt.official.common.di.AppRetrofit
import org.sopt.official.common.di.Auth
import org.sopt.official.data.interceptor.AuthInterceptor
import org.sopt.official.data.repository.AuthRepositoryImpl
import org.sopt.official.data.service.AuthService
import org.sopt.official.data.source.api.auth.LocalAuthDataSource
Expand All @@ -51,23 +49,13 @@ object AuthModule {
@Auth
fun provideAuthService(@AppRetrofit retrofit: Retrofit): AuthService = retrofit.create(AuthService::class.java)

@Provides
@Singleton
@Auth(false)
fun provideNoneAuthService(@AppRetrofit(false) retrofit: Retrofit): AuthService = retrofit.create(AuthService::class.java)

@Module
@InstallIn(SingletonComponent::class)
interface Binder {
@Binds
@Singleton
fun bindAuthRepository(repository: AuthRepositoryImpl): AuthRepository

@Binds
@Singleton
@Auth
fun bindAuthInterceptor(interceptor: AuthInterceptor): Interceptor

@Binds
@Singleton
fun bindRemoteAuthDataSource(dataSource: DefaultRemoteAuthDataSource): RemoteAuthDataSource
Expand Down
41 changes: 41 additions & 0 deletions app/src/main/java/org/sopt/official/di/NavigatorModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* MIT License
* Copyright 2023 SOPT - Shout Our Passion Together
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.sopt.official.di

import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.sopt.official.common.navigator.NavigatorProvider
import org.sopt.official.feature.navigator.NavigatorProviderIntent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
interface NavigationModule {
@Binds
@Singleton
fun bindNavigatorIntent(navigatorProviderIntent: NavigatorProviderIntent): NavigatorProvider
}
10 changes: 5 additions & 5 deletions app/src/main/java/org/sopt/official/feature/auth/AuthActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
package org.sopt.official.feature.auth

import android.animation.ObjectAnimator
import android.content.Context
import android.content.Intent
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.content.Intent
import android.graphics.Paint
import android.os.Bundle
import android.view.animation.AnimationUtils
Expand All @@ -46,16 +46,16 @@ import org.sopt.official.BuildConfig
import org.sopt.official.R
import org.sopt.official.auth.PlaygroundAuth
import org.sopt.official.auth.data.PlaygroundAuthDatasource
import org.sopt.official.auth.data.remote.model.response.OAuthToken
import org.sopt.official.network.model.response.OAuthToken
import org.sopt.official.common.di.Auth
import org.sopt.official.config.messaging.SoptFirebaseMessagingService.Companion.REMOTE_MESSAGE_EVENT_LINK
import org.sopt.official.config.messaging.SoptFirebaseMessagingService.Companion.REMOTE_MESSAGE_EVENT_TYPE
import org.sopt.official.common.di.Auth
import org.sopt.official.data.model.request.AuthRequest
import org.sopt.official.data.persistence.SoptDataStore
import org.sopt.official.data.service.AuthService
import org.sopt.official.databinding.ActivityAuthBinding
import org.sopt.official.domain.entity.auth.UserStatus
import org.sopt.official.feature.home.HomeActivity
import org.sopt.official.network.persistence.SoptDataStore
import org.sopt.official.util.dp
import org.sopt.official.util.setOnAnimationEndListener
import org.sopt.official.util.setOnSingleClickListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ import org.sopt.official.util.setOnSingleClickListener
import org.sopt.official.util.stringOf
import org.sopt.official.util.ui.setVisible
import org.sopt.official.util.viewBinding
import javax.inject.Inject
import java.io.Serializable
import javax.inject.Inject

@AndroidEntryPoint
class HomeActivity : AppCompatActivity() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* MIT License
* Copyright 2023 SOPT - Shout Our Passion Together
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.sopt.official.feature.navigator

import android.content.Context
import android.content.Intent
import dagger.hilt.android.qualifiers.ApplicationContext
import org.sopt.official.common.navigator.NavigatorProvider
import org.sopt.official.feature.auth.AuthActivity
import javax.inject.Inject

class NavigatorProviderIntent @Inject constructor(
@ApplicationContext private val context: Context
) : NavigatorProvider {
override fun getAuthActivityIntent(): Intent =
AuthActivity.newInstance(context)
}
2 changes: 1 addition & 1 deletion app/src/main/java/org/sopt/official/util/Auth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
package org.sopt.official.util

import org.sopt.official.auth.data.remote.model.response.OAuthToken
import org.sopt.official.network.model.response.OAuthToken
import org.sopt.official.domain.entity.auth.Auth
import org.sopt.official.domain.entity.auth.Token
import org.sopt.official.domain.entity.auth.UserStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import org.sopt.official.data.persistence.SoptDataStore
import org.sopt.official.network.persistence.SoptDataStore
import org.sopt.official.datastore.fake.FakeAndroidKeyStore

@RunWith(RobolectricTestRunner::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ annotation class Logging

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class Auth(val needed: Boolean = true)
annotation class Auth()

@Qualifier
@Retention(AnnotationRetention.BINARY)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* MIT License
* Copyright 2023 SOPT - Shout Our Passion Together
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.sopt.official.common.navigator

import android.content.Intent

interface NavigatorProvider {
fun getAuthActivityIntent(): Intent
}
Empty file added core/network/.gitignore
Empty file.
Loading

0 comments on commit fdcaff6

Please sign in to comment.