From 84ccc7a683ead6ced8abca47f1f096092a9fef16 Mon Sep 17 00:00:00 2001 From: stslex Date: Thu, 21 Sep 2023 23:14:15 +0300 Subject: [PATCH] refactor data base, add test --- .gitignore | 3 +- core/database/.gitignore | 1 + core/database/build.gradle.kts | 14 +++ core/database/consumer-rules.pro | 0 core/database/proguard-rules.pro | 21 ++++ .../core/database/ExampleInstrumentedTest.kt | 24 ++++ core/database/src/main/AndroidManifest.xml | 4 + .../core/database/AppDatabase.kt | 25 +++++ .../core/database/di/DatabaseApi.kt | 11 ++ .../core/database/di/DatabaseApiBuilder.kt | 14 +++ .../core/database/di/DatabaseComponent.kt | 18 +++ .../core/database/di/DatabaseDependencies.kt | 8 ++ .../di/DatabaseDependenciesComponent.kt | 15 +++ .../core/database/di/DatabaseModule.kt | 31 ++++++ .../core/database/favourite}/FavouriteDao.kt | 2 +- .../database/favourite}/FavouriteEntity.kt | 4 +- .../core/database/search}/SearchDao.kt | 2 +- .../core/database/search}/SearchEntity.kt | 2 +- .../core/database/FavouriteDaoTest.kt | 105 ++++++++++++++++++ .../core/database/SearchDaoTest.kt | 99 +++++++++++++++++ core/favourite/build.gradle.kts | 4 +- .../data/datasource/FavouriteDatabase.kt | 18 --- .../{repository => model}/FavouriteMapper.kt | 9 +- .../data/{repository => model}/JsonParser.kt | 2 +- .../repository/FavouriteRepositoryImpl.kt | 6 +- .../core/favourite/di/FavouriteApiBuilder.kt | 7 +- .../core/favourite/di/FavouriteComponent.kt | 15 +-- .../favourite/di/FavouriteDatabaseModule.kt | 24 ---- .../favourite/di/FavouriteDependencies.kt | 4 +- .../di/FavouriteDependenciesComponent.kt | 14 +++ fastlane/report.xml | 8 +- feature/search/build.gradle.kts | 4 +- .../data/{repository => }/SearchRepository.kt | 4 +- .../{repository => }/SearchRepositoryImpl.kt | 6 +- .../search/data/database/SearchDatabase.kt | 18 --- .../search/di/SearchPhotosComponent.kt | 22 +--- .../search/di/SearchPhotosComponentBuilder.kt | 7 +- .../search/di/SearchPhotosDependencies.kt | 4 +- .../di/SearchPhotosDependenciesComponent.kt | 20 ++++ .../feature/search/di/SearchPhotosModule.kt | 4 +- .../search/di/SearchPhotosProvideModule.kt | 24 ---- .../interactor/SearchPhotosInteractorImpl.kt | 4 +- .../search/domain/model/SearchMapper.kt | 2 +- gradle/libs.versions.toml | 7 ++ settings.gradle.kts | 1 + 45 files changed, 482 insertions(+), 159 deletions(-) create mode 100644 core/database/.gitignore create mode 100644 core/database/build.gradle.kts create mode 100644 core/database/consumer-rules.pro create mode 100644 core/database/proguard-rules.pro create mode 100644 core/database/src/androidTest/java/st/slex/csplashscreen/core/database/ExampleInstrumentedTest.kt create mode 100644 core/database/src/main/AndroidManifest.xml create mode 100644 core/database/src/main/java/st/slex/csplashscreen/core/database/AppDatabase.kt create mode 100644 core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseApi.kt create mode 100644 core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseApiBuilder.kt create mode 100644 core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseComponent.kt create mode 100644 core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseDependencies.kt create mode 100644 core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseDependenciesComponent.kt create mode 100644 core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseModule.kt rename core/{favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/datasource => database/src/main/java/st/slex/csplashscreen/core/database/favourite}/FavouriteDao.kt (92%) rename core/{favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/datasource => database/src/main/java/st/slex/csplashscreen/core/database/favourite}/FavouriteEntity.kt (89%) rename {feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/database => core/database/src/main/java/st/slex/csplashscreen/core/database/search}/SearchDao.kt (89%) rename {feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/database => core/database/src/main/java/st/slex/csplashscreen/core/database/search}/SearchEntity.kt (83%) create mode 100644 core/database/src/test/java/st/slex/csplashscreen/core/database/FavouriteDaoTest.kt create mode 100644 core/database/src/test/java/st/slex/csplashscreen/core/database/SearchDaoTest.kt delete mode 100644 core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/datasource/FavouriteDatabase.kt rename core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/{repository => model}/FavouriteMapper.kt (71%) rename core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/{repository => model}/JsonParser.kt (76%) delete mode 100644 core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteDatabaseModule.kt create mode 100644 core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteDependenciesComponent.kt rename feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/{repository => }/SearchRepository.kt (77%) rename feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/{repository => }/SearchRepositoryImpl.kt (88%) delete mode 100644 feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/database/SearchDatabase.kt create mode 100644 feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosDependenciesComponent.kt delete mode 100644 feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosProvideModule.kt diff --git a/.gitignore b/.gitignore index 2d8264d4..6a3af2d9 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ .cxx local.properties play_config.* -keystore.* \ No newline at end of file +keystore.* +Gemfile.lock \ No newline at end of file diff --git a/core/database/.gitignore b/core/database/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/core/database/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/core/database/build.gradle.kts b/core/database/build.gradle.kts new file mode 100644 index 00000000..5b5eee65 --- /dev/null +++ b/core/database/build.gradle.kts @@ -0,0 +1,14 @@ +plugins { + id("csplashscreen.android.library") +} + +android.namespace = "st.slex.csplashscreen.core.database" + +dependencies { + implementation(project(":core:core")) + implementation(libs.bundles.room) + annotationProcessor(libs.androidx.room.compiler) + ksp(libs.androidx.room.compiler) + implementation(libs.androidx.paging.runtime) + androidTestApi(libs.androidx.room.testing) +} \ No newline at end of file diff --git a/core/database/consumer-rules.pro b/core/database/consumer-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/core/database/proguard-rules.pro b/core/database/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/core/database/proguard-rules.pro @@ -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 \ No newline at end of file diff --git a/core/database/src/androidTest/java/st/slex/csplashscreen/core/database/ExampleInstrumentedTest.kt b/core/database/src/androidTest/java/st/slex/csplashscreen/core/database/ExampleInstrumentedTest.kt new file mode 100644 index 00000000..d4b62e63 --- /dev/null +++ b/core/database/src/androidTest/java/st/slex/csplashscreen/core/database/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package st.slex.csplashscreen.core.database + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("st.slex.csplashscreen.core.database.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/core/database/src/main/AndroidManifest.xml b/core/database/src/main/AndroidManifest.xml new file mode 100644 index 00000000..a5918e68 --- /dev/null +++ b/core/database/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/core/database/src/main/java/st/slex/csplashscreen/core/database/AppDatabase.kt b/core/database/src/main/java/st/slex/csplashscreen/core/database/AppDatabase.kt new file mode 100644 index 00000000..61e9c78b --- /dev/null +++ b/core/database/src/main/java/st/slex/csplashscreen/core/database/AppDatabase.kt @@ -0,0 +1,25 @@ +package st.slex.csplashscreen.core.database + +import androidx.room.Database +import androidx.room.RoomDatabase +import st.slex.csplashscreen.core.database.favourite.FavouriteDao +import st.slex.csplashscreen.core.database.favourite.FavouriteEntity +import st.slex.csplashscreen.core.database.search.SearchDao +import st.slex.csplashscreen.core.database.search.SearchEntity + +@Database( + entities = [SearchEntity::class, FavouriteEntity::class], + version = 1, + exportSchema = false +) +abstract class AppDatabase : RoomDatabase() { + + abstract val favouriteDao: FavouriteDao + + abstract val searchDao: SearchDao + + companion object { + val NAME = "app.db" + } +} + diff --git a/core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseApi.kt b/core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseApi.kt new file mode 100644 index 00000000..b936c6ef --- /dev/null +++ b/core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseApi.kt @@ -0,0 +1,11 @@ +package st.slex.csplashscreen.core.database.di + +import st.slex.csplashscreen.core.database.favourite.FavouriteDao +import st.slex.csplashscreen.core.database.search.SearchDao + +interface DatabaseApi { + + val searchDao: SearchDao + + val favouriteDao: FavouriteDao +} \ No newline at end of file diff --git a/core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseApiBuilder.kt b/core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseApiBuilder.kt new file mode 100644 index 00000000..ac0315d6 --- /dev/null +++ b/core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseApiBuilder.kt @@ -0,0 +1,14 @@ +package st.slex.csplashscreen.core.database.di + +import st.slex.csplashscreen.core.core.AppApi + +object DatabaseApiBuilder { + + fun build(appApi: AppApi): DatabaseApi = DaggerDatabaseComponent + .factory() + .create( + dependencies = DaggerDatabaseDependenciesComponent + .factory() + .create(appApi) + ) +} \ No newline at end of file diff --git a/core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseComponent.kt b/core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseComponent.kt new file mode 100644 index 00000000..fc71786b --- /dev/null +++ b/core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseComponent.kt @@ -0,0 +1,18 @@ +package st.slex.csplashscreen.core.database.di + +import dagger.Component +import javax.inject.Singleton + +@Component( + dependencies = [DatabaseDependencies::class], + modules = [DatabaseModule::class] +) +@Singleton +interface DatabaseComponent : DatabaseApi { + + @Component.Factory + interface Factory { + fun create(dependencies: DatabaseDependencies): DatabaseApi + } +} + diff --git a/core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseDependencies.kt b/core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseDependencies.kt new file mode 100644 index 00000000..bd826677 --- /dev/null +++ b/core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseDependencies.kt @@ -0,0 +1,8 @@ +package st.slex.csplashscreen.core.database.di + +import android.content.Context + +interface DatabaseDependencies { + + val context: Context +} \ No newline at end of file diff --git a/core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseDependenciesComponent.kt b/core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseDependenciesComponent.kt new file mode 100644 index 00000000..049aa7a7 --- /dev/null +++ b/core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseDependenciesComponent.kt @@ -0,0 +1,15 @@ +package st.slex.csplashscreen.core.database.di + +import dagger.Component +import st.slex.csplashscreen.core.core.AppApi +import javax.inject.Singleton + +@Component(dependencies = [AppApi::class]) +@Singleton +interface DatabaseDependenciesComponent : DatabaseDependencies { + + @Component.Factory + interface Factory { + fun create(appApi: AppApi): DatabaseDependencies + } +} \ No newline at end of file diff --git a/core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseModule.kt b/core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseModule.kt new file mode 100644 index 00000000..1537e880 --- /dev/null +++ b/core/database/src/main/java/st/slex/csplashscreen/core/database/di/DatabaseModule.kt @@ -0,0 +1,31 @@ +package st.slex.csplashscreen.core.database.di + +import android.content.Context +import androidx.room.Room +import dagger.Module +import dagger.Provides +import st.slex.csplashscreen.core.database.AppDatabase +import st.slex.csplashscreen.core.database.favourite.FavouriteDao +import st.slex.csplashscreen.core.database.search.SearchDao +import javax.inject.Singleton + +@Module +class DatabaseModule { + + @Provides + @Singleton + fun provideDatabase(context: Context): AppDatabase = Room.databaseBuilder( + context, + AppDatabase::class.java, + AppDatabase.NAME + ) + .build() + + @Provides + @Singleton + fun provideSearchDao(database: AppDatabase): SearchDao = database.searchDao + + @Provides + @Singleton + fun providesFavouriteDao(database: AppDatabase): FavouriteDao = database.favouriteDao +} \ No newline at end of file diff --git a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/datasource/FavouriteDao.kt b/core/database/src/main/java/st/slex/csplashscreen/core/database/favourite/FavouriteDao.kt similarity index 92% rename from core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/datasource/FavouriteDao.kt rename to core/database/src/main/java/st/slex/csplashscreen/core/database/favourite/FavouriteDao.kt index 9f50ce25..28119313 100644 --- a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/datasource/FavouriteDao.kt +++ b/core/database/src/main/java/st/slex/csplashscreen/core/database/favourite/FavouriteDao.kt @@ -1,4 +1,4 @@ -package st.slex.csplashscreen.core.favourite.data.datasource +package st.slex.csplashscreen.core.database.favourite import androidx.paging.PagingSource import androidx.room.Dao diff --git a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/datasource/FavouriteEntity.kt b/core/database/src/main/java/st/slex/csplashscreen/core/database/favourite/FavouriteEntity.kt similarity index 89% rename from core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/datasource/FavouriteEntity.kt rename to core/database/src/main/java/st/slex/csplashscreen/core/database/favourite/FavouriteEntity.kt index 362ba4c4..67d4cbcf 100644 --- a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/datasource/FavouriteEntity.kt +++ b/core/database/src/main/java/st/slex/csplashscreen/core/database/favourite/FavouriteEntity.kt @@ -1,4 +1,4 @@ -package st.slex.csplashscreen.core.favourite.data.datasource +package st.slex.csplashscreen.core.database.favourite import androidx.room.ColumnInfo import androidx.room.Entity @@ -19,4 +19,4 @@ data class FavouriteEntity( val downloadUrl: String, @ColumnInfo(name = "tags") val tags: String, -) +) \ No newline at end of file diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/database/SearchDao.kt b/core/database/src/main/java/st/slex/csplashscreen/core/database/search/SearchDao.kt similarity index 89% rename from feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/database/SearchDao.kt rename to core/database/src/main/java/st/slex/csplashscreen/core/database/search/SearchDao.kt index 1ab234a0..cde802d9 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/database/SearchDao.kt +++ b/core/database/src/main/java/st/slex/csplashscreen/core/database/search/SearchDao.kt @@ -1,4 +1,4 @@ -package st.slex.csplashscreen.feature.search.data.database +package st.slex.csplashscreen.core.database.search import androidx.paging.PagingSource import androidx.room.Dao diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/database/SearchEntity.kt b/core/database/src/main/java/st/slex/csplashscreen/core/database/search/SearchEntity.kt similarity index 83% rename from feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/database/SearchEntity.kt rename to core/database/src/main/java/st/slex/csplashscreen/core/database/search/SearchEntity.kt index 40c2b7c4..5b968b22 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/database/SearchEntity.kt +++ b/core/database/src/main/java/st/slex/csplashscreen/core/database/search/SearchEntity.kt @@ -1,4 +1,4 @@ -package st.slex.csplashscreen.feature.search.data.database +package st.slex.csplashscreen.core.database.search import androidx.room.ColumnInfo import androidx.room.Entity diff --git a/core/database/src/test/java/st/slex/csplashscreen/core/database/FavouriteDaoTest.kt b/core/database/src/test/java/st/slex/csplashscreen/core/database/FavouriteDaoTest.kt new file mode 100644 index 00000000..fe1da01d --- /dev/null +++ b/core/database/src/test/java/st/slex/csplashscreen/core/database/FavouriteDaoTest.kt @@ -0,0 +1,105 @@ +package st.slex.csplashscreen.core.database + +import android.content.Context +import androidx.paging.PagingSource +import androidx.room.Room +import androidx.test.core.app.ApplicationProvider +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.cancellable +import kotlinx.coroutines.flow.firstOrNull +import kotlinx.coroutines.runBlocking +import org.junit.AfterClass +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config +import st.slex.csplashscreen.core.database.favourite.FavouriteDao +import st.slex.csplashscreen.core.database.favourite.FavouriteEntity +import java.util.UUID + +@RunWith(RobolectricTestRunner::class) +@Config(manifest = Config.NONE) +class FavouriteDaoTest { + + private val dao: FavouriteDao + + init { + val context: Context = ApplicationProvider.getApplicationContext() + database = Room + .databaseBuilder(context, AppDatabase::class.java, AppDatabase.NAME) + .build() + dao = database.favouriteDao + } + + @Test + fun `add single item to db`() = runBlocking(Dispatchers.IO) { + val expected = generateRandomItem() + dao.add(expected) + val actual = dao.getItem(expected.uuid) + Assert.assertEquals(expected, actual) + } + + @Test + fun `remove item from db`() = runBlocking(Dispatchers.IO) { + val expected = generateRandomItem() + dao.add(expected) + val actual = dao.getItem(expected.uuid) + Assert.assertEquals(expected, actual) + dao.remove(expected.uuid) + val actualRemoved = dao.getItem(expected.uuid) + Assert.assertNull(actualRemoved) + } + + @Test + fun `get flow items`() = runBlocking(Dispatchers.IO) { + val expected = generateRandomItem() + dao.add(expected) + val actual = dao.getFlow(expected.uuid) + .cancellable() + .firstOrNull() + Assert.assertEquals(expected, actual) + } + + @Test + fun `get paging items`() = runBlocking(Dispatchers.IO) { + val insertItemSize = 10 + val pageLoadSize = 15 + repeat(insertItemSize) { + val expected = generateRandomItem() + dao.add(expected) + } + val loadResult = dao.getAll().load( + PagingSource.LoadParams.Refresh( + key = null, + loadSize = pageLoadSize, + placeholdersEnabled = false + ) + ) + val actual = (loadResult as? PagingSource.LoadResult.Page)?.data + Assert.assertNotNull(actual) + Assert.assertTrue(actual!!.size in insertItemSize..pageLoadSize) + } + + private fun generateRandomItem(): FavouriteEntity = UUID.randomUUID().toString() + .let { uuid -> + FavouriteEntity( + uuid = uuid, + url = "url_$uuid", + username = "username_$uuid", + userUrl = "user_url_$uuid", + downloadUrl = "download_url_$uuid", + tags = "tags_$uuid", + ) + } + + companion object { + private lateinit var database: AppDatabase + + @AfterClass + @JvmStatic + fun afterTestsEnd() { + database.close() + } + } +} \ No newline at end of file diff --git a/core/database/src/test/java/st/slex/csplashscreen/core/database/SearchDaoTest.kt b/core/database/src/test/java/st/slex/csplashscreen/core/database/SearchDaoTest.kt new file mode 100644 index 00000000..49660458 --- /dev/null +++ b/core/database/src/test/java/st/slex/csplashscreen/core/database/SearchDaoTest.kt @@ -0,0 +1,99 @@ +package st.slex.csplashscreen.core.database + +import android.content.Context +import androidx.paging.PagingSource +import androidx.room.Room +import androidx.test.core.app.ApplicationProvider +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.runBlocking +import org.junit.AfterClass +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config +import st.slex.csplashscreen.core.database.search.SearchDao +import st.slex.csplashscreen.core.database.search.SearchEntity +import java.util.UUID + +@RunWith(RobolectricTestRunner::class) +@Config(manifest = Config.NONE) +class SearchDaoTest { + + private val dao: SearchDao + + init { + val context: Context = ApplicationProvider.getApplicationContext() + database = Room + .databaseBuilder(context, AppDatabase::class.java, AppDatabase.NAME) + .build() + dao = database.searchDao + } + + @Test + fun `add single item`() = runBlocking(Dispatchers.IO) { + val expected = generateUniqueItem() + dao.clear() + dao.addSearch(expected) + val loadResult = dao.getAllSearch().load( + PagingSource.LoadParams.Refresh( + key = null, + loadSize = 10, + placeholdersEnabled = false + ) + ) + val actual = (loadResult as? PagingSource.LoadResult.Page)?.data?.firstOrNull() + Assert.assertEquals(expected, actual) + } + + @Test + fun `remove all items`() = runBlocking(Dispatchers.IO) { + repeat(10) { + val expected = generateUniqueItem() + dao.addSearch(expected) + } + val loadPreResult = dao.getAllSearch() + .load( + PagingSource.LoadParams.Refresh( + key = null, + loadSize = 10, + placeholdersEnabled = false + ) + ) + .let { + (it as? PagingSource.LoadResult.Page)?.data.orEmpty() + } + Assert.assertTrue(loadPreResult.isNotEmpty()) + + dao.clear() + + val loadResult = dao.getAllSearch() + .load( + PagingSource.LoadParams.Refresh( + key = null, + loadSize = 10, + placeholdersEnabled = false + ) + ) + .let { + (it as? PagingSource.LoadResult.Page)?.data + } + + Assert.assertTrue(loadResult?.isEmpty() ?: false) + } + + private fun generateUniqueItem() = SearchEntity( + query = UUID.randomUUID().toString(), + timestamp = System.currentTimeMillis() + ) + + companion object { + private lateinit var database: AppDatabase + + @AfterClass + @JvmStatic + fun afterTestsEnd() { + database.close() + } + } +} \ No newline at end of file diff --git a/core/favourite/build.gradle.kts b/core/favourite/build.gradle.kts index d1150f4c..c4e8fbf0 100644 --- a/core/favourite/build.gradle.kts +++ b/core/favourite/build.gradle.kts @@ -5,11 +5,9 @@ plugins { dependencies { implementation(project(":core:core")) + implementation(project(":core:database")) implementation(project(":core:photos")) - implementation(libs.bundles.room) - annotationProcessor(libs.androidx.room.compiler) - ksp(libs.androidx.room.compiler) implementation(libs.androidx.paging.runtime) implementation("com.google.code.gson:gson:2.10.1") } diff --git a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/datasource/FavouriteDatabase.kt b/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/datasource/FavouriteDatabase.kt deleted file mode 100644 index 1b5724f1..00000000 --- a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/datasource/FavouriteDatabase.kt +++ /dev/null @@ -1,18 +0,0 @@ -package st.slex.csplashscreen.core.favourite.data.datasource - -import androidx.room.Database -import androidx.room.RoomDatabase - -@Database( - entities = [FavouriteEntity::class], - version = 1, - exportSchema = false -) -abstract class FavouriteDatabase : RoomDatabase() { - - abstract val dao: FavouriteDao - - companion object { - const val NAME = "db.favourite" - } -} \ No newline at end of file diff --git a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/repository/FavouriteMapper.kt b/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/model/FavouriteMapper.kt similarity index 71% rename from core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/repository/FavouriteMapper.kt rename to core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/model/FavouriteMapper.kt index 70d20cf0..d0c87e43 100644 --- a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/repository/FavouriteMapper.kt +++ b/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/model/FavouriteMapper.kt @@ -1,10 +1,10 @@ -package st.slex.csplashscreen.core.favourite.data.repository +package st.slex.csplashscreen.core.favourite.data.model import androidx.paging.PagingData import androidx.paging.map -import st.slex.csplashscreen.core.favourite.data.datasource.FavouriteEntity -import st.slex.csplashscreen.core.favourite.data.repository.JsonParser.parse -import st.slex.csplashscreen.core.favourite.data.repository.JsonParser.toJson +import st.slex.csplashscreen.core.database.favourite.FavouriteEntity +import st.slex.csplashscreen.core.favourite.data.model.JsonParser.parse +import st.slex.csplashscreen.core.favourite.data.model.JsonParser.toJson import st.slex.csplashscreen.core.photos.ui.model.PhotoModel object FavouriteMapper { @@ -31,4 +31,3 @@ object FavouriteMapper { entity.toDomain() } } - diff --git a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/repository/JsonParser.kt b/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/model/JsonParser.kt similarity index 76% rename from core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/repository/JsonParser.kt rename to core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/model/JsonParser.kt index 97f58b05..4d20f700 100644 --- a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/repository/JsonParser.kt +++ b/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/model/JsonParser.kt @@ -1,4 +1,4 @@ -package st.slex.csplashscreen.core.favourite.data.repository +package st.slex.csplashscreen.core.favourite.data.model import com.google.gson.Gson diff --git a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/repository/FavouriteRepositoryImpl.kt b/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/repository/FavouriteRepositoryImpl.kt index d7d1386b..3b1c6a99 100644 --- a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/repository/FavouriteRepositoryImpl.kt +++ b/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/data/repository/FavouriteRepositoryImpl.kt @@ -8,9 +8,9 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import kotlinx.coroutines.withContext -import st.slex.csplashscreen.core.favourite.data.datasource.FavouriteDao -import st.slex.csplashscreen.core.favourite.data.repository.FavouriteMapper.toDomain -import st.slex.csplashscreen.core.favourite.data.repository.FavouriteMapper.toEntity +import st.slex.csplashscreen.core.database.favourite.FavouriteDao +import st.slex.csplashscreen.core.favourite.data.model.FavouriteMapper.toDomain +import st.slex.csplashscreen.core.favourite.data.model.FavouriteMapper.toEntity import st.slex.csplashscreen.core.photos.ui.model.PhotoModel import javax.inject.Inject import javax.inject.Singleton diff --git a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteApiBuilder.kt b/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteApiBuilder.kt index b2c032a9..d01a2554 100644 --- a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteApiBuilder.kt +++ b/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteApiBuilder.kt @@ -1,6 +1,7 @@ package st.slex.csplashscreen.core.favourite.di import st.slex.csplashscreen.core.core.AppApi +import st.slex.csplashscreen.core.database.di.DatabaseApiBuilder object FavouriteApiBuilder { @@ -9,8 +10,10 @@ object FavouriteApiBuilder { ): FavouriteApi = DaggerFavouriteComponent .factory() .create( - dependencies = DaggerFavouriteComponent_FavouriteDependenciesComponent + dependencies = DaggerFavouriteDependenciesComponent .factory() - .create(appApi) + .create( + databaseApi = DatabaseApiBuilder.build(appApi) + ) ) } \ No newline at end of file diff --git a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteComponent.kt b/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteComponent.kt index 8919d88b..b16e536c 100644 --- a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteComponent.kt +++ b/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteComponent.kt @@ -1,11 +1,10 @@ package st.slex.csplashscreen.core.favourite.di import dagger.Component -import st.slex.csplashscreen.core.core.AppApi import javax.inject.Singleton @Component( - modules = [FavouriteModule::class, FavouriteDatabaseModule::class], + modules = [FavouriteModule::class], dependencies = [FavouriteDependencies::class] ) @Singleton @@ -16,14 +15,4 @@ interface FavouriteComponent : FavouriteApi { fun create(dependencies: FavouriteDependencies): FavouriteApi } - - @Component(dependencies = [AppApi::class]) - interface FavouriteDependenciesComponent : FavouriteDependencies { - - @Component.Factory - interface Factory { - - fun create(appApi: AppApi): FavouriteDependencies - } - } -} \ No newline at end of file +} diff --git a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteDatabaseModule.kt b/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteDatabaseModule.kt deleted file mode 100644 index 01077de9..00000000 --- a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteDatabaseModule.kt +++ /dev/null @@ -1,24 +0,0 @@ -package st.slex.csplashscreen.core.favourite.di - -import android.content.Context -import androidx.room.Room -import dagger.Module -import dagger.Provides -import st.slex.csplashscreen.core.favourite.data.datasource.FavouriteDao -import st.slex.csplashscreen.core.favourite.data.datasource.FavouriteDatabase -import javax.inject.Singleton - -@Module -class FavouriteDatabaseModule { - - @Provides - @Singleton - fun provideDao(context: Context): FavouriteDao = Room - .databaseBuilder( - context, - FavouriteDatabase::class.java, - FavouriteDatabase.NAME - ) - .build() - .dao -} \ No newline at end of file diff --git a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteDependencies.kt b/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteDependencies.kt index e5a7853b..5042df80 100644 --- a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteDependencies.kt +++ b/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteDependencies.kt @@ -1,8 +1,8 @@ package st.slex.csplashscreen.core.favourite.di -import android.content.Context +import st.slex.csplashscreen.core.database.favourite.FavouriteDao interface FavouriteDependencies { - val context: Context + val favouriteDao: FavouriteDao } \ No newline at end of file diff --git a/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteDependenciesComponent.kt b/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteDependenciesComponent.kt new file mode 100644 index 00000000..4c08faea --- /dev/null +++ b/core/favourite/src/main/java/st/slex/csplashscreen/core/favourite/di/FavouriteDependenciesComponent.kt @@ -0,0 +1,14 @@ +package st.slex.csplashscreen.core.favourite.di + +import dagger.Component +import st.slex.csplashscreen.core.database.di.DatabaseApi + +@Component(dependencies = [DatabaseApi::class]) +interface FavouriteDependenciesComponent : FavouriteDependencies { + + @Component.Factory + interface Factory { + + fun create(databaseApi: DatabaseApi): FavouriteDependencies + } +} \ No newline at end of file diff --git a/fastlane/report.xml b/fastlane/report.xml index 42922753..a509e063 100644 --- a/fastlane/report.xml +++ b/fastlane/report.xml @@ -5,17 +5,19 @@ - + - + - + + + diff --git a/feature/search/build.gradle.kts b/feature/search/build.gradle.kts index c5829598..70df7840 100644 --- a/feature/search/build.gradle.kts +++ b/feature/search/build.gradle.kts @@ -10,10 +10,8 @@ dependencies { implementation(project(":core:navigation")) implementation(project(":core:network")) implementation(project(":core:photos")) + implementation(project(":core:database")) - implementation(libs.bundles.room) - annotationProcessor(libs.androidx.room.compiler) - ksp(libs.androidx.room.compiler) implementation(libs.androidx.paging.runtime) } diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/repository/SearchRepository.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/SearchRepository.kt similarity index 77% rename from feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/repository/SearchRepository.kt rename to feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/SearchRepository.kt index c13159ed..3177e9ed 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/repository/SearchRepository.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/SearchRepository.kt @@ -1,9 +1,9 @@ -package st.slex.csplashscreen.feature.search.data.repository +package st.slex.csplashscreen.feature.search.data import androidx.paging.PagingData import kotlinx.coroutines.flow.Flow +import st.slex.csplashscreen.core.database.search.SearchEntity import st.slex.csplashscreen.core.network.model.remote.image.RemoteImageModel -import st.slex.csplashscreen.feature.search.data.database.SearchEntity interface SearchRepository { diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/repository/SearchRepositoryImpl.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/SearchRepositoryImpl.kt similarity index 88% rename from feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/repository/SearchRepositoryImpl.kt rename to feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/SearchRepositoryImpl.kt index 61ad5bbf..6bbe0e33 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/repository/SearchRepositoryImpl.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/SearchRepositoryImpl.kt @@ -1,4 +1,4 @@ -package st.slex.csplashscreen.feature.search.data.repository +package st.slex.csplashscreen.feature.search.data import androidx.paging.Pager import androidx.paging.PagingConfig @@ -7,10 +7,10 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.withContext +import st.slex.csplashscreen.core.database.search.SearchDao +import st.slex.csplashscreen.core.database.search.SearchEntity import st.slex.csplashscreen.core.network.model.remote.image.RemoteImageModel import st.slex.csplashscreen.core.network.source.interf.SearchPhotosNetworkSource -import st.slex.csplashscreen.feature.search.data.database.SearchDao -import st.slex.csplashscreen.feature.search.data.database.SearchEntity import javax.inject.Inject class SearchRepositoryImpl @Inject constructor( diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/database/SearchDatabase.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/database/SearchDatabase.kt deleted file mode 100644 index a6476636..00000000 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/data/database/SearchDatabase.kt +++ /dev/null @@ -1,18 +0,0 @@ -package st.slex.csplashscreen.feature.search.data.database - -import androidx.room.Database -import androidx.room.RoomDatabase - -@Database( - entities = [SearchEntity::class], - version = 1, - exportSchema = false -) -abstract class SearchDatabase : RoomDatabase() { - - abstract val dao: SearchDao - - companion object { - const val NAME = "search.db" - } -} \ No newline at end of file diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponent.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponent.kt index 180d7cab..40e301ad 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponent.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponent.kt @@ -2,13 +2,10 @@ package st.slex.csplashscreen.feature.search.di import androidx.lifecycle.ViewModelProvider import dagger.Component -import st.slex.csplashscreen.core.core.AppApi -import st.slex.csplashscreen.core.network.di.NetworkClientApi -import st.slex.csplashscreen.core.ui.di.NavigationApi @Component( dependencies = [SearchPhotosDependencies::class], - modules = [SearchPhotosModule::class, SearchPhotosProvideModule::class] + modules = [SearchPhotosModule::class] ) @SearchPhotosScope interface SearchPhotosComponent { @@ -18,19 +15,6 @@ interface SearchPhotosComponent { fun create(dependencies: SearchPhotosDependencies): SearchPhotosComponent } - @Component(dependencies = [AppApi::class, NavigationApi::class, NetworkClientApi::class]) - @SearchPhotosScope - interface SearchPhotosDependenciesComponent : SearchPhotosDependencies { - - @Component.Factory - interface Factory { - fun create( - appApi: AppApi, - navigationApi: NavigationApi, - networkClientApi: NetworkClientApi - ): SearchPhotosDependencies - } - } - val viewModelFactory: ViewModelProvider.Factory -} \ No newline at end of file +} + diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponentBuilder.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponentBuilder.kt index f1029ece..53af73b3 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponentBuilder.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosComponentBuilder.kt @@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.platform.LocalContext import st.slex.csplashscreen.core.core.AppApi import st.slex.csplashscreen.core.core.appApi +import st.slex.csplashscreen.core.database.di.DatabaseApiBuilder import st.slex.csplashscreen.core.network.di.NetworkApiBuilder import st.slex.csplashscreen.core.ui.base.daggerViewModel import st.slex.csplashscreen.core.ui.di.NavigationApi @@ -18,10 +19,10 @@ object SearchPhotosComponentBuilder { ): SearchPhotosComponent = DaggerSearchPhotosComponent .factory() .create( - dependencies = DaggerSearchPhotosComponent_SearchPhotosDependenciesComponent + dependencies = DaggerSearchPhotosDependenciesComponent .factory() .create( - appApi = appApi, + databaseApi = DatabaseApiBuilder.build(appApi), navigationApi = navigationApi, networkClientApi = NetworkApiBuilder.build() ) @@ -31,7 +32,7 @@ object SearchPhotosComponentBuilder { @Composable fun setupSearchPhotosComponent(key: String): SearchViewModel { val context = LocalContext.current - return daggerViewModel { + return daggerViewModel(key) { SearchPhotosComponentBuilder .build(context.appApi, context.navigationApi) .viewModelFactory diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosDependencies.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosDependencies.kt index 53a28e35..525d30aa 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosDependencies.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosDependencies.kt @@ -1,12 +1,12 @@ package st.slex.csplashscreen.feature.search.di -import android.content.Context +import st.slex.csplashscreen.core.database.search.SearchDao import st.slex.csplashscreen.core.network.source.interf.SearchPhotosNetworkSource import st.slex.csplashscreen.core.ui.di.Navigator interface SearchPhotosDependencies { - val context: Context + val searchDao: SearchDao val navigator: Navigator diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosDependenciesComponent.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosDependenciesComponent.kt new file mode 100644 index 00000000..42b545d2 --- /dev/null +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosDependenciesComponent.kt @@ -0,0 +1,20 @@ +package st.slex.csplashscreen.feature.search.di + +import dagger.Component +import st.slex.csplashscreen.core.database.di.DatabaseApi +import st.slex.csplashscreen.core.network.di.NetworkClientApi +import st.slex.csplashscreen.core.ui.di.NavigationApi + +@Component(dependencies = [DatabaseApi::class, NavigationApi::class, NetworkClientApi::class]) +@SearchPhotosScope +interface SearchPhotosDependenciesComponent : SearchPhotosDependencies { + + @Component.Factory + interface Factory { + fun create( + databaseApi: DatabaseApi, + navigationApi: NavigationApi, + networkClientApi: NetworkClientApi + ): SearchPhotosDependencies + } +} \ No newline at end of file diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosModule.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosModule.kt index 26303682..5c97c5bf 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosModule.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosModule.kt @@ -7,8 +7,8 @@ import dagger.Binds import dagger.Module import dagger.multibindings.IntoMap import st.slex.csplashscreen.core.ui.di.ViewModelKey -import st.slex.csplashscreen.feature.search.data.repository.SearchRepository -import st.slex.csplashscreen.feature.search.data.repository.SearchRepositoryImpl +import st.slex.csplashscreen.feature.search.data.SearchRepository +import st.slex.csplashscreen.feature.search.data.SearchRepositoryImpl import st.slex.csplashscreen.feature.search.domain.interactor.SearchPhotosInteractor import st.slex.csplashscreen.feature.search.domain.interactor.SearchPhotosInteractorImpl import st.slex.csplashscreen.feature.search.navigation.SearchPhotosRouter diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosProvideModule.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosProvideModule.kt deleted file mode 100644 index df0f9883..00000000 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/di/SearchPhotosProvideModule.kt +++ /dev/null @@ -1,24 +0,0 @@ -package st.slex.csplashscreen.feature.search.di - -import android.content.Context -import androidx.room.Room -import dagger.Module -import dagger.Provides -import st.slex.csplashscreen.feature.search.data.database.SearchDao -import st.slex.csplashscreen.feature.search.data.database.SearchDatabase - -@Module -class SearchPhotosProvideModule { - - @Provides - @SearchPhotosScope - fun providesDao( - context: Context - ): SearchDao = Room.databaseBuilder( - context, - SearchDatabase::class.java, - SearchDatabase.NAME - ) - .build() - .dao -} \ No newline at end of file diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/domain/interactor/SearchPhotosInteractorImpl.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/domain/interactor/SearchPhotosInteractorImpl.kt index 3fdbf9da..a918aa94 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/domain/interactor/SearchPhotosInteractorImpl.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/domain/interactor/SearchPhotosInteractorImpl.kt @@ -9,10 +9,10 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import kotlinx.coroutines.withContext +import st.slex.csplashscreen.core.database.search.SearchEntity import st.slex.csplashscreen.core.network.model.toDomain import st.slex.csplashscreen.core.network.model.ui.ImageModel -import st.slex.csplashscreen.feature.search.data.database.SearchEntity -import st.slex.csplashscreen.feature.search.data.repository.SearchRepository +import st.slex.csplashscreen.feature.search.data.SearchRepository import st.slex.csplashscreen.feature.search.domain.model.SearchMapper.toPresentation import st.slex.csplashscreen.feature.search.ui.model.SearchItem import javax.inject.Inject diff --git a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/domain/model/SearchMapper.kt b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/domain/model/SearchMapper.kt index 2a0d557f..fc0bf699 100644 --- a/feature/search/src/main/java/st/slex/csplashscreen/feature/search/domain/model/SearchMapper.kt +++ b/feature/search/src/main/java/st/slex/csplashscreen/feature/search/domain/model/SearchMapper.kt @@ -1,6 +1,6 @@ package st.slex.csplashscreen.feature.search.domain.model -import st.slex.csplashscreen.feature.search.data.database.SearchEntity +import st.slex.csplashscreen.core.database.search.SearchEntity import st.slex.csplashscreen.feature.search.ui.model.SearchItem import java.time.Instant import java.time.OffsetDateTime diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 30179a1b..5c527a55 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -22,6 +22,8 @@ okhttp3 = "4.11.0" junit = "4.13.2" androidxJunit = "1.1.5" espresso = "3.5.1" +robolectric = "4.9" +androidxTest = "1.5.0" room = "2.5.2" ksp = "1.9.0-1.0.13" @@ -85,11 +87,14 @@ junit = { group = "junit", name = "junit", version.ref = "junit" } mockito = { group = "org.mockito", name = "mockito-core", version.ref = "mockito" } androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidxJunit" } androidx-espresso = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espresso" } +robolectric = { group = "org.robolectric", name = "robolectric", version.ref = "robolectric" } +androidx-test = { group = "androidx.test", name = "core-ktx", version.ref = "androidxTest" } androidx-room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" } androidx-room-paging = { group = "androidx.room", name = "room-paging", version.ref = "room" } androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" } androidx-room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" } +androidx-room-testing = { group = "androidx.room", name = "room-testing", version.ref = "room" } dagger-core = { group = "com.google.dagger", name = "dagger", version.ref = "dagger" } dagger-compiler = { group = "com.google.dagger", name = "dagger-compiler", version.ref = "dagger" } @@ -149,6 +154,8 @@ android-test = [ test = [ "mockito", "junit", + "robolectric", + "androidx-test" ] room = [ diff --git a/settings.gradle.kts b/settings.gradle.kts index ce634951..e08cf90b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -34,3 +34,4 @@ include(":feature:photo-detail") include(":feature:search") include(":feature:favourite") include(":core:favourite") +include(":core:database")