-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ode-refactor [Feature/#17] : 좋아요 페이지 리팩토링
- Loading branch information
Showing
30 changed files
with
671 additions
and
436 deletions.
There are no files selected for viewing
7 changes: 0 additions & 7 deletions
7
app/src/main/java/com/hackathon/alddeul_babsang/app/Qualifier.kt
This file was deleted.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
...ackathon/alddeul_babsang/app/Extension.kt → ...athon/alddeul_babsang/app/di/Extension.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,4 +1,4 @@ | ||
package com.hackathon.alddeul_babsang.app | ||
package com.hackathon.alddeul_babsang.app.di | ||
|
||
fun String?.isJsonObject(): Boolean = this?.startsWith("{") == true && this.endsWith("}") | ||
fun String?.isJsonArray(): Boolean = this?.startsWith("[") == true && this.endsWith("]") |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/hackathon/alddeul_babsang/app/di/Qualifier.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,15 @@ | ||
package com.hackathon.alddeul_babsang.app.di | ||
|
||
import javax.inject.Qualifier | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class AlddeulRetrofit | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class AccessToken | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class UserPreferences |
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
2 changes: 1 addition & 1 deletion
2
...thon/alddeul_babsang/app/ServiceModule.kt → ...n/alddeul_babsang/app/di/ServiceModule.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
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/hackathon/alddeul_babsang/app/di/UserPreferencesModule.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,26 @@ | ||
package com.hackathon.alddeul_babsang.app.di | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object UserPreferencesModule { | ||
private const val USER_PREFERENCES = "user_preferences" | ||
private val Context.userDataStore by preferencesDataStore(name = USER_PREFERENCES) | ||
|
||
@Provides | ||
@Singleton | ||
@UserPreferences | ||
fun provideDataStore( | ||
@ApplicationContext context: Context | ||
): DataStore<Preferences> = context.userDataStore | ||
} |
35 changes: 35 additions & 0 deletions
35
app/src/main/java/com/hackathon/alddeul_babsang/app/interceptor/TokenInterceptor.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,35 @@ | ||
package com.hackathon.alddeul_babsang.app.interceptor | ||
|
||
import com.hackathon.alddeul_babsang.data.datasource.UserPreferencesDataSource | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.runBlocking | ||
import okhttp3.Interceptor | ||
import okhttp3.Response | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
class TokenInterceptor @Inject constructor( | ||
private val userPreferencesDataSource: UserPreferencesDataSource | ||
) : Interceptor { | ||
override fun intercept(chain: Interceptor.Chain): Response = runBlocking { | ||
val request = chain.request() | ||
val url = request.url.toString() | ||
|
||
// 특정 URL 패턴에 대해서는 토큰을 추가하지 않음 | ||
if (url.contains("/api/v1/auth/login") || | ||
url.contains("api/v1/signup") || | ||
url.contains("api/v1/member")) { | ||
// 로그인 요청 등 토큰이 필요 없는 요청의 경우 | ||
return@runBlocking chain.proceed(request) | ||
} | ||
|
||
// 토큰이 필요한 요청의 경우 | ||
val accessToken = userPreferencesDataSource.getUserAccessToken().first() | ||
val newRequest = request.newBuilder() | ||
.addHeader("Authorization", "Bearer $accessToken") | ||
.build() | ||
|
||
Timber.tag("interceptor").d("accessToken $accessToken") | ||
chain.proceed(newRequest) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/hackathon/alddeul_babsang/data/datasource/UserPreferencesDataSource.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,16 @@ | ||
package com.hackathon.alddeul_babsang.data.datasource | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface UserPreferencesDataSource { | ||
suspend fun saveUserAccessToken(accessToken: String) | ||
fun getUserAccessToken(): Flow<String?> | ||
|
||
suspend fun saveCheckLogin(checkLogin: Boolean) | ||
fun getCheckLogin(): Flow<Boolean> | ||
|
||
suspend fun saveUserRefreshToken(refreshToken: String) | ||
fun getUserRefreshToken(): Flow<String?> | ||
|
||
suspend fun clear() | ||
} |
58 changes: 58 additions & 0 deletions
58
...n/java/com/hackathon/alddeul_babsang/data/datasourceimpl/UserPreferencesDataSourceImpl.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,58 @@ | ||
package com.hackathon.alddeul_babsang.data.datasourceimpl | ||
|
||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.booleanPreferencesKey | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.core.stringPreferencesKey | ||
import com.hackathon.alddeul_babsang.app.di.UserPreferences | ||
import com.hackathon.alddeul_babsang.data.datasource.UserPreferencesDataSource | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
import javax.inject.Inject | ||
|
||
class UserPreferencesDataSourceImpl @Inject constructor( | ||
@UserPreferences private val dataStore: DataStore<Preferences> | ||
) : UserPreferencesDataSource { | ||
private val USER_ACCESS_TOKEN = stringPreferencesKey("user_access_token") | ||
private val USER_REFRESH_TOKEN = stringPreferencesKey("user_refresh_token") | ||
private val CHECK_LOGIN = booleanPreferencesKey("check_login") | ||
|
||
override suspend fun saveUserAccessToken(accessToken: String) { | ||
dataStore.edit { preferences -> | ||
preferences[USER_ACCESS_TOKEN] = accessToken | ||
} | ||
} | ||
|
||
override fun getUserAccessToken(): Flow<String?> = dataStore.data.map { preferences -> | ||
preferences[USER_ACCESS_TOKEN] | ||
} | ||
|
||
override suspend fun saveCheckLogin(checkLogin: Boolean) { | ||
dataStore.edit { preferences -> | ||
preferences[CHECK_LOGIN] = checkLogin | ||
} | ||
} | ||
|
||
override fun getCheckLogin(): Flow<Boolean> = dataStore.data.map { preferences -> | ||
preferences[CHECK_LOGIN] ?: false | ||
} | ||
|
||
override suspend fun saveUserRefreshToken(refreshToken: String) { | ||
dataStore.edit { preferences -> | ||
preferences[USER_REFRESH_TOKEN] = refreshToken | ||
} | ||
} | ||
|
||
override fun getUserRefreshToken(): Flow<String?> = dataStore.data.map { preferences -> | ||
preferences[USER_REFRESH_TOKEN] | ||
} | ||
|
||
override suspend fun clear() { | ||
dataStore.edit { preferences -> | ||
preferences.remove(USER_ACCESS_TOKEN) | ||
preferences.remove(USER_REFRESH_TOKEN) | ||
preferences.remove(CHECK_LOGIN) | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...n/java/com/hackathon/alddeul_babsang/data/repositoryimpl/UserPreferencesRepositoryImpl.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,32 @@ | ||
package com.hackathon.alddeul_babsang.data.repositoryimpl | ||
|
||
import com.hackathon.alddeul_babsang.data.datasource.UserPreferencesDataSource | ||
import com.hackathon.alddeul_babsang.domain.repository.UserPreferencesRepository | ||
import kotlinx.coroutines.flow.Flow | ||
import javax.inject.Inject | ||
|
||
class UserPreferencesRepositoryImpl @Inject constructor( | ||
private val dataSource: UserPreferencesDataSource | ||
) : UserPreferencesRepository { | ||
|
||
override suspend fun saveUserAccessToken(accessToken: String) { | ||
dataSource.saveUserAccessToken(accessToken) | ||
} | ||
|
||
override fun getUserAccessToken(): Flow<String?> = dataSource.getUserAccessToken() | ||
|
||
override suspend fun saveCheckLogin(checkLogin: Boolean) { | ||
dataSource.saveCheckLogin(checkLogin) | ||
} | ||
|
||
override fun getCheckLogin(): Flow<Boolean> = dataSource.getCheckLogin() | ||
|
||
override suspend fun saveUserRefreshToken(refreshToken: String) { | ||
dataSource.saveUserRefreshToken(refreshToken) | ||
} | ||
|
||
override fun getUserRefreshToken(): Flow<String?> = dataSource.getUserRefreshToken() | ||
|
||
override suspend fun clear() = dataSource.clear() | ||
|
||
} |
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
2 changes: 1 addition & 1 deletion
2
...absang/domain/entity/BabsangListEntity.kt → ...deul_babsang/domain/entity/LikesEntity.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
16 changes: 16 additions & 0 deletions
16
...rc/main/java/com/hackathon/alddeul_babsang/domain/repository/UserPreferencesRepository.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,16 @@ | ||
package com.hackathon.alddeul_babsang.domain.repository | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface UserPreferencesRepository { | ||
suspend fun saveUserAccessToken(accessToken: String) | ||
fun getUserAccessToken(): Flow<String?> | ||
|
||
suspend fun saveCheckLogin(checkLogin: Boolean) | ||
fun getCheckLogin(): Flow<Boolean> | ||
|
||
suspend fun saveUserRefreshToken(refreshToken: String) | ||
fun getUserRefreshToken(): Flow<String?> | ||
|
||
suspend fun clear() | ||
} |
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
Oops, something went wrong.