diff --git a/app/src/main/java/gq/kirmanak/mealient/data/recipes/db/RecipeStorageImpl.kt b/app/src/main/java/gq/kirmanak/mealient/data/recipes/db/RecipeStorageImpl.kt index 8f5224e..de086fc 100644 --- a/app/src/main/java/gq/kirmanak/mealient/data/recipes/db/RecipeStorageImpl.kt +++ b/app/src/main/java/gq/kirmanak/mealient/data/recipes/db/RecipeStorageImpl.kt @@ -6,7 +6,8 @@ import gq.kirmanak.mealient.data.recipes.network.FullRecipeInfo import gq.kirmanak.mealient.data.recipes.network.RecipeSummaryInfo import gq.kirmanak.mealient.database.AppDb import gq.kirmanak.mealient.database.recipe.RecipeDao -import gq.kirmanak.mealient.database.recipe.entity.* +import gq.kirmanak.mealient.database.recipe.entity.FullRecipeEntity +import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity import gq.kirmanak.mealient.extensions.recipeEntity import gq.kirmanak.mealient.extensions.toRecipeEntity import gq.kirmanak.mealient.extensions.toRecipeIngredientEntity @@ -27,67 +28,10 @@ class RecipeStorageImpl @Inject constructor( ) = db.withTransaction { logger.v { "saveRecipes() called with $recipes" } - val tagEntities = mutableSetOf() - tagEntities.addAll(recipeDao.queryAllTags()) - - val categoryEntities = mutableSetOf() - categoryEntities.addAll(recipeDao.queryAllCategories()) - - val tagRecipeEntities = mutableSetOf() - val categoryRecipeEntities = mutableSetOf() - for (recipe in recipes) { val recipeSummaryEntity = recipe.recipeEntity() recipeDao.insertRecipe(recipeSummaryEntity) - - for (tag in recipe.tags) { - val tagId = getIdOrInsert(tagEntities, tag) - tagRecipeEntities += TagRecipeEntity(tagId, recipeSummaryEntity.remoteId) - } - - for (category in recipe.recipeCategories) { - val categoryId = getOrInsert(categoryEntities, category) - categoryRecipeEntities += CategoryRecipeEntity( - categoryId, - recipeSummaryEntity.remoteId - ) - } } - - recipeDao.insertTagRecipeEntities(tagRecipeEntities) - recipeDao.insertCategoryRecipeEntities(categoryRecipeEntities) - } - - private suspend fun getOrInsert( - categoryEntities: MutableSet, - category: String - ): Long { - val existingCategory = categoryEntities.find { it.name == category } - val categoryId = if (existingCategory == null) { - val categoryEntity = CategoryEntity(name = category) - val newId = recipeDao.insertCategory(categoryEntity) - categoryEntities.add(categoryEntity.copy(localId = newId)) - newId - } else { - existingCategory.localId - } - return categoryId - } - - private suspend fun getIdOrInsert( - tagEntities: MutableSet, - tag: String - ): Long { - val existingTag = tagEntities.find { it.name == tag } - val tagId = if (existingTag == null) { - val tagEntity = TagEntity(name = tag) - val newId = recipeDao.insertTag(tagEntity) - tagEntities.add(tagEntity.copy(localId = newId)) - newId - } else { - existingTag.localId - } - return tagId } @@ -108,8 +52,6 @@ class RecipeStorageImpl @Inject constructor( logger.v { "clearAllLocalData() called" } db.withTransaction { recipeDao.removeAllRecipes() - recipeDao.removeAllCategories() - recipeDao.removeAllTags() } } diff --git a/app/src/main/java/gq/kirmanak/mealient/data/recipes/network/RecipeSummaryInfo.kt b/app/src/main/java/gq/kirmanak/mealient/data/recipes/network/RecipeSummaryInfo.kt index 49a67ab..9e9cf8f 100644 --- a/app/src/main/java/gq/kirmanak/mealient/data/recipes/network/RecipeSummaryInfo.kt +++ b/app/src/main/java/gq/kirmanak/mealient/data/recipes/network/RecipeSummaryInfo.kt @@ -7,12 +7,8 @@ data class RecipeSummaryInfo( val remoteId: String, val name: String, val slug: String, - val image: String?, val description: String = "", - val recipeCategories: List, - val tags: List, - val rating: Int?, - val dateAdded: LocalDate, - val dateUpdated: LocalDateTime, val imageId: String, + val dateAdded: LocalDate, + val dateUpdated: LocalDateTime ) diff --git a/app/src/main/java/gq/kirmanak/mealient/extensions/RemoteToLocalMappings.kt b/app/src/main/java/gq/kirmanak/mealient/extensions/RemoteToLocalMappings.kt index 9a95a2d..c457429 100644 --- a/app/src/main/java/gq/kirmanak/mealient/extensions/RemoteToLocalMappings.kt +++ b/app/src/main/java/gq/kirmanak/mealient/extensions/RemoteToLocalMappings.kt @@ -36,11 +36,7 @@ fun GetRecipeSummaryResponseV0.toRecipeSummaryInfo() = RecipeSummaryInfo( remoteId = remoteId.toString(), name = name, slug = slug, - image = image, description = description, - recipeCategories = recipeCategories, - tags = tags, - rating = rating, dateAdded = dateAdded, dateUpdated = dateUpdated, imageId = slug, @@ -50,11 +46,7 @@ fun GetRecipeSummaryResponseV1.toRecipeSummaryInfo() = RecipeSummaryInfo( remoteId = remoteId, name = name, slug = slug, - image = image, description = description, - recipeCategories = recipeCategories, - tags = tags, - rating = rating, dateAdded = dateAdded, dateUpdated = dateUpdated, imageId = remoteId, @@ -64,9 +56,7 @@ fun RecipeSummaryInfo.recipeEntity() = RecipeSummaryEntity( remoteId = remoteId, name = name, slug = slug, - image = image, description = description, - rating = rating, dateAdded = dateAdded, dateUpdated = dateUpdated, imageId = imageId, diff --git a/app/src/test/java/gq/kirmanak/mealient/data/recipes/db/RecipeStorageImplTest.kt b/app/src/test/java/gq/kirmanak/mealient/data/recipes/db/RecipeStorageImplTest.kt index d432f53..8dddb8f 100644 --- a/app/src/test/java/gq/kirmanak/mealient/data/recipes/db/RecipeStorageImplTest.kt +++ b/app/src/test/java/gq/kirmanak/mealient/data/recipes/db/RecipeStorageImplTest.kt @@ -3,10 +3,6 @@ package gq.kirmanak.mealient.data.recipes.db import com.google.common.truth.Truth.assertThat import dagger.hilt.android.testing.HiltAndroidTest import gq.kirmanak.mealient.database.AppDb -import gq.kirmanak.mealient.database.recipe.entity.CategoryEntity -import gq.kirmanak.mealient.database.recipe.entity.CategoryRecipeEntity -import gq.kirmanak.mealient.database.recipe.entity.TagEntity -import gq.kirmanak.mealient.database.recipe.entity.TagRecipeEntity import gq.kirmanak.mealient.test.HiltRobolectricTest import gq.kirmanak.mealient.test.RecipeImplTestData.BREAD_INGREDIENT import gq.kirmanak.mealient.test.RecipeImplTestData.CAKE_BREAD_RECIPE_INGREDIENT_ENTITY @@ -36,28 +32,6 @@ class RecipeStorageImplTest : HiltRobolectricTest() { @Inject lateinit var appDb: AppDb - @Test - fun `when saveRecipes then saves tags`() = runTest { - subject.saveRecipes(TEST_RECIPE_SUMMARIES) - val actualTags = appDb.recipeDao().queryAllTags() - assertThat(actualTags).containsExactly( - TagEntity(localId = 1, name = "gluten"), - TagEntity(localId = 2, name = "allergic"), - TagEntity(localId = 3, name = "milk") - ) - } - - @Test - fun `when saveRecipes then saves categories`() = runTest { - subject.saveRecipes(TEST_RECIPE_SUMMARIES) - val actual = appDb.recipeDao().queryAllCategories() - assertThat(actual).containsExactly( - CategoryEntity(localId = 1, name = "dessert"), - CategoryEntity(localId = 2, name = "tasty"), - CategoryEntity(localId = 3, name = "porridge") - ) - } - @Test fun `when saveRecipes then saves recipes`() = runTest { subject.saveRecipes(TEST_RECIPE_SUMMARIES) @@ -68,30 +42,6 @@ class RecipeStorageImplTest : HiltRobolectricTest() { ) } - @Test - fun `when saveRecipes then saves category recipes`() = runTest { - subject.saveRecipes(TEST_RECIPE_SUMMARIES) - val actual = appDb.recipeDao().queryAllCategoryRecipes() - assertThat(actual).containsExactly( - CategoryRecipeEntity(categoryId = 1, recipeId = "1"), - CategoryRecipeEntity(categoryId = 2, recipeId = "1"), - CategoryRecipeEntity(categoryId = 3, recipeId = "2"), - CategoryRecipeEntity(categoryId = 2, recipeId = "2") - ) - } - - @Test - fun `when saveRecipes then saves tag recipes`() = runTest { - subject.saveRecipes(TEST_RECIPE_SUMMARIES) - val actual = appDb.recipeDao().queryAllTagRecipes() - assertThat(actual).containsExactly( - TagRecipeEntity(tagId = 1, recipeId = "1"), - TagRecipeEntity(tagId = 2, recipeId = "1"), - TagRecipeEntity(tagId = 3, recipeId = "2"), - TagRecipeEntity(tagId = 1, recipeId = "2"), - ) - } - @Test fun `when refreshAll then old recipes aren't preserved`() = runTest { subject.saveRecipes(TEST_RECIPE_SUMMARIES) @@ -100,28 +50,6 @@ class RecipeStorageImplTest : HiltRobolectricTest() { assertThat(actual).containsExactly(CAKE_RECIPE_SUMMARY_ENTITY) } - @Test - fun `when refreshAll then old category recipes aren't preserved`() = runTest { - subject.saveRecipes(TEST_RECIPE_SUMMARIES) - subject.refreshAll(listOf(RECIPE_SUMMARY_CAKE)) - val actual = appDb.recipeDao().queryAllCategoryRecipes() - assertThat(actual).containsExactly( - CategoryRecipeEntity(categoryId = 1, recipeId = "1"), - CategoryRecipeEntity(categoryId = 2, recipeId = "1"), - ) - } - - @Test - fun `when refreshAll then old tag recipes aren't preserved`() = runTest { - subject.saveRecipes(TEST_RECIPE_SUMMARIES) - subject.refreshAll(listOf(RECIPE_SUMMARY_CAKE)) - val actual = appDb.recipeDao().queryAllTagRecipes() - assertThat(actual).containsExactly( - TagRecipeEntity(tagId = 1, recipeId = "1"), - TagRecipeEntity(tagId = 2, recipeId = "1"), - ) - } - @Test fun `when clearAllLocalData then recipes aren't preserved`() = runTest { subject.saveRecipes(TEST_RECIPE_SUMMARIES) @@ -130,22 +58,6 @@ class RecipeStorageImplTest : HiltRobolectricTest() { assertThat(actual).isEmpty() } - @Test - fun `when clearAllLocalData then categories aren't preserved`() = runTest { - subject.saveRecipes(TEST_RECIPE_SUMMARIES) - subject.clearAllLocalData() - val actual = appDb.recipeDao().queryAllCategories() - assertThat(actual).isEmpty() - } - - @Test - fun `when clearAllLocalData then tags aren't preserved`() = runTest { - subject.saveRecipes(TEST_RECIPE_SUMMARIES) - subject.clearAllLocalData() - val actual = appDb.recipeDao().queryAllTags() - assertThat(actual).isEmpty() - } - @Test fun `when saveRecipeInfo then saves recipe info`() = runTest { subject.saveRecipes(listOf(RECIPE_SUMMARY_CAKE)) diff --git a/app/src/test/java/gq/kirmanak/mealient/test/RecipeImplTestData.kt b/app/src/test/java/gq/kirmanak/mealient/test/RecipeImplTestData.kt index d4ab9e1..049d6ad 100644 --- a/app/src/test/java/gq/kirmanak/mealient/test/RecipeImplTestData.kt +++ b/app/src/test/java/gq/kirmanak/mealient/test/RecipeImplTestData.kt @@ -13,11 +13,7 @@ object RecipeImplTestData { remoteId = "1", name = "Cake", slug = "cake", - image = "86", description = "A tasty cake", - recipeCategories = listOf("dessert", "tasty"), - tags = listOf("gluten", "allergic"), - rating = 4, dateAdded = LocalDate.parse("2021-11-13"), dateUpdated = LocalDateTime.parse("2021-11-13T15:30:13"), imageId = "cake", @@ -27,11 +23,7 @@ object RecipeImplTestData { remoteId = "2", name = "Porridge", slug = "porridge", - image = "89", description = "A tasty porridge", - recipeCategories = listOf("porridge", "tasty"), - tags = listOf("gluten", "milk"), - rating = 5, dateAdded = LocalDate.parse("2021-11-12"), dateUpdated = LocalDateTime.parse("2021-10-13T17:35:23"), imageId = "porridge", @@ -43,9 +35,7 @@ object RecipeImplTestData { remoteId = "1", name = "Cake", slug = "cake", - image = "86", description = "A tasty cake", - rating = 4, dateAdded = LocalDate.parse("2021-11-13"), dateUpdated = LocalDateTime.parse("2021-11-13T15:30:13"), imageId = "cake", @@ -55,9 +45,7 @@ object RecipeImplTestData { remoteId = "2", name = "Porridge", slug = "porridge", - image = "89", description = "A tasty porridge", - rating = 5, dateAdded = LocalDate.parse("2021-11-12"), dateUpdated = LocalDateTime.parse("2021-10-13T17:35:23"), imageId = "porridge", diff --git a/database/schemas/gq.kirmanak.mealient.database.AppDb/6.json b/database/schemas/gq.kirmanak.mealient.database.AppDb/6.json new file mode 100644 index 0000000..81e2dc6 --- /dev/null +++ b/database/schemas/gq.kirmanak.mealient.database.AppDb/6.json @@ -0,0 +1,160 @@ +{ + "formatVersion": 1, + "database": { + "version": 6, + "identityHash": "f6e28dd617e4d4a6843a7865c9da736d", + "entities": [ + { + "tableName": "recipe_summaries", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`remote_id` TEXT NOT NULL, `name` TEXT NOT NULL, `slug` TEXT NOT NULL, `description` TEXT NOT NULL, `date_added` INTEGER NOT NULL, `date_updated` INTEGER NOT NULL, `image_id` TEXT, PRIMARY KEY(`remote_id`))", + "fields": [ + { + "fieldPath": "remoteId", + "columnName": "remote_id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "slug", + "columnName": "slug", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "description", + "columnName": "description", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "dateAdded", + "columnName": "date_added", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "dateUpdated", + "columnName": "date_updated", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "imageId", + "columnName": "image_id", + "affinity": "TEXT", + "notNull": false + } + ], + "primaryKey": { + "columnNames": [ + "remote_id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "recipe", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`remote_id` TEXT NOT NULL, `recipe_yield` TEXT NOT NULL, PRIMARY KEY(`remote_id`))", + "fields": [ + { + "fieldPath": "remoteId", + "columnName": "remote_id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "recipeYield", + "columnName": "recipe_yield", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "remote_id" + ], + "autoGenerate": false + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "recipe_ingredient", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`local_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `recipe_id` TEXT NOT NULL, `note` TEXT NOT NULL)", + "fields": [ + { + "fieldPath": "localId", + "columnName": "local_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "recipeId", + "columnName": "recipe_id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "note", + "columnName": "note", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "local_id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "recipe_instruction", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`local_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `recipe_id` TEXT NOT NULL, `text` TEXT NOT NULL)", + "fields": [ + { + "fieldPath": "localId", + "columnName": "local_id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "recipeId", + "columnName": "recipe_id", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "text", + "columnName": "text", + "affinity": "TEXT", + "notNull": true + } + ], + "primaryKey": { + "columnNames": [ + "local_id" + ], + "autoGenerate": true + }, + "indices": [], + "foreignKeys": [] + } + ], + "views": [], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'f6e28dd617e4d4a6843a7865c9da736d')" + ] + } +} \ No newline at end of file diff --git a/database/src/main/kotlin/gq/kirmanak/mealient/database/AppDb.kt b/database/src/main/kotlin/gq/kirmanak/mealient/database/AppDb.kt index 62d87f7..37571cd 100644 --- a/database/src/main/kotlin/gq/kirmanak/mealient/database/AppDb.kt +++ b/database/src/main/kotlin/gq/kirmanak/mealient/database/AppDb.kt @@ -6,12 +6,8 @@ import gq.kirmanak.mealient.database.recipe.RecipeDao import gq.kirmanak.mealient.database.recipe.entity.* @Database( - version = 5, + version = 6, entities = [ - CategoryEntity::class, - CategoryRecipeEntity::class, - TagEntity::class, - TagRecipeEntity::class, RecipeSummaryEntity::class, RecipeEntity::class, RecipeIngredientEntity::class, @@ -22,6 +18,7 @@ import gq.kirmanak.mealient.database.recipe.entity.* AutoMigration(from = 1, to = 2), AutoMigration(from = 3, to = 4), AutoMigration(from = 4, to = 5, spec = AppDb.From4To5Migration::class), + AutoMigration(from = 5, to = 6, spec = AppDb.From5To6Migration::class), ] ) @TypeConverters(RoomTypeConverters::class) @@ -35,4 +32,12 @@ abstract class AppDb : RoomDatabase() { @DeleteColumn(tableName = "recipe_ingredient", columnName = "disable_amount") @DeleteColumn(tableName = "recipe_ingredient", columnName = "quantity") class From4To5Migration : AutoMigrationSpec + + @DeleteColumn(tableName = "recipe_summaries", columnName = "image") + @DeleteColumn(tableName = "recipe_summaries", columnName = "rating") + @DeleteTable(tableName = "tag_recipe") + @DeleteTable(tableName = "tags") + @DeleteTable(tableName = "categories") + @DeleteTable(tableName = "category_recipe") + class From5To6Migration : AutoMigrationSpec } \ No newline at end of file diff --git a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/RecipeDao.kt b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/RecipeDao.kt index 091ec3f..b3d1f72 100644 --- a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/RecipeDao.kt +++ b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/RecipeDao.kt @@ -6,54 +6,18 @@ import gq.kirmanak.mealient.database.recipe.entity.* @Dao interface RecipeDao { - @Query("SELECT * FROM tags") - suspend fun queryAllTags(): List - - @Query("SELECT * FROM categories") - suspend fun queryAllCategories(): List - @Query("SELECT * FROM recipe_summaries ORDER BY date_added DESC") fun queryRecipesByPages(): PagingSource @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insertRecipe(recipeSummaryEntity: RecipeSummaryEntity) - @Insert(onConflict = OnConflictStrategy.IGNORE) - suspend fun insertTag(tagEntity: TagEntity): Long - - @Insert(onConflict = OnConflictStrategy.IGNORE) - suspend fun insertTagRecipeEntity(tagRecipeEntity: TagRecipeEntity) - - @Insert(onConflict = OnConflictStrategy.IGNORE) - suspend fun insertCategory(categoryEntity: CategoryEntity): Long - - @Insert(onConflict = OnConflictStrategy.IGNORE) - suspend fun insertCategoryRecipeEntity(categoryRecipeEntity: CategoryRecipeEntity) - - @Insert(onConflict = OnConflictStrategy.IGNORE) - suspend fun insertTagRecipeEntities(tagRecipeEntities: Set) - - @Insert(onConflict = OnConflictStrategy.IGNORE) - suspend fun insertCategoryRecipeEntities(categoryRecipeEntities: Set) - @Query("DELETE FROM recipe_summaries") suspend fun removeAllRecipes() - @Query("DELETE FROM tags") - suspend fun removeAllTags() - - @Query("DELETE FROM categories") - suspend fun removeAllCategories() - @Query("SELECT * FROM recipe_summaries ORDER BY date_updated DESC") suspend fun queryAllRecipes(): List - @Query("SELECT * FROM category_recipe") - suspend fun queryAllCategoryRecipes(): List - - @Query("SELECT * FROM tag_recipe") - suspend fun queryAllTagRecipes(): List - @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insertRecipe(recipe: RecipeEntity) diff --git a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/CategoryEntity.kt b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/CategoryEntity.kt deleted file mode 100644 index 4384ded..0000000 --- a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/CategoryEntity.kt +++ /dev/null @@ -1,12 +0,0 @@ -package gq.kirmanak.mealient.database.recipe.entity - -import androidx.room.ColumnInfo -import androidx.room.Entity -import androidx.room.Index -import androidx.room.PrimaryKey - -@Entity(tableName = "categories", indices = [Index(value = ["name"], unique = true)]) -data class CategoryEntity( - @PrimaryKey(autoGenerate = true) @ColumnInfo(name = "local_id") val localId: Long = 0, - @ColumnInfo(name = "name") val name: String, -) \ No newline at end of file diff --git a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/CategoryRecipeEntity.kt b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/CategoryRecipeEntity.kt deleted file mode 100644 index 1962af1..0000000 --- a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/CategoryRecipeEntity.kt +++ /dev/null @@ -1,29 +0,0 @@ -package gq.kirmanak.mealient.database.recipe.entity - -import androidx.room.ColumnInfo -import androidx.room.Entity -import androidx.room.ForeignKey -import androidx.room.Index - -@Entity( - tableName = "category_recipe", - primaryKeys = ["category_id", "recipe_id"], - indices = [Index(value = ["category_id", "recipe_id"], unique = true)], - foreignKeys = [ForeignKey( - entity = CategoryEntity::class, - parentColumns = ["local_id"], - childColumns = ["category_id"], - onDelete = ForeignKey.CASCADE, - onUpdate = ForeignKey.CASCADE - ), ForeignKey( - entity = RecipeSummaryEntity::class, - parentColumns = ["remote_id"], - childColumns = ["recipe_id"], - onDelete = ForeignKey.CASCADE, - onUpdate = ForeignKey.CASCADE - )] -) -data class CategoryRecipeEntity( - @ColumnInfo(name = "category_id") val categoryId: Long, - @ColumnInfo(name = "recipe_id", index = true) val recipeId: String, -) \ No newline at end of file diff --git a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeSummaryEntity.kt b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeSummaryEntity.kt index 0bde53e..afbc99d 100644 --- a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeSummaryEntity.kt +++ b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/RecipeSummaryEntity.kt @@ -11,14 +11,8 @@ data class RecipeSummaryEntity( @PrimaryKey @ColumnInfo(name = "remote_id") val remoteId: String, @ColumnInfo(name = "name") val name: String, @ColumnInfo(name = "slug") val slug: String, - @ColumnInfo(name = "image") val image: String?, @ColumnInfo(name = "description") val description: String, - @ColumnInfo(name = "rating") val rating: Int?, @ColumnInfo(name = "date_added") val dateAdded: LocalDate, @ColumnInfo(name = "date_updated") val dateUpdated: LocalDateTime, @ColumnInfo(name = "image_id") val imageId: String?, -) { - override fun toString(): String { - return "RecipeSummaryEntity(remoteId=$remoteId, name='$name')" - } -} \ No newline at end of file +) \ No newline at end of file diff --git a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/TagEntity.kt b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/TagEntity.kt deleted file mode 100644 index 460c649..0000000 --- a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/TagEntity.kt +++ /dev/null @@ -1,12 +0,0 @@ -package gq.kirmanak.mealient.database.recipe.entity - -import androidx.room.ColumnInfo -import androidx.room.Entity -import androidx.room.Index -import androidx.room.PrimaryKey - -@Entity(tableName = "tags", indices = [Index(value = ["name"], unique = true)]) -data class TagEntity( - @PrimaryKey(autoGenerate = true) @ColumnInfo(name = "local_id") val localId: Long = 0, - @ColumnInfo(name = "name") val name: String -) \ No newline at end of file diff --git a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/TagRecipeEntity.kt b/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/TagRecipeEntity.kt deleted file mode 100644 index 5d4b27b..0000000 --- a/database/src/main/kotlin/gq/kirmanak/mealient/database/recipe/entity/TagRecipeEntity.kt +++ /dev/null @@ -1,27 +0,0 @@ -package gq.kirmanak.mealient.database.recipe.entity - -import androidx.room.ColumnInfo -import androidx.room.Entity -import androidx.room.ForeignKey - -@Entity( - tableName = "tag_recipe", - primaryKeys = ["tag_id", "recipe_id"], - foreignKeys = [ForeignKey( - entity = TagEntity::class, - parentColumns = ["local_id"], - childColumns = ["tag_id"], - onDelete = ForeignKey.CASCADE, - onUpdate = ForeignKey.CASCADE - ), ForeignKey( - entity = RecipeSummaryEntity::class, - parentColumns = ["remote_id"], - childColumns = ["recipe_id"], - onDelete = ForeignKey.CASCADE, - onUpdate = ForeignKey.CASCADE - )] -) -data class TagRecipeEntity( - @ColumnInfo(name = "tag_id") val tagId: Long, - @ColumnInfo(name = "recipe_id", index = true) val recipeId: String, -) \ No newline at end of file diff --git a/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/v0/models/GetRecipeSummaryResponseV0.kt b/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/v0/models/GetRecipeSummaryResponseV0.kt index 6fdd0f0..cc28c55 100644 --- a/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/v0/models/GetRecipeSummaryResponseV0.kt +++ b/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/v0/models/GetRecipeSummaryResponseV0.kt @@ -10,15 +10,7 @@ data class GetRecipeSummaryResponseV0( @SerialName("id") val remoteId: Int, @SerialName("name") val name: String, @SerialName("slug") val slug: String, - @SerialName("image") val image: String?, @SerialName("description") val description: String = "", - @SerialName("recipeCategory") val recipeCategories: List, - @SerialName("tags") val tags: List, - @SerialName("rating") val rating: Int?, @SerialName("dateAdded") val dateAdded: LocalDate, @SerialName("dateUpdated") val dateUpdated: LocalDateTime -) { - override fun toString(): String { - return "GetRecipeSummaryResponse(remoteId=$remoteId, name='$name')" - } -} \ No newline at end of file +) \ No newline at end of file diff --git a/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/v1/models/GetRecipeSummaryResponseV1.kt b/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/v1/models/GetRecipeSummaryResponseV1.kt index 3ec4a06..f4512b8 100644 --- a/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/v1/models/GetRecipeSummaryResponseV1.kt +++ b/datasource/src/main/kotlin/gq/kirmanak/mealient/datasource/v1/models/GetRecipeSummaryResponseV1.kt @@ -10,15 +10,7 @@ data class GetRecipeSummaryResponseV1( @SerialName("id") val remoteId: String, @SerialName("name") val name: String, @SerialName("slug") val slug: String, - @SerialName("image") val image: String?, @SerialName("description") val description: String = "", - @SerialName("recipeCategory") val recipeCategories: List, - @SerialName("tags") val tags: List, - @SerialName("rating") val rating: Int?, @SerialName("dateAdded") val dateAdded: LocalDate, @SerialName("dateUpdated") val dateUpdated: LocalDateTime -) { - override fun toString(): String { - return "GetRecipeSummaryResponseV1(remoteId=$remoteId, name='$name')" - } -} \ No newline at end of file +) \ No newline at end of file