Initialize v1 support
This commit is contained in:
@@ -9,5 +9,5 @@ interface RecipeRepo {
|
|||||||
|
|
||||||
suspend fun clearLocalData()
|
suspend fun clearLocalData()
|
||||||
|
|
||||||
suspend fun loadRecipeInfo(recipeId: Long, recipeSlug: String): FullRecipeInfo
|
suspend fun loadRecipeInfo(recipeId: String, recipeSlug: String): FullRecipeInfo
|
||||||
}
|
}
|
||||||
@@ -17,5 +17,5 @@ interface RecipeStorage {
|
|||||||
|
|
||||||
suspend fun saveRecipeInfo(recipe: GetRecipeResponse)
|
suspend fun saveRecipeInfo(recipe: GetRecipeResponse)
|
||||||
|
|
||||||
suspend fun queryRecipeInfo(recipeId: Long): FullRecipeInfo
|
suspend fun queryRecipeInfo(recipeId: String): FullRecipeInfo
|
||||||
}
|
}
|
||||||
@@ -132,7 +132,7 @@ class RecipeStorageImpl @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun queryRecipeInfo(recipeId: Long): FullRecipeInfo {
|
override suspend fun queryRecipeInfo(recipeId: String): FullRecipeInfo {
|
||||||
logger.v { "queryRecipeInfo() called with: recipeId = $recipeId" }
|
logger.v { "queryRecipeInfo() called with: recipeId = $recipeId" }
|
||||||
val fullRecipeInfo = checkNotNull(recipeDao.queryFullRecipeInfo(recipeId)) {
|
val fullRecipeInfo = checkNotNull(recipeDao.queryFullRecipeInfo(recipeId)) {
|
||||||
"Can't find recipe by id $recipeId in DB"
|
"Can't find recipe by id $recipeId in DB"
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class RecipeRepoImpl @Inject constructor(
|
|||||||
storage.clearAllLocalData()
|
storage.clearAllLocalData()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun loadRecipeInfo(recipeId: Long, recipeSlug: String): FullRecipeInfo {
|
override suspend fun loadRecipeInfo(recipeId: String, recipeSlug: String): FullRecipeInfo {
|
||||||
logger.v { "loadRecipeInfo() called with: recipeId = $recipeId, recipeSlug = $recipeSlug" }
|
logger.v { "loadRecipeInfo() called with: recipeId = $recipeId, recipeSlug = $recipeSlug" }
|
||||||
|
|
||||||
runCatchingExceptCancel {
|
runCatchingExceptCancel {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ fun GetRecipeResponse.toRecipeEntity() = RecipeEntity(
|
|||||||
recipeYield = recipeYield
|
recipeYield = recipeYield
|
||||||
)
|
)
|
||||||
|
|
||||||
fun GetRecipeIngredientResponse.toRecipeIngredientEntity(remoteId: Long) =
|
fun GetRecipeIngredientResponse.toRecipeIngredientEntity(remoteId: String) =
|
||||||
RecipeIngredientEntity(
|
RecipeIngredientEntity(
|
||||||
recipeId = remoteId,
|
recipeId = remoteId,
|
||||||
title = title,
|
title = title,
|
||||||
@@ -24,7 +24,7 @@ fun GetRecipeIngredientResponse.toRecipeIngredientEntity(remoteId: Long) =
|
|||||||
quantity = quantity
|
quantity = quantity
|
||||||
)
|
)
|
||||||
|
|
||||||
fun GetRecipeInstructionResponse.toRecipeInstructionEntity(remoteId: Long) =
|
fun GetRecipeInstructionResponse.toRecipeInstructionEntity(remoteId: String) =
|
||||||
RecipeInstructionEntity(
|
RecipeInstructionEntity(
|
||||||
recipeId = remoteId,
|
recipeId = remoteId,
|
||||||
title = title,
|
title = title,
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class RecipeModelLoader private constructor(
|
|||||||
options: Options?
|
options: Options?
|
||||||
): String? {
|
): String? {
|
||||||
logger.v { "getUrl() called with: model = $model, width = $width, height = $height, options = $options" }
|
logger.v { "getUrl() called with: model = $model, width = $width, height = $height, options = $options" }
|
||||||
return runBlocking { recipeImageUrlProvider.generateImageUrl(model?.slug) }
|
return runBlocking { recipeImageUrlProvider.generateImageUrl(model?.remoteId) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getHeaders(
|
override fun getHeaders(
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class RecipeInfoViewModel @Inject constructor(
|
|||||||
private val _uiState = MutableLiveData(RecipeInfoUiState())
|
private val _uiState = MutableLiveData(RecipeInfoUiState())
|
||||||
val uiState: LiveData<RecipeInfoUiState> get() = _uiState
|
val uiState: LiveData<RecipeInfoUiState> get() = _uiState
|
||||||
|
|
||||||
fun loadRecipeInfo(recipeId: Long, recipeSlug: String) {
|
fun loadRecipeInfo(recipeId: String, recipeSlug: String) {
|
||||||
logger.v { "loadRecipeInfo() called with: recipeId = $recipeId, recipeSlug = $recipeSlug" }
|
logger.v { "loadRecipeInfo() called with: recipeId = $recipeId, recipeSlug = $recipeSlug" }
|
||||||
_uiState.value = RecipeInfoUiState()
|
_uiState.value = RecipeInfoUiState()
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
app:argType="string" />
|
app:argType="string" />
|
||||||
<argument
|
<argument
|
||||||
android:name="recipe_id"
|
android:name="recipe_id"
|
||||||
app:argType="long" />
|
app:argType="string" />
|
||||||
</dialog>
|
</dialog>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/disclaimerFragment"
|
android:id="@+id/disclaimerFragment"
|
||||||
|
|||||||
404
database/schemas/gq.kirmanak.mealient.database.AppDb/3.json
Normal file
404
database/schemas/gq.kirmanak.mealient.database.AppDb/3.json
Normal file
@@ -0,0 +1,404 @@
|
|||||||
|
{
|
||||||
|
"formatVersion": 1,
|
||||||
|
"database": {
|
||||||
|
"version": 3,
|
||||||
|
"identityHash": "28c896eb34e95c0cff33148178252f72",
|
||||||
|
"entities": [
|
||||||
|
{
|
||||||
|
"tableName": "categories",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`local_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "localId",
|
||||||
|
"columnName": "local_id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "name",
|
||||||
|
"columnName": "name",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"local_id"
|
||||||
|
],
|
||||||
|
"autoGenerate": true
|
||||||
|
},
|
||||||
|
"indices": [
|
||||||
|
{
|
||||||
|
"name": "index_categories_name",
|
||||||
|
"unique": true,
|
||||||
|
"columnNames": [
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"orders": [],
|
||||||
|
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_categories_name` ON `${TABLE_NAME}` (`name`)"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "category_recipe",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`category_id` INTEGER NOT NULL, `recipe_id` TEXT NOT NULL, PRIMARY KEY(`category_id`, `recipe_id`), FOREIGN KEY(`category_id`) REFERENCES `categories`(`local_id`) ON UPDATE CASCADE ON DELETE CASCADE , FOREIGN KEY(`recipe_id`) REFERENCES `recipe_summaries`(`remote_id`) ON UPDATE CASCADE ON DELETE CASCADE )",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "categoryId",
|
||||||
|
"columnName": "category_id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "recipeId",
|
||||||
|
"columnName": "recipe_id",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"category_id",
|
||||||
|
"recipe_id"
|
||||||
|
],
|
||||||
|
"autoGenerate": false
|
||||||
|
},
|
||||||
|
"indices": [
|
||||||
|
{
|
||||||
|
"name": "index_category_recipe_category_id_recipe_id",
|
||||||
|
"unique": true,
|
||||||
|
"columnNames": [
|
||||||
|
"category_id",
|
||||||
|
"recipe_id"
|
||||||
|
],
|
||||||
|
"orders": [],
|
||||||
|
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_category_recipe_category_id_recipe_id` ON `${TABLE_NAME}` (`category_id`, `recipe_id`)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "index_category_recipe_recipe_id",
|
||||||
|
"unique": false,
|
||||||
|
"columnNames": [
|
||||||
|
"recipe_id"
|
||||||
|
],
|
||||||
|
"orders": [],
|
||||||
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_category_recipe_recipe_id` ON `${TABLE_NAME}` (`recipe_id`)"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"foreignKeys": [
|
||||||
|
{
|
||||||
|
"table": "categories",
|
||||||
|
"onDelete": "CASCADE",
|
||||||
|
"onUpdate": "CASCADE",
|
||||||
|
"columns": [
|
||||||
|
"category_id"
|
||||||
|
],
|
||||||
|
"referencedColumns": [
|
||||||
|
"local_id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"table": "recipe_summaries",
|
||||||
|
"onDelete": "CASCADE",
|
||||||
|
"onUpdate": "CASCADE",
|
||||||
|
"columns": [
|
||||||
|
"recipe_id"
|
||||||
|
],
|
||||||
|
"referencedColumns": [
|
||||||
|
"remote_id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "tags",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`local_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "localId",
|
||||||
|
"columnName": "local_id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "name",
|
||||||
|
"columnName": "name",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"local_id"
|
||||||
|
],
|
||||||
|
"autoGenerate": true
|
||||||
|
},
|
||||||
|
"indices": [
|
||||||
|
{
|
||||||
|
"name": "index_tags_name",
|
||||||
|
"unique": true,
|
||||||
|
"columnNames": [
|
||||||
|
"name"
|
||||||
|
],
|
||||||
|
"orders": [],
|
||||||
|
"createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_tags_name` ON `${TABLE_NAME}` (`name`)"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"foreignKeys": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "tag_recipe",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`tag_id` INTEGER NOT NULL, `recipe_id` TEXT NOT NULL, PRIMARY KEY(`tag_id`, `recipe_id`), FOREIGN KEY(`tag_id`) REFERENCES `tags`(`local_id`) ON UPDATE CASCADE ON DELETE CASCADE , FOREIGN KEY(`recipe_id`) REFERENCES `recipe_summaries`(`remote_id`) ON UPDATE CASCADE ON DELETE CASCADE )",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "tagId",
|
||||||
|
"columnName": "tag_id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "recipeId",
|
||||||
|
"columnName": "recipe_id",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"primaryKey": {
|
||||||
|
"columnNames": [
|
||||||
|
"tag_id",
|
||||||
|
"recipe_id"
|
||||||
|
],
|
||||||
|
"autoGenerate": false
|
||||||
|
},
|
||||||
|
"indices": [
|
||||||
|
{
|
||||||
|
"name": "index_tag_recipe_recipe_id",
|
||||||
|
"unique": false,
|
||||||
|
"columnNames": [
|
||||||
|
"recipe_id"
|
||||||
|
],
|
||||||
|
"orders": [],
|
||||||
|
"createSql": "CREATE INDEX IF NOT EXISTS `index_tag_recipe_recipe_id` ON `${TABLE_NAME}` (`recipe_id`)"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"foreignKeys": [
|
||||||
|
{
|
||||||
|
"table": "tags",
|
||||||
|
"onDelete": "CASCADE",
|
||||||
|
"onUpdate": "CASCADE",
|
||||||
|
"columns": [
|
||||||
|
"tag_id"
|
||||||
|
],
|
||||||
|
"referencedColumns": [
|
||||||
|
"local_id"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"table": "recipe_summaries",
|
||||||
|
"onDelete": "CASCADE",
|
||||||
|
"onUpdate": "CASCADE",
|
||||||
|
"columns": [
|
||||||
|
"recipe_id"
|
||||||
|
],
|
||||||
|
"referencedColumns": [
|
||||||
|
"remote_id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tableName": "recipe_summaries",
|
||||||
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`remote_id` TEXT NOT NULL, `name` TEXT NOT NULL, `slug` TEXT NOT NULL, `image` TEXT, `description` TEXT NOT NULL, `rating` INTEGER, `date_added` INTEGER NOT NULL, `date_updated` INTEGER NOT NULL, 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": "image",
|
||||||
|
"columnName": "image",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "description",
|
||||||
|
"columnName": "description",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "rating",
|
||||||
|
"columnName": "rating",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "dateAdded",
|
||||||
|
"columnName": "date_added",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "dateUpdated",
|
||||||
|
"columnName": "date_updated",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"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, `title` TEXT NOT NULL, `note` TEXT NOT NULL, `unit` TEXT NOT NULL, `food` TEXT NOT NULL, `disable_amount` INTEGER NOT NULL, `quantity` REAL NOT NULL)",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"fieldPath": "localId",
|
||||||
|
"columnName": "local_id",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "recipeId",
|
||||||
|
"columnName": "recipe_id",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "title",
|
||||||
|
"columnName": "title",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "note",
|
||||||
|
"columnName": "note",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "unit",
|
||||||
|
"columnName": "unit",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "food",
|
||||||
|
"columnName": "food",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "disableAmount",
|
||||||
|
"columnName": "disable_amount",
|
||||||
|
"affinity": "INTEGER",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "quantity",
|
||||||
|
"columnName": "quantity",
|
||||||
|
"affinity": "REAL",
|
||||||
|
"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, `title` 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": "title",
|
||||||
|
"columnName": "title",
|
||||||
|
"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, '28c896eb34e95c0cff33148178252f72')"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ import gq.kirmanak.mealient.database.recipe.RecipeDao
|
|||||||
import gq.kirmanak.mealient.database.recipe.entity.*
|
import gq.kirmanak.mealient.database.recipe.entity.*
|
||||||
|
|
||||||
@Database(
|
@Database(
|
||||||
version = 2,
|
version = 3,
|
||||||
entities = [
|
entities = [
|
||||||
CategoryEntity::class,
|
CategoryEntity::class,
|
||||||
CategoryRecipeEntity::class,
|
CategoryRecipeEntity::class,
|
||||||
@@ -21,7 +21,7 @@ import gq.kirmanak.mealient.database.recipe.entity.*
|
|||||||
],
|
],
|
||||||
exportSchema = true,
|
exportSchema = true,
|
||||||
autoMigrations = [
|
autoMigrations = [
|
||||||
AutoMigration(from = 1, to = 2)
|
AutoMigration(from = 1, to = 2),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@TypeConverters(RoomTypeConverters::class)
|
@TypeConverters(RoomTypeConverters::class)
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ interface DatabaseModule {
|
|||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun createDb(@ApplicationContext context: Context): AppDb =
|
fun createDb(@ApplicationContext context: Context): AppDb =
|
||||||
Room.databaseBuilder(context, AppDb::class.java, "app.db").build()
|
Room.databaseBuilder(context, AppDb::class.java, "app.db")
|
||||||
|
.fallbackToDestructiveMigrationFrom(2)
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,11 +66,11 @@ interface RecipeDao {
|
|||||||
@Transaction
|
@Transaction
|
||||||
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH) // The lint is wrong, the columns are actually used
|
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH) // The lint is wrong, the columns are actually used
|
||||||
@Query("SELECT * FROM recipe JOIN recipe_summaries ON recipe.remote_id = recipe_summaries.remote_id JOIN recipe_ingredient ON recipe_ingredient.recipe_id = recipe.remote_id JOIN recipe_instruction ON recipe_instruction.recipe_id = recipe.remote_id WHERE recipe.remote_id = :recipeId")
|
@Query("SELECT * FROM recipe JOIN recipe_summaries ON recipe.remote_id = recipe_summaries.remote_id JOIN recipe_ingredient ON recipe_ingredient.recipe_id = recipe.remote_id JOIN recipe_instruction ON recipe_instruction.recipe_id = recipe.remote_id WHERE recipe.remote_id = :recipeId")
|
||||||
suspend fun queryFullRecipeInfo(recipeId: Long): FullRecipeInfo?
|
suspend fun queryFullRecipeInfo(recipeId: String): FullRecipeInfo?
|
||||||
|
|
||||||
@Query("DELETE FROM recipe_ingredient WHERE recipe_id = :recipeId")
|
@Query("DELETE FROM recipe_ingredient WHERE recipe_id = :recipeId")
|
||||||
suspend fun deleteRecipeIngredients(recipeId: Long)
|
suspend fun deleteRecipeIngredients(recipeId: String)
|
||||||
|
|
||||||
@Query("DELETE FROM recipe_instruction WHERE recipe_id = :recipeId")
|
@Query("DELETE FROM recipe_instruction WHERE recipe_id = :recipeId")
|
||||||
suspend fun deleteRecipeInstructions(recipeId: Long)
|
suspend fun deleteRecipeInstructions(recipeId: String)
|
||||||
}
|
}
|
||||||
@@ -25,5 +25,5 @@ import androidx.room.Index
|
|||||||
)
|
)
|
||||||
data class CategoryRecipeEntity(
|
data class CategoryRecipeEntity(
|
||||||
@ColumnInfo(name = "category_id") val categoryId: Long,
|
@ColumnInfo(name = "category_id") val categoryId: Long,
|
||||||
@ColumnInfo(name = "recipe_id", index = true) val recipeId: Long
|
@ColumnInfo(name = "recipe_id", index = true) val recipeId: String,
|
||||||
)
|
)
|
||||||
@@ -6,6 +6,6 @@ import androidx.room.PrimaryKey
|
|||||||
|
|
||||||
@Entity(tableName = "recipe")
|
@Entity(tableName = "recipe")
|
||||||
data class RecipeEntity(
|
data class RecipeEntity(
|
||||||
@PrimaryKey @ColumnInfo(name = "remote_id") val remoteId: Long,
|
@PrimaryKey @ColumnInfo(name = "remote_id") val remoteId: String,
|
||||||
@ColumnInfo(name = "recipe_yield") val recipeYield: String,
|
@ColumnInfo(name = "recipe_yield") val recipeYield: String,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ import androidx.room.PrimaryKey
|
|||||||
@Entity(tableName = "recipe_ingredient")
|
@Entity(tableName = "recipe_ingredient")
|
||||||
data class RecipeIngredientEntity(
|
data class RecipeIngredientEntity(
|
||||||
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "local_id") val localId: Long = 0,
|
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "local_id") val localId: Long = 0,
|
||||||
@ColumnInfo(name = "recipe_id") val recipeId: Long,
|
@ColumnInfo(name = "recipe_id") val recipeId: String,
|
||||||
@ColumnInfo(name = "title") val title: String,
|
@ColumnInfo(name = "title") val title: String,
|
||||||
@ColumnInfo(name = "note") val note: String,
|
@ColumnInfo(name = "note") val note: String,
|
||||||
@ColumnInfo(name = "unit") val unit: String,
|
@ColumnInfo(name = "unit") val unit: String,
|
||||||
@ColumnInfo(name = "food") val food: String,
|
@ColumnInfo(name = "food") val food: String,
|
||||||
@ColumnInfo(name = "disable_amount") val disableAmount: Boolean,
|
@ColumnInfo(name = "disable_amount") val disableAmount: Boolean,
|
||||||
@ColumnInfo(name = "quantity") val quantity: Int,
|
@ColumnInfo(name = "quantity") val quantity: Double,
|
||||||
)
|
)
|
||||||
@@ -7,7 +7,7 @@ import androidx.room.PrimaryKey
|
|||||||
@Entity(tableName = "recipe_instruction")
|
@Entity(tableName = "recipe_instruction")
|
||||||
data class RecipeInstructionEntity(
|
data class RecipeInstructionEntity(
|
||||||
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "local_id") val localId: Long = 0,
|
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "local_id") val localId: Long = 0,
|
||||||
@ColumnInfo(name = "recipe_id") val recipeId: Long,
|
@ColumnInfo(name = "recipe_id") val recipeId: String,
|
||||||
@ColumnInfo(name = "title") val title: String,
|
@ColumnInfo(name = "title") val title: String,
|
||||||
@ColumnInfo(name = "text") val text: String,
|
@ColumnInfo(name = "text") val text: String,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import kotlinx.datetime.LocalDateTime
|
|||||||
|
|
||||||
@Entity(tableName = "recipe_summaries")
|
@Entity(tableName = "recipe_summaries")
|
||||||
data class RecipeSummaryEntity(
|
data class RecipeSummaryEntity(
|
||||||
@PrimaryKey @ColumnInfo(name = "remote_id") val remoteId: Long,
|
@PrimaryKey @ColumnInfo(name = "remote_id") val remoteId: String,
|
||||||
@ColumnInfo(name = "name") val name: String,
|
@ColumnInfo(name = "name") val name: String,
|
||||||
@ColumnInfo(name = "slug") val slug: String,
|
@ColumnInfo(name = "slug") val slug: String,
|
||||||
@ColumnInfo(name = "image") val image: String?,
|
@ColumnInfo(name = "image") val image: String?,
|
||||||
|
|||||||
@@ -23,5 +23,5 @@ import androidx.room.ForeignKey
|
|||||||
)
|
)
|
||||||
data class TagRecipeEntity(
|
data class TagRecipeEntity(
|
||||||
@ColumnInfo(name = "tag_id") val tagId: Long,
|
@ColumnInfo(name = "tag_id") val tagId: Long,
|
||||||
@ColumnInfo(name = "recipe_id", index = true) val recipeId: Long
|
@ColumnInfo(name = "recipe_id", index = true) val recipeId: String,
|
||||||
)
|
)
|
||||||
@@ -44,6 +44,19 @@ class MealieDataSourceImpl @Inject constructor(
|
|||||||
block = { getVersion("$baseUrl/api/debug/version") },
|
block = { getVersion("$baseUrl/api/debug/version") },
|
||||||
logMethod = { "getVersionInfo" },
|
logMethod = { "getVersionInfo" },
|
||||||
logParameters = { "baseUrl = $baseUrl" },
|
logParameters = { "baseUrl = $baseUrl" },
|
||||||
|
).getOrElse {
|
||||||
|
when (it) {
|
||||||
|
is HttpException, is SerializationException -> getVersionInfoV1(baseUrl)
|
||||||
|
is SocketTimeoutException,
|
||||||
|
is ConnectException -> throw NetworkError.NoServerConnection(it)
|
||||||
|
else -> throw NetworkError.MalformedUrl(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun getVersionInfoV1(baseUrl: String): VersionResponse = makeCall(
|
||||||
|
block = { getVersion("$baseUrl/api/app/about") },
|
||||||
|
logMethod = { "getVersionInfoV1" },
|
||||||
|
logParameters = { "baseUrl = $baseUrl" },
|
||||||
).getOrElse {
|
).getOrElse {
|
||||||
throw when (it) {
|
throw when (it) {
|
||||||
is HttpException, is SerializationException -> NetworkError.NotMealie(it)
|
is HttpException, is SerializationException -> NetworkError.NotMealie(it)
|
||||||
@@ -58,7 +71,23 @@ class MealieDataSourceImpl @Inject constructor(
|
|||||||
block = { getRecipeSummary("$baseUrl/api/recipes/summary", token, start, limit) },
|
block = { getRecipeSummary("$baseUrl/api/recipes/summary", token, start, limit) },
|
||||||
logMethod = { "requestRecipes" },
|
logMethod = { "requestRecipes" },
|
||||||
logParameters = { "baseUrl = $baseUrl, token = $token, start = $start, limit = $limit" }
|
logParameters = { "baseUrl = $baseUrl, token = $token, start = $start, limit = $limit" }
|
||||||
).getOrThrowUnauthorized()
|
).getOrElse {
|
||||||
|
val code = (it as? HttpException)?.code() ?: throw it
|
||||||
|
if (code == 404) requestRecipesV1(baseUrl, token, start, limit) else throw it
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun requestRecipesV1(
|
||||||
|
baseUrl: String, token: String?, start: Int, limit: Int
|
||||||
|
): List<GetRecipeSummaryResponse> {
|
||||||
|
// Imagine start is 30 and limit is 15. It means that we already have page 1 and 2, now we need page 3
|
||||||
|
val perPage = limit
|
||||||
|
val page = start / perPage + 1
|
||||||
|
return makeCall(
|
||||||
|
block = { getRecipeSummaryV1("$baseUrl/api/recipes", token, page, perPage) },
|
||||||
|
logMethod = { "requestRecipesV1" },
|
||||||
|
logParameters = { "baseUrl = $baseUrl, token = $token, start = $start, limit = $limit" }
|
||||||
|
).map { it.items }.getOrThrowUnauthorized()
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun requestRecipeInfo(
|
override suspend fun requestRecipeInfo(
|
||||||
baseUrl: String, token: String?, slug: String
|
baseUrl: String, token: String?, slug: String
|
||||||
|
|||||||
@@ -34,6 +34,14 @@ interface MealieService {
|
|||||||
@Query("limit") limit: Int,
|
@Query("limit") limit: Int,
|
||||||
): List<GetRecipeSummaryResponse>
|
): List<GetRecipeSummaryResponse>
|
||||||
|
|
||||||
|
@GET
|
||||||
|
suspend fun getRecipeSummaryV1(
|
||||||
|
@Url url: String,
|
||||||
|
@Header(AUTHORIZATION_HEADER_NAME) token: String?,
|
||||||
|
@Query("page") page: Int,
|
||||||
|
@Query("perPage") perPage: Int,
|
||||||
|
): GetRecipesResponseV1
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
suspend fun getRecipe(
|
suspend fun getRecipe(
|
||||||
@Url url: String,
|
@Url url: String,
|
||||||
|
|||||||
@@ -10,5 +10,5 @@ data class GetRecipeIngredientResponse(
|
|||||||
@SerialName("unit") val unit: String = "",
|
@SerialName("unit") val unit: String = "",
|
||||||
@SerialName("food") val food: String = "",
|
@SerialName("food") val food: String = "",
|
||||||
@SerialName("disableAmount") val disableAmount: Boolean,
|
@SerialName("disableAmount") val disableAmount: Boolean,
|
||||||
@SerialName("quantity") val quantity: Int,
|
@SerialName("quantity") val quantity: Double,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import kotlinx.serialization.Serializable
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class GetRecipeResponse(
|
data class GetRecipeResponse(
|
||||||
@SerialName("id") val remoteId: Long,
|
@SerialName("id") val remoteId: String,
|
||||||
@SerialName("name") val name: String,
|
@SerialName("name") val name: String,
|
||||||
@SerialName("slug") val slug: String,
|
@SerialName("slug") val slug: String,
|
||||||
@SerialName("image") val image: String,
|
@SerialName("image") val image: String,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import kotlinx.serialization.Serializable
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class GetRecipeSummaryResponse(
|
data class GetRecipeSummaryResponse(
|
||||||
@SerialName("id") val remoteId: Long,
|
@SerialName("id") val remoteId: String,
|
||||||
@SerialName("name") val name: String,
|
@SerialName("name") val name: String,
|
||||||
@SerialName("slug") val slug: String,
|
@SerialName("slug") val slug: String,
|
||||||
@SerialName("image") val image: String?,
|
@SerialName("image") val image: String?,
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package gq.kirmanak.mealient.datasource.models
|
||||||
|
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class GetRecipesResponseV1(
|
||||||
|
@SerialName("items") val items: List<GetRecipeSummaryResponse>,
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user