Skip to content

Commit

Permalink
feat/#60: Room 데이터베이스 및 관련 클래스 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jinukeu committed Jan 30, 2025
1 parent a720ec3 commit 18b376e
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 1 deletion.
4 changes: 4 additions & 0 deletions core/data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ dependencies {
implementation(libs.encrypted.datastore.preference.ksp.annotations)
implementation(libs.encrypted.datastore.preference.security)

ksp(libs.room.compiler)
implementation(libs.room.runtime)
implementation(libs.room.ktx)

implementation(libs.androidx.core.ktx)
implementation(libs.retrofit.core)
implementation(libs.retrofit.kotlin.serialization)
Expand Down
10 changes: 10 additions & 0 deletions core/data/src/main/java/com/yapp/core/data/data/SusuDispatcher.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.yapp.core.data.data

import javax.inject.Qualifier

@Qualifier
annotation class Dispatcher(val susuDispatcher: YappDispatchers)

enum class YappDispatchers {
IO,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.yapp.core.data.data.di

import com.yapp.core.data.data.Dispatcher
import com.yapp.core.data.data.YappDispatchers
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers

@Module
@InstallIn(SingletonComponent::class)
object DispatchersModule {
@Provides
@Dispatcher(YappDispatchers.IO)
fun providesIODispatcher(): CoroutineDispatcher = Dispatchers.IO
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.yapp.core.data.local

object EntityTable {
const val POSITION_CONFIG = "positions_configs"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.yapp.core.data.local

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Upsert

@Dao
interface PositionConfigDao {
@Query("SELECT * FROM ${EntityTable.POSITION_CONFIG}")
fun getPositionConfigs(): List<PositionConfigEntity>

@Upsert
fun upsertPositionConfigs(positionConfigs: List<PositionConfigEntity>)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.yapp.core.data.local

import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = EntityTable.POSITION_CONFIG)
data class PositionConfigEntity(
@PrimaryKey
val name: String,
val label: String,
)
14 changes: 14 additions & 0 deletions core/data/src/main/java/com/yapp/core/data/local/RoomDataBase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.yapp.core.data.local

import androidx.room.Database
import androidx.room.RoomDatabase

@Database(
entities = [
PositionConfigEntity::class,
],
version = 1,
)
abstract class RoomDataBase : RoomDatabase() {
abstract fun positionConfigDao(): PositionConfigDao
}
17 changes: 17 additions & 0 deletions core/data/src/main/java/com/yapp/core/data/local/di/DaoModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.yapp.core.data.local.di

import com.yapp.core.data.local.RoomDataBase
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object DaoModule {

@Singleton
@Provides
fun providePositionDao(db: RoomDataBase) = db.positionConfigDao()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.yapp.core.data.local
package com.yapp.core.data.local.di

import android.content.Context
import androidx.datastore.core.DataStore
Expand All @@ -7,6 +7,8 @@ import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.emptyPreferences
import androidx.datastore.preferences.preferencesDataStoreFile
import com.yapp.core.data.local.SecurityPreferences
import com.yapp.core.data.local.generateSecurityPreferences
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down
28 changes: 28 additions & 0 deletions core/data/src/main/java/com/yapp/core/data/local/di/RoomModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.yapp.core.data.local.di

import android.content.Context
import androidx.room.Room
import com.yapp.core.data.local.RoomDataBase
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)
object RoomModule {

private const val DB_NAME = "database-yapp"

@Provides
@Singleton
fun provideRoomDataBase(
@ApplicationContext context: Context,
) = Room.databaseBuilder(
context,
RoomDataBase::class.java,
DB_NAME,
).build()
}
5 changes: 5 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ encryptedDatastore = "1.9.25-1.0.20-1.2.0"
protobuf = "3.25.5"
protobufPlugin = "0.9.4"

room = "2.6.1"

[libraries]
android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "agp" }
Expand Down Expand Up @@ -82,6 +83,10 @@ encrypted-datastore-preference-security = { group = "tech.thdev", name = "useful
protobuf-kotlin-lite = { group = "com.google.protobuf", name = "protobuf-kotlin-lite", version.ref = "protobuf" }
protobuf-protoc = { group = "com.google.protobuf", name = "protoc", version.ref = "protobuf" }

room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
android-library = { id = "com.android.library", version.ref = "agp" }
Expand Down

0 comments on commit 18b376e

Please sign in to comment.