generated from AND-SOPT-ANDROID/and-sopt-android-template
-
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.
feat/#8: UserDatasource, UserRepository 구현
- Loading branch information
1 parent
27f4359
commit 2b4fe9a
Showing
7 changed files
with
98 additions
and
4 deletions.
There are no files selected for viewing
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
30 changes: 30 additions & 0 deletions
30
data/src/main/java/org/sopt/and/data/datasource/UserDataSource.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,30 @@ | ||
package org.sopt.and.data.datasource | ||
|
||
import android.content.SharedPreferences | ||
import jakarta.inject.Inject | ||
import org.sopt.and.data.di.UserSharedPreference | ||
|
||
internal class UserDataSource @Inject constructor( | ||
@UserSharedPreference private val userSharedPreference: SharedPreferences | ||
) { | ||
|
||
var id: String | ||
get() = userSharedPreference.getString(ID, "").toString() | ||
set(value) = userSharedPreference.edit().putString(ID, value).apply() | ||
|
||
var password: String | ||
get() = userSharedPreference.getString(PASSWORD, "").toString() | ||
set(value) = userSharedPreference.edit().putString(PASSWORD, value).apply() | ||
|
||
fun clearIdPassword() { | ||
id = DEFAULT_STRING | ||
password = DEFAULT_STRING | ||
userSharedPreference.edit().clear().apply() | ||
} | ||
|
||
companion object { | ||
private const val ID = "id" | ||
private const val PASSWORD = "password" | ||
private const val DEFAULT_STRING = "" | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
data/src/main/java/org/sopt/and/data/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,21 @@ | ||
package org.sopt.and.data.di | ||
|
||
import android.content.SharedPreferences | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import org.sopt.and.data.datasource.UserDataSource | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
internal object DataSourceModule { | ||
|
||
@Singleton | ||
@Provides | ||
fun provideUserDataSource( | ||
@UserSharedPreference userSharedPreference: SharedPreferences | ||
): UserDataSource = UserDataSource(userSharedPreference) | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
data/src/main/java/org/sopt/and/data/di/RepositoryModule.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 org.sopt.and.data.di | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import org.sopt.and.data.repository.UserRepositoryImpl | ||
import org.sopt.and.domain.repository.UserRepository | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
internal interface RepositoryModule { | ||
|
||
@Binds | ||
fun bindUserRepository(userRepositoryImpl: UserRepositoryImpl): UserRepository | ||
} |
23 changes: 23 additions & 0 deletions
23
data/src/main/java/org/sopt/and/data/repository/UserRepositoryImpl.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,23 @@ | ||
package org.sopt.and.data.repository | ||
|
||
import jakarta.inject.Inject | ||
import org.sopt.and.data.datasource.UserDataSource | ||
import org.sopt.and.domain.repository.UserRepository | ||
|
||
internal class UserRepositoryImpl @Inject constructor( | ||
private val userDataSource: UserDataSource | ||
): UserRepository { | ||
override fun saveUser(id: String, password: String) { | ||
userDataSource.id = id | ||
userDataSource.password = password | ||
} | ||
|
||
override fun clearIdPassword() { | ||
userDataSource.clearIdPassword() | ||
} | ||
|
||
override fun getId(): String { | ||
return userDataSource.id | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
domain/src/main/java/org/sopt/and/domain/repository/UserRepository.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,7 @@ | ||
package org.sopt.and.domain.repository | ||
|
||
interface UserRepository { | ||
fun saveUser(id: String, password: String) | ||
fun clearIdPassword() | ||
fun getId(): String | ||
} |