-
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.
- Loading branch information
1 parent
05ffb5d
commit ff6a453
Showing
7 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
...m/bff/wespot/model/auth/KakaoAuthToken.kt → ...spot/model/auth/request/KakaoAuthToken.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,6 +1,7 @@ | ||
package com.bff.wespot.model.auth | ||
package com.bff.wespot.model.auth.request | ||
|
||
data class KakaoAuthToken( | ||
val accessToken: String, | ||
val idToken: String?, | ||
val socialType: String | ||
) |
2 changes: 1 addition & 1 deletion
2
...otlin/com/bff/wespot/model/auth/School.kt → .../bff/wespot/model/auth/response/School.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.bff.wespot.model.auth | ||
package com.bff.wespot.model.auth.response | ||
|
||
data class School( | ||
val id: Int, | ||
|
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
10 changes: 10 additions & 0 deletions
10
data/src/main/kotlin/com/bff/wespot/data/local/WeSpotDataStore.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.bff.wespot.data.local | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface WeSpotDataStore { | ||
suspend fun saveString(key: String, value: String) | ||
fun getString(key: String): Flow<String> | ||
suspend fun saveBoolean(key: String, value: Boolean) | ||
fun getBoolean(key: String): Flow<Boolean> | ||
} |
70 changes: 70 additions & 0 deletions
70
data/src/main/kotlin/com/bff/wespot/data/local/WeSpotDataStoreImpl.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,70 @@ | ||
package com.bff.wespot.data.local | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.core.IOException | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.booleanPreferencesKey | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.core.emptyPreferences | ||
import androidx.datastore.preferences.core.stringPreferencesKey | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.catch | ||
import kotlinx.coroutines.flow.distinctUntilChanged | ||
import kotlinx.coroutines.flow.map | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class WeSpotDataStoreImpl @Inject constructor( | ||
@ApplicationContext private val context: Context | ||
) : WeSpotDataStore { | ||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "wespot") | ||
private val datastore = context.dataStore | ||
|
||
override suspend fun saveString( | ||
key: String, | ||
value: String | ||
) { | ||
datastore.edit { preferences -> | ||
preferences[stringPreferencesKey(key)] = value | ||
} | ||
} | ||
|
||
override suspend fun saveBoolean( | ||
key: String, | ||
value: Boolean | ||
) { | ||
datastore.edit { preferences -> | ||
preferences[booleanPreferencesKey(key)] = value | ||
} | ||
} | ||
|
||
override fun getString(key: String): Flow<String> = | ||
datastore.data.distinctUntilChanged() | ||
.catch {e -> | ||
if(e is IOException) { | ||
emit(emptyPreferences()) | ||
} else { | ||
throw e | ||
} | ||
} | ||
.map { | ||
it[stringPreferencesKey(key)] ?: "" | ||
} | ||
|
||
override fun getBoolean(key: String): Flow<Boolean> = | ||
datastore.data.distinctUntilChanged() | ||
.catch {e -> | ||
if(e is IOException) { | ||
emit(emptyPreferences()) | ||
} else { | ||
throw e | ||
} | ||
} | ||
.map { | ||
it[booleanPreferencesKey(key)] ?: false | ||
} | ||
} |
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