-
Notifications
You must be signed in to change notification settings - Fork 1
feat: 서재 UI/UX 개편 (3) - Room 모듈 구현 #697
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /build |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import com.into.websoso.buildConfigs | ||
| import com.into.websoso.setNamespace | ||
|
|
||
| plugins { | ||
| id("websoso.android.library") | ||
| } | ||
|
|
||
| android { | ||
| setNamespace("core.database") | ||
| } | ||
|
|
||
| dependencies { | ||
| // 데이터 레이어 의존성 | ||
| implementation(projects.data.library) | ||
|
|
||
| // 데이터베이스 관련 라이브러리 | ||
| implementation(libs.room.ktx) | ||
| implementation(libs.room.runtime) | ||
| kapt(libs.room.compiler) | ||
| } | ||
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest> | ||
|
|
||
| </manifest> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.into.websoso.core.database | ||
|
|
||
| import androidx.room.Database | ||
| import androidx.room.RoomDatabase | ||
| import com.into.websoso.core.database.datasource.library.NovelDao | ||
| import com.into.websoso.core.database.entity.NovelEntity | ||
|
|
||
| @Database( | ||
| entities = [NovelEntity::class], | ||
| version = 1, | ||
| exportSchema = false, | ||
| ) | ||
| internal abstract class WebsosoDatabase : RoomDatabase() { | ||
| internal abstract fun novelDao(): NovelDao | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,27 @@ | ||||||||||||||||||||||||||||||||||
| package com.into.websoso.core.database.datasource.library | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import com.into.websoso.data.library.datasource.LibraryLocalDataSource | ||||||||||||||||||||||||||||||||||
| import dagger.Binds | ||||||||||||||||||||||||||||||||||
| import dagger.Module | ||||||||||||||||||||||||||||||||||
| import dagger.hilt.InstallIn | ||||||||||||||||||||||||||||||||||
| import dagger.hilt.components.SingletonComponent | ||||||||||||||||||||||||||||||||||
| import javax.inject.Inject | ||||||||||||||||||||||||||||||||||
| import javax.inject.Singleton | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| internal class DefaultLibraryDataSource | ||||||||||||||||||||||||||||||||||
| @Inject | ||||||||||||||||||||||||||||||||||
| constructor( | ||||||||||||||||||||||||||||||||||
| private val novelDao: NovelDao, | ||||||||||||||||||||||||||||||||||
| ) : LibraryLocalDataSource { | ||||||||||||||||||||||||||||||||||
| override suspend fun selectAllNovels() { | ||||||||||||||||||||||||||||||||||
| TODO("Not yet implemented") | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+11
to
+19
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. 미구현된 메서드 구현 필요
다음과 같이 메서드를 구현하는 것을 권장합니다: - override suspend fun selectAllNovels() {
- TODO("Not yet implemented")
- }
+ override suspend fun selectAllNovels() = novelDao.selectAllNovels()또한, LibraryLocalDataSource의 반환 타입에 따라 적절한 모델 변환이 필요할 수 있습니다. 만약 LibraryLocalDataSource 인터페이스의 메서드가 특정 반환 타입을 가지고 있다면 그에 맞게 수정해주세요. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @Module | ||||||||||||||||||||||||||||||||||
| @InstallIn(SingletonComponent::class) | ||||||||||||||||||||||||||||||||||
| internal interface LibraryDataSourceModule { | ||||||||||||||||||||||||||||||||||
| @Binds | ||||||||||||||||||||||||||||||||||
| @Singleton | ||||||||||||||||||||||||||||||||||
| fun bindLibraryLocalDataSource(defaultLibraryDataSource: DefaultLibraryDataSource): LibraryLocalDataSource | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.into.websoso.core.database.datasource.library | ||
|
|
||
| import androidx.room.Dao | ||
| import androidx.room.Insert | ||
| import androidx.room.OnConflictStrategy | ||
| import androidx.room.Query | ||
| import com.into.websoso.core.database.WebsosoDatabase | ||
| import com.into.websoso.core.database.entity.NovelEntity | ||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.components.SingletonComponent | ||
| import kotlinx.coroutines.flow.Flow | ||
| import javax.inject.Singleton | ||
|
|
||
| @Dao | ||
| internal interface NovelDao { | ||
| @Insert(onConflict = OnConflictStrategy.REPLACE) | ||
| suspend fun insertNovels(novels: List<NovelEntity>) | ||
|
|
||
| @Query( | ||
| value = """ | ||
| SELECT * FROM novels | ||
| ORDER BY userNovelId | ||
| DESC | ||
| """, | ||
| ) | ||
| fun selectAllNovels(): Flow<List<NovelEntity>> | ||
|
|
||
| @Query( | ||
| value = """ | ||
| SELECT * FROM novels | ||
| WHERE userNovelId = :id | ||
| """, | ||
| ) | ||
| suspend fun selectNovelById(id: Long): NovelEntity? | ||
|
|
||
| @Query( | ||
| value = """ | ||
| DELETE FROM novels | ||
| """, | ||
| ) | ||
| suspend fun deleteAllNovels() | ||
| } | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| internal object NovelDaoModule { | ||
| @Provides | ||
| @Singleton | ||
| internal fun provideNovelDao(database: WebsosoDatabase): NovelDao = database.novelDao() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.into.websoso.core.database.di | ||
|
|
||
| import android.content.Context | ||
| import androidx.room.Room | ||
| import com.into.websoso.core.database.WebsosoDatabase | ||
| 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 | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| internal object DatabaseModule { | ||
| @Provides | ||
| @Singleton | ||
| internal fun provideDatabase( | ||
| @ApplicationContext context: Context, | ||
| ): WebsosoDatabase = | ||
| Room | ||
| .databaseBuilder( | ||
| context, | ||
| WebsosoDatabase::class.java, | ||
| "websoso.db", | ||
| ).build() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.into.websoso.core.database.entity | ||
|
|
||
| import androidx.room.Entity | ||
| import androidx.room.PrimaryKey | ||
|
|
||
| @Entity(tableName = "novels") | ||
| internal data class NovelEntity( | ||
| @PrimaryKey | ||
| val userNovelId: Long, | ||
| val novelId: Long, | ||
| val author: String, | ||
| val title: String, | ||
| val novelImage: String, | ||
| val novelRating: Float, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| package com.into.websoso.data.account.datasource | ||
|
|
||
| interface AccountLocalDataSource { | ||
| suspend fun accessToken(): String | ||
| suspend fun selectAccessToken(): String | ||
|
|
||
| suspend fun refreshToken(): String | ||
| suspend fun selectRefreshToken(): String | ||
|
|
||
| suspend fun saveAccessToken(accessToken: String) | ||
| suspend fun updateAccessToken(accessToken: String) | ||
|
|
||
| suspend fun saveRefreshToken(refreshToken: String) | ||
| suspend fun updateRefreshToken(refreshToken: String) | ||
|
|
||
| suspend fun clearTokens() | ||
| suspend fun deleteTokens() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| package com.into.websoso.data.library.datasource | ||
|
|
||
| interface LibraryLocalDataSource { | ||
| suspend fun getFullLibrary() | ||
| suspend fun selectAllNovels() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ include( | |
| ":core:auth-kakao", | ||
| ":core:network", | ||
| ":core:datastore", | ||
| ":core:database", | ||
| ) | ||
|
|
||
| include( | ||
|
|
||
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.
🚫 [ktlint] standard:no-unused-imports reported by reviewdog 🐶
Unused import