Skip to content

Commit f44317a

Browse files
authored
πŸ”€ #45 from boostcampwm-2022/feat/my_run_custom_calendar
ν˜„μž¬ μ—°κ²°λœ 계정 ν‘œμ‹œ κ΅¬ν˜„, λ‘œκ·Έμ•„μ›ƒ/νšŒμ›νƒˆν‡΄ 둜직 κ΅¬ν˜„, μΊ˜λ¦°λ” λ·° κ΅¬ν˜„
2 parents dbc911b + 4abe7b0 commit f44317a

28 files changed

+387
-55
lines changed

β€Žbuild.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ buildscript {
1414
kotlinxCoroutinesVersion = "1.6.4"
1515
paging3Version = "3.1.1"
1616
navVersion = "2.5.3"
17-
playServicesAuthVersion = "20.3.0"
17+
playServicesAuthVersion = "20.4.0"
1818
hiltVersion = "2.44"
1919
lottieVersion = "5.2.0"
2020
activityKtxVersion = "1.6.1"

β€Ždata/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ dependencies {
4444
implementation platform("com.google.firebase:firebase-bom:$firebaseVersion")
4545
implementation "com.google.firebase:firebase-analytics-ktx"
4646
implementation "com.google.firebase:firebase-firestore-ktx"
47+
implementation "com.google.firebase:firebase-auth-ktx"
48+
implementation "com.google.android.gms:play-services-auth:$playServicesAuthVersion"
4749

4850
// Hilt
4951
implementation "com.google.dagger:hilt-android:$hiltVersion"

β€Ždata/src/main/java/com/whyranoid/data/account/AccountDataSource.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ interface AccountDataSource {
66
fun getUserNickName(): Flow<String>
77
fun getUserProfileImgUri(): Flow<String>
88
fun getUserUid(): Flow<String>
9+
fun getEmail(): Flow<Result<String>>
910
suspend fun updateUserNickName(uid: String, newNickName: String): Result<String>
11+
suspend fun signOut(): Result<Boolean>
12+
suspend fun withDrawal(): Result<Boolean>
1013
}

β€Ždata/src/main/java/com/whyranoid/data/account/AccountDataSourceImpl.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import androidx.datastore.core.DataStore
44
import androidx.datastore.preferences.core.Preferences
55
import androidx.datastore.preferences.core.edit
66
import androidx.datastore.preferences.core.stringPreferencesKey
7+
import com.google.firebase.auth.FirebaseAuth
78
import com.google.firebase.firestore.FirebaseFirestore
9+
import com.whyranoid.data.account.AccountDataSourceImpl.PreferenceKeys.email
810
import com.whyranoid.data.account.AccountDataSourceImpl.PreferenceKeys.nickName
911
import com.whyranoid.data.account.AccountDataSourceImpl.PreferenceKeys.profileImgUri
1012
import com.whyranoid.data.account.AccountDataSourceImpl.PreferenceKeys.uid
13+
import kotlinx.coroutines.flow.Flow
1114
import kotlinx.coroutines.flow.map
1215
import javax.inject.Inject
1316

@@ -16,6 +19,9 @@ class AccountDataSourceImpl @Inject constructor(
1619
private val fireBaseDb: FirebaseFirestore
1720
) : AccountDataSource {
1821

22+
private val auth = FirebaseAuth.getInstance()
23+
private val currentUser = auth.currentUser
24+
1925
private object PreferenceKeys {
2026
val uid = stringPreferencesKey(UID_KEY)
2127
val email = stringPreferencesKey(EMAIL_KEY)
@@ -38,6 +44,15 @@ class AccountDataSourceImpl @Inject constructor(
3844
preferences[uid] ?: EMPTY_STRING
3945
}
4046

47+
override fun getEmail(): Flow<Result<String>> {
48+
return dataStoreDb.data
49+
.map { preferences ->
50+
runCatching {
51+
preferences[email] ?: EMPTY_STRING
52+
}
53+
}
54+
}
55+
4156
override suspend fun updateUserNickName(uid: String, newNickName: String) = runCatching {
4257
// λ‘œμ»¬μ— μ—…λ°μ΄νŠΈ
4358
dataStoreDb.edit { preferences ->
@@ -51,6 +66,15 @@ class AccountDataSourceImpl @Inject constructor(
5166
newNickName
5267
}
5368

69+
override suspend fun signOut(): Result<Boolean> = runCatching {
70+
signOut()
71+
true
72+
}
73+
74+
override suspend fun withDrawal(): Result<Boolean> {
75+
TODO("Not yet implemented")
76+
}
77+
5478
companion object {
5579
private const val UID_KEY = "uid"
5680
private const val EMAIL_KEY = "email"

β€Ždata/src/main/java/com/whyranoid/data/account/AccountRepositoryImpl.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class AccountRepositoryImpl @Inject constructor(
2525
return accountDataSource.getUserNickName()
2626
}
2727

28+
override fun getEmail(): Flow<Result<String>> {
29+
return accountDataSource.getEmail()
30+
}
31+
2832
override suspend fun updateNickname(uid: String, newNickName: String): Result<String> {
2933
return accountDataSource.updateUserNickName(uid, newNickName)
3034
}
@@ -36,4 +40,12 @@ class AccountRepositoryImpl @Inject constructor(
3640
override suspend fun updateProfileUrl(newProfileUrl: String): Boolean {
3741
return true
3842
}
43+
44+
override suspend fun signOut(): Result<Boolean> {
45+
TODO("Not yet implemented")
46+
}
47+
48+
override suspend fun withDrawal(): Result<Boolean> {
49+
TODO("Not yet implemented")
50+
}
3951
}

β€Ždata/src/main/java/com/whyranoid/data/account/RunningHistoryDao.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ interface RunningHistoryDao {
1212
@Insert(onConflict = OnConflictStrategy.ABORT)
1313
suspend fun addRunningHistory(runningHistory: RunningHistoryEntity)
1414

15-
@Query("SELECT * FROM running_history ORDER BY startedAt ASC")
15+
@Query("SELECT * FROM running_history ORDER BY started_at ASC")
1616
fun getRunningHistory(): Flow<List<RunningHistoryEntity>>
1717
}

β€Ždata/src/main/java/com/whyranoid/data/account/RunningHistoryEntity.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.whyranoid.data.account
22

3+
import androidx.room.ColumnInfo
34
import androidx.room.Entity
45
import androidx.room.PrimaryKey
56
import com.whyranoid.domain.model.RunningHistory
@@ -8,11 +9,11 @@ import com.whyranoid.domain.model.RunningHistory
89
data class RunningHistoryEntity(
910
@PrimaryKey
1011
val historyId: String,
11-
val startedAt: Long,
12-
val finishedAt: Long,
13-
val totalRunningTime: Int,
14-
val pace: Double,
15-
val totalDistance: Double
12+
@ColumnInfo(name = "started_at") val startedAt: Long,
13+
@ColumnInfo(name = "finished_at") val finishedAt: Long,
14+
@ColumnInfo(name = "total_running_time") val totalRunningTime: Int,
15+
@ColumnInfo(name = "pace") val pace: Double,
16+
@ColumnInfo(name = "total_distance") val totalDistance: Double
1617
)
1718

1819
fun RunningHistoryEntity.toRunningHistory(): RunningHistory {

β€Ždata/src/main/java/com/whyranoid/data/account/RunningHistoryLocalDataSourceImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import kotlinx.coroutines.flow.map
66
import javax.inject.Inject
77

88
class RunningHistoryLocalDataSourceImpl @Inject constructor(
9-
private val roomDb: RunningHistoryLocalDataBase
9+
private val runningHistoryDao: RunningHistoryDao
1010
) : RunningHistoryLocalDataSource {
1111

1212
override fun getRunningHistory(): Flow<List<RunningHistory>> {
13-
return roomDb.runningHistoryDao().getRunningHistory().map { runningHistoryList ->
13+
return runningHistoryDao.getRunningHistory().map { runningHistoryList ->
1414
runningHistoryList.map { runningHistoryEntity ->
1515
runningHistoryEntity.toRunningHistory()
1616
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.whyranoid.data.di
2+
3+
import android.content.Context
4+
import androidx.room.Room
5+
import com.whyranoid.data.account.RunningHistoryDao
6+
import com.whyranoid.data.account.RunningHistoryLocalDataBase
7+
import dagger.Module
8+
import dagger.Provides
9+
import dagger.hilt.InstallIn
10+
import dagger.hilt.android.qualifiers.ApplicationContext
11+
import dagger.hilt.components.SingletonComponent
12+
import javax.inject.Singleton
13+
14+
@Module
15+
@InstallIn(SingletonComponent::class)
16+
object RunningHistoryDataBaseModule {
17+
@Singleton
18+
@Provides
19+
fun provideRoomDataBase(
20+
@ApplicationContext appContext: Context
21+
): RunningHistoryLocalDataBase = Room.databaseBuilder(
22+
appContext,
23+
RunningHistoryLocalDataBase::class.java,
24+
"mogakrun_running_history.db"
25+
)
26+
.build()
27+
28+
@Singleton
29+
@Provides
30+
fun provideRunningHistoryDao(runningHistoryLocalDataBase: RunningHistoryLocalDataBase): RunningHistoryDao =
31+
runningHistoryLocalDataBase.runningHistoryDao()
32+
}

β€Ždata/src/main/java/com/whyranoid/data/di/DataBaseModule.kt renamed to β€Ždata/src/main/java/com/whyranoid/data/di/UserDataBaseModule.kt

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import androidx.datastore.core.DataStore
55
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
66
import androidx.datastore.preferences.core.Preferences
77
import androidx.datastore.preferences.preferencesDataStoreFile
8-
import androidx.room.Room
9-
import com.whyranoid.data.account.RunningHistoryLocalDataBase
108
import dagger.Module
119
import dagger.Provides
1210
import dagger.hilt.InstallIn
@@ -16,22 +14,7 @@ import javax.inject.Singleton
1614

1715
@Module
1816
@InstallIn(SingletonComponent::class)
19-
object DataBaseModule {
20-
@Singleton
21-
@Provides
22-
fun provideRoomDataBase(
23-
@ApplicationContext appContext: Context
24-
): RunningHistoryLocalDataBase = Room.databaseBuilder(
25-
appContext,
26-
RunningHistoryLocalDataBase::class.java,
27-
"mogakrun_running_history.db"
28-
)
29-
.build()
30-
}
31-
32-
@Module
33-
@InstallIn(SingletonComponent::class)
34-
object DataStoreModule {
17+
object UserDataBaseModule {
3518

3619
private const val USER_PREFERENCES = "user_preferences"
3720

0 commit comments

Comments
Β (0)