-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from Team-Notitime/feat/sign/52-login-api-conn…
…ection Feat/sign/52 login api connection
- Loading branch information
Showing
55 changed files
with
701 additions
and
49 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
13 changes: 11 additions & 2 deletions
13
app/src/main/java/com/easyhz/noffice/navigation/sign/SignNavigation.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
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
12 changes: 12 additions & 0 deletions
12
core/common/src/main/java/com/easyhz/noffice/core/common/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,12 @@ | ||
package com.easyhz.noffice.core.common.di | ||
|
||
import javax.inject.Qualifier | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.RUNTIME) | ||
annotation class Dispatcher(val dispatcher: NofficeDispatchers) | ||
|
||
enum class NofficeDispatchers { | ||
DEFAULT, | ||
IO, | ||
} |
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 @@ | ||
/build |
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 @@ | ||
plugins { | ||
alias(libs.plugins.noffice.android.library) | ||
alias(libs.plugins.noffice.android.hilt) | ||
} | ||
|
||
android { | ||
namespace = "com.easyhz.noffice.core.datastore" | ||
} | ||
|
||
dependencies { | ||
implementation(projects.core.common) | ||
implementation(projects.core.model) | ||
|
||
implementation(libs.androidx.datastore) | ||
implementation(libs.androidx.datastore.core) | ||
} |
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
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,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest /> |
12 changes: 12 additions & 0 deletions
12
...re/src/main/java/com/easyhz/noffice/core/datastore/datasource/auth/AuthLocalDataSource.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 com.easyhz.noffice.core.datastore.datasource.auth | ||
|
||
|
||
interface AuthLocalDataSource { | ||
suspend fun getAccessToken(): Result<String> | ||
suspend fun getRefreshToken(): Result<String> | ||
suspend fun deleteToken() | ||
suspend fun updateAccessToken(access: String) | ||
suspend fun updateTokens(access: String, refresh: String) | ||
suspend fun getAuthProvider(): Result<String> | ||
suspend fun updateAuthProvider(provider: String) | ||
} |
73 changes: 73 additions & 0 deletions
73
...rc/main/java/com/easyhz/noffice/core/datastore/datasource/auth/AuthLocalDataSourceImpl.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,73 @@ | ||
package com.easyhz.noffice.core.datastore.datasource.auth | ||
|
||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.core.stringPreferencesKey | ||
import com.easyhz.noffice.core.common.di.Dispatcher | ||
import com.easyhz.noffice.core.common.di.NofficeDispatchers.IO | ||
import com.easyhz.noffice.core.datastore.util.AuthKey | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.withContext | ||
import javax.inject.Inject | ||
|
||
class AuthLocalDataSourceImpl @Inject constructor( | ||
@Dispatcher(IO) private val dispatcher: CoroutineDispatcher, | ||
private val dataStore: DataStore<Preferences> | ||
): AuthLocalDataSource { | ||
private val accessToken = stringPreferencesKey(AuthKey.ACCESS_TOKEN.key) | ||
private val refreshToken = stringPreferencesKey(AuthKey.REFRESH_TOKEN.key) | ||
private val authProvider = stringPreferencesKey(AuthKey.AUTH_PROVIDER.key) | ||
|
||
override suspend fun getAccessToken(): Result<String> = withContext(dispatcher) { | ||
val preferences = dataStore.data.first() | ||
return@withContext preferences[accessToken]?.let { | ||
Result.success(it) | ||
} ?: Result.failure(generateNullException(AuthKey.ACCESS_TOKEN)) | ||
} | ||
|
||
override suspend fun getRefreshToken(): Result<String> = withContext(dispatcher) { | ||
val preferences = dataStore.data.first() | ||
return@withContext preferences[refreshToken]?.let { | ||
Result.success(it) | ||
} ?: Result.failure(generateNullException(AuthKey.REFRESH_TOKEN)) | ||
} | ||
|
||
override suspend fun deleteToken(): Unit = withContext(dispatcher) { | ||
dataStore.edit { preferences -> | ||
preferences.remove(accessToken) | ||
preferences.remove(refreshToken) | ||
} | ||
} | ||
|
||
override suspend fun updateAccessToken(access: String): Unit = withContext(dispatcher) { | ||
dataStore.edit { preferences -> | ||
preferences[accessToken] = access | ||
} | ||
} | ||
|
||
override suspend fun updateTokens(access: String, refresh: String): Unit = withContext(dispatcher) { | ||
dataStore.edit { preferences -> | ||
preferences[accessToken] = access | ||
preferences[refreshToken] = refresh | ||
} | ||
} | ||
|
||
override suspend fun getAuthProvider(): Result<String> = withContext(dispatcher) { | ||
val preferences = dataStore.data.first() | ||
return@withContext preferences[authProvider]?.let { | ||
Result.success(it) | ||
} ?: Result.failure(generateNullException(AuthKey.AUTH_PROVIDER)) | ||
} | ||
|
||
override suspend fun updateAuthProvider(provider: String): Unit = withContext(dispatcher) { | ||
dataStore.edit { preferences -> | ||
preferences[authProvider] = provider | ||
} | ||
} | ||
|
||
private fun generateNullException(authKey: AuthKey): Exception { | ||
return Exception("${authKey.key} is null") | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
core/datastore/src/main/java/com/easyhz/noffice/core/datastore/di/DataSourceModule.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,17 @@ | ||
package com.easyhz.noffice.core.datastore.di | ||
|
||
import com.easyhz.noffice.core.datastore.datasource.auth.AuthLocalDataSource | ||
import com.easyhz.noffice.core.datastore.datasource.auth.AuthLocalDataSourceImpl | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
interface DataSourceModule { | ||
@Binds | ||
fun bindAuthLocalDataSource( | ||
authLocalDataSourceImpl: AuthLocalDataSourceImpl | ||
): AuthLocalDataSource | ||
} |
26 changes: 26 additions & 0 deletions
26
core/datastore/src/main/java/com/easyhz/noffice/core/datastore/di/DataStoreModule.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.easyhz.noffice.core.datastore.di | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import com.easyhz.noffice.core.datastore.util.authDataStore | ||
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 | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
abstract class DataStoreModule { | ||
companion object { | ||
|
||
@Singleton | ||
@Provides | ||
fun provideUserDataStorePreferences( | ||
@ApplicationContext context: Context | ||
): DataStore<Preferences> = | ||
context.authDataStore | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
core/datastore/src/main/java/com/easyhz/noffice/core/datastore/util/DataStoreConfig.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 com.easyhz.noffice.core.datastore.util | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.preferencesDataStore | ||
|
||
val Context.authDataStore: DataStore<Preferences> by preferencesDataStore( | ||
name = "noffice-auth" | ||
) |
13 changes: 13 additions & 0 deletions
13
core/datastore/src/main/java/com/easyhz/noffice/core/datastore/util/DataStoreKey.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,13 @@ | ||
package com.easyhz.noffice.core.datastore.util | ||
|
||
internal enum class AuthKey( | ||
val key: String | ||
) { | ||
ACCESS_TOKEN( | ||
key = "ACCESS_TOKEN" | ||
), REFRESH_TOKEN( | ||
key = "REFRESH_TOKEN" | ||
), AUTH_PROVIDER( | ||
key = "PROVIDER" | ||
) | ||
} |
8 changes: 8 additions & 0 deletions
8
core/model/src/main/java/com/easyhz/noffice/core/model/auth/param/AuthParam.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,8 @@ | ||
package com.easyhz.noffice.core.model.auth.param | ||
|
||
import android.content.Context | ||
|
||
data class AuthParam( | ||
val context: Context, | ||
val providerName: String | ||
) |
14 changes: 14 additions & 0 deletions
14
core/network/src/main/java/com/easyhz/noffice/core/network/api/auth/AuthService.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,14 @@ | ||
package com.easyhz.noffice.core.network.api.auth | ||
|
||
import com.easyhz.noffice.core.network.model.request.sign.LoginRequest | ||
import com.easyhz.noffice.core.network.model.response.auth.UserResponse | ||
import com.easyhz.noffice.core.network.util.NofficeResult | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface AuthService { | ||
@POST("/api/v1/member/login") | ||
suspend fun login( | ||
@Body body: LoginRequest | ||
): NofficeResult<UserResponse> | ||
} |
2 changes: 1 addition & 1 deletion
2
...network/src/main/java/com/easyhz/noffice/core/network/converter/ErrorResponseConverter.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
Oops, something went wrong.