-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor/clean architecture #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
84e5e70
8e56512
0ad4ac3
6ba75ee
9f510c6
36d2eb9
ebe74c2
6bcfe3a
35137e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package org.sopt.dosopttemplate.data.local | ||
|
|
||
| import androidx.room.Database | ||
| import androidx.room.RoomDatabase | ||
| import org.sopt.dosopttemplate.data.local.dao.UserInfoDao | ||
| import org.sopt.dosopttemplate.data.local.entity.UserInfoEntity | ||
|
|
||
| @Database(entities = [UserInfoEntity::class], version = 1) | ||
| abstract class AppDatabase : RoomDatabase() { | ||
| abstract fun userInfoDao(): UserInfoDao | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package org.sopt.dosopttemplate.data.local.dao | ||
|
|
||
| import androidx.room.Dao | ||
| import androidx.room.Entity | ||
| import androidx.room.Insert | ||
| import androidx.room.Query | ||
| import kotlinx.coroutines.flow.Flow | ||
| import org.sopt.dosopttemplate.data.local.entity.UserInfoEntity | ||
|
|
||
| @Entity | ||
| @Dao | ||
| interface UserInfoDao { | ||
| @Insert | ||
| fun saveUserInfo(userInfoEntity: UserInfoEntity) | ||
|
|
||
| @Query("SELECT * FROM user_info LIMIT 1") | ||
| fun getUserInfo(): Flow<UserInfoEntity> | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package org.sopt.dosopttemplate.data.local.datasource | ||
|
|
||
| import kotlinx.coroutines.flow.Flow | ||
| import org.sopt.dosopttemplate.data.local.entity.UserInfoEntity | ||
|
|
||
| interface RoomDataSource { | ||
| fun saveUserInfo(userInfoEntity: UserInfoEntity) | ||
| fun getUserInfo(): Flow<UserInfoEntity> | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package org.sopt.dosopttemplate.data.local.datasourceimpl | ||
|
|
||
| import kotlinx.coroutines.flow.Flow | ||
| import org.sopt.dosopttemplate.data.local.dao.UserInfoDao | ||
| import org.sopt.dosopttemplate.data.local.datasource.RoomDataSource | ||
| import org.sopt.dosopttemplate.data.local.entity.UserInfoEntity | ||
| import javax.inject.Inject | ||
|
|
||
| class RoomDataSourceImpl @Inject constructor( | ||
| private val userInfoDao: UserInfoDao | ||
| ) : RoomDataSource { | ||
| override fun saveUserInfo(userInfoEntity: UserInfoEntity) { | ||
| userInfoDao.saveUserInfo(userInfoEntity) | ||
| } | ||
|
|
||
| override fun getUserInfo(): Flow<UserInfoEntity> { | ||
| return userInfoDao.getUserInfo() | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package org.sopt.dosopttemplate.data.local.entity | ||
|
|
||
| import androidx.room.Entity | ||
| import androidx.room.PrimaryKey | ||
| import kotlinx.coroutines.flow.Flow | ||
| import org.sopt.dosopttemplate.domain.model.UserInfo | ||
|
|
||
| @Entity(tableName = "user_info") | ||
| data class UserInfoEntity( | ||
| @PrimaryKey(autoGenerate = true) | ||
| val userNum: Long = 0, | ||
| val nickName: String, | ||
| val id: String, | ||
| val password: String, | ||
| val mbti: String, | ||
| ) { | ||
| fun toUserInfo(): UserInfo { | ||
| return UserInfo( | ||
| nickName = this.nickName, | ||
| id = this.id, | ||
| password = this.password, | ||
| mbti = this.mbti | ||
| ) | ||
| } | ||
|
Comment on lines
+17
to
+24
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. map 함수는 전 dto내부에 선언하는데 웹소소 처럼
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. �취향 차이인 듯 합니다! 제 생각엔 각각의 장단점이 있어서 컨벤션 맞춰서 진행하면 되지 않을까 하는 생각 ㅎㅎ ? |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package org.sopt.dosopttemplate.data.local.repositoryimpl | ||
|
|
||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.map | ||
| import org.sopt.dosopttemplate.data.local.dao.UserInfoDao | ||
| import org.sopt.dosopttemplate.data.local.entity.UserInfoEntity | ||
| import org.sopt.dosopttemplate.domain.model.UserInfo | ||
| import org.sopt.dosopttemplate.domain.repository.UserInfoRepository | ||
| import javax.inject.Inject | ||
|
|
||
| class UserInfoRepositoryImpl @Inject constructor( | ||
| private val userDao: UserInfoDao | ||
| ) : UserInfoRepository { | ||
|
|
||
| override fun saveUserInfo(userInfo: UserInfo) { | ||
| userDao.saveUserInfo( | ||
| userInfoEntity = UserInfoEntity( | ||
| id = userInfo.id, | ||
| password = userInfo.password, | ||
| nickName = userInfo.nickName, | ||
| mbti = userInfo.mbti | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| override fun getUserInfo(): Flow<UserInfo> { | ||
| return userDao.getUserInfo().map { userInfoEntity -> | ||
| userInfoEntity.toUserInfo() | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package org.sopt.dosopttemplate.di | ||
|
|
||
| import android.content.Context | ||
| import androidx.room.Room | ||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.android.qualifiers.ApplicationContext | ||
| import dagger.hilt.components.SingletonComponent | ||
| import org.sopt.dosopttemplate.data.local.AppDatabase | ||
| import org.sopt.dosopttemplate.data.local.dao.UserInfoDao | ||
| import org.sopt.dosopttemplate.data.local.datasource.RoomDataSource | ||
| import org.sopt.dosopttemplate.data.local.datasourceimpl.RoomDataSourceImpl | ||
| import javax.inject.Singleton | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| abstract class DatabaseModule { | ||
|
|
||
| companion object { | ||
| @Singleton | ||
| @Provides | ||
| fun provideAppDatabase(@ApplicationContext context: Context): AppDatabase { | ||
| return Room.databaseBuilder(context, AppDatabase::class.java, "user_info").build() | ||
| } | ||
|
|
||
| @Singleton | ||
| @Provides | ||
| fun provideRoomDataSource(impl: RoomDataSourceImpl): RoomDataSource { | ||
| return impl | ||
| } | ||
|
|
||
| @Singleton | ||
| @Provides | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @singleton |
||
| fun provideUserInfoDao(appDatabase: AppDatabase): UserInfoDao { | ||
| return appDatabase.userInfoDao() | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package org.sopt.dosopttemplate.di | ||
|
|
||
| import dagger.Binds | ||
| import dagger.Module | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.components.SingletonComponent | ||
| import org.sopt.dosopttemplate.data.local.repositoryimpl.UserInfoRepositoryImpl | ||
| import org.sopt.dosopttemplate.domain.repository.UserInfoRepository | ||
| import javax.inject.Singleton | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| abstract class RepositoryModule { | ||
| @Singleton | ||
| @Binds | ||
| abstract fun provideUserInfoRepositoryImpl(userInfoRepositoryImpl: UserInfoRepositoryImpl): UserInfoRepository | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package org.sopt.dosopttemplate.domain.model | ||
|
|
||
| data class UserInfo( | ||
| val nickName: String, | ||
| val id: String, | ||
| val password: String, | ||
| val mbti: String, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
추가로 interface를 구현했기 때문에 RoomDataSource는 필요 없고 UserInfoDao로 바로 RoomDataSourceImpl이 가능 할것 같습니다! 어제 회의때 이야기 한 부분인데 이 부분은 저도 아직 잘 몰라서.. 함께 고민해봐요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분에 대해서도 고민해봤는데
UserInfoDao가 db 에 직접적으로 접근할 수 있기 때문에RoomDataSource를 통해서 추상화를 해주어야 한다고 생각했습니다!지금 같이 가벼운 로직에는
UserInfoDao에서 바로Impl로 연결해도 될 것 같긴 한데 dao의 구현을 숨겨 캡슐화 하기 위해서 저는 분리하긴 했습니다