Simplify network layer (#175)
* Use Ktor for network requests * Remove V0 version * Remove Retrofit dependency * Fix url * Update versions of dependencies * Revert kotlinx-datetime Due to https://github.com/Kotlin/kotlinx-datetime/issues/304 * Rename leftovers * Remove OkHttp * Remove unused manifest * Remove unused Hilt module * Fix building empty image URLs * Use OkHttp as engine for Ktor * Reduce visibility of internal classes * Fix first set up test * Store only auth token, not header * Remove UnitInfo/FoodInfo/VersionInfo/NewShoppingListItemInfo * Remove RecipeSummaryInfo and ShoppingListsInfo * Remove FullShoppingListInfo * Remove ParseRecipeURLInfo * Remove FullRecipeInfo * Sign out if access token does not work * Rename getVersionInfo method * Update version name
This commit is contained in:
@@ -5,138 +5,48 @@ import gq.kirmanak.mealient.database.recipe.entity.RecipeIngredientEntity
|
||||
import gq.kirmanak.mealient.database.recipe.entity.RecipeInstructionEntity
|
||||
import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeInfo
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeIngredient
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeIngredientInfo
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeInstruction
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeInstructionInfo
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeSettings
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeSettingsInfo
|
||||
import gq.kirmanak.mealient.datasource.models.FoodInfo
|
||||
import gq.kirmanak.mealient.datasource.models.FullRecipeInfo
|
||||
import gq.kirmanak.mealient.datasource.models.FullShoppingListInfo
|
||||
import gq.kirmanak.mealient.datasource.models.NewShoppingListItemInfo
|
||||
import gq.kirmanak.mealient.datasource.models.ParseRecipeURLInfo
|
||||
import gq.kirmanak.mealient.datasource.models.RecipeIngredientInfo
|
||||
import gq.kirmanak.mealient.datasource.models.RecipeInstructionInfo
|
||||
import gq.kirmanak.mealient.datasource.models.RecipeSettingsInfo
|
||||
import gq.kirmanak.mealient.datasource.models.RecipeSummaryInfo
|
||||
import gq.kirmanak.mealient.datasource.models.ShoppingListInfo
|
||||
import gq.kirmanak.mealient.datasource.models.ShoppingListItemInfo
|
||||
import gq.kirmanak.mealient.datasource.models.ShoppingListItemRecipeReferenceInfo
|
||||
import gq.kirmanak.mealient.datasource.models.ShoppingListsInfo
|
||||
import gq.kirmanak.mealient.datasource.models.UnitInfo
|
||||
import gq.kirmanak.mealient.datasource.models.VersionInfo
|
||||
import gq.kirmanak.mealient.datasource.v0.models.AddRecipeIngredientV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.AddRecipeInstructionV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.AddRecipeRequestV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.AddRecipeSettingsV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.GetRecipeIngredientResponseV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.GetRecipeInstructionResponseV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.GetRecipeResponseV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.GetRecipeSummaryResponseV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.ParseRecipeURLRequestV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.VersionResponseV0
|
||||
import gq.kirmanak.mealient.datasource.v1.models.AddRecipeIngredientV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.AddRecipeInstructionV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.AddRecipeSettingsV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.CreateRecipeRequestV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.CreateShoppingListItemRequestV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetFoodsResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetRecipeIngredientResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetRecipeInstructionResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetRecipeResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetRecipeSettingsResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetRecipeSummaryResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetShoppingListItemRecipeReferenceFullResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetShoppingListItemResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetShoppingListResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetShoppingListsResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetShoppingListsSummaryResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetUnitsResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.ParseRecipeURLRequestV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.UpdateRecipeRequestV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.VersionResponseV1
|
||||
import gq.kirmanak.mealient.datasource.models.CreateRecipeRequest
|
||||
import gq.kirmanak.mealient.datasource.models.GetRecipeIngredientResponse
|
||||
import gq.kirmanak.mealient.datasource.models.GetRecipeInstructionResponse
|
||||
import gq.kirmanak.mealient.datasource.models.GetRecipeResponse
|
||||
import gq.kirmanak.mealient.datasource.models.GetRecipeSummaryResponse
|
||||
import gq.kirmanak.mealient.datasource.models.UpdateRecipeRequest
|
||||
import gq.kirmanak.mealient.datastore.recipe.AddRecipeDraft
|
||||
|
||||
interface ModelMapper {
|
||||
|
||||
fun toRecipeEntity(fullRecipeInfo: FullRecipeInfo): RecipeEntity
|
||||
fun toRecipeEntity(getRecipeResponse: GetRecipeResponse): RecipeEntity
|
||||
|
||||
fun toRecipeIngredientEntity(
|
||||
recipeIngredientInfo: RecipeIngredientInfo, remoteId: String
|
||||
ingredientResponse: GetRecipeIngredientResponse, remoteId: String
|
||||
): RecipeIngredientEntity
|
||||
|
||||
fun toRecipeInstructionEntity(
|
||||
recipeInstructionInfo: RecipeInstructionInfo, remoteId: String
|
||||
instructionResponse: GetRecipeInstructionResponse, remoteId: String
|
||||
): RecipeInstructionEntity
|
||||
|
||||
fun toRecipeSummaryEntity(
|
||||
recipeSummaryInfo: RecipeSummaryInfo, isFavorite: Boolean
|
||||
recipeSummaryInfo: GetRecipeSummaryResponse, isFavorite: Boolean
|
||||
): RecipeSummaryEntity
|
||||
|
||||
fun toAddRecipeInfo(addRecipeDraft: AddRecipeDraft): AddRecipeInfo
|
||||
|
||||
fun toDraft(addRecipeInfo: AddRecipeInfo): AddRecipeDraft
|
||||
|
||||
fun toVersionInfo(versionResponseV1: VersionResponseV1): VersionInfo
|
||||
fun toCreateRequest(addRecipeInfo: AddRecipeInfo): CreateRecipeRequest
|
||||
|
||||
fun toFullRecipeInfo(getRecipeResponseV1: GetRecipeResponseV1): FullRecipeInfo
|
||||
fun toUpdateRequest(addRecipeInfo: AddRecipeInfo): UpdateRecipeRequest
|
||||
|
||||
fun toRecipeSettingsInfo(getRecipeSettingsResponseV1: GetRecipeSettingsResponseV1?): RecipeSettingsInfo
|
||||
fun toSettings(addRecipeSettingsInfo: AddRecipeSettingsInfo): AddRecipeSettings
|
||||
|
||||
fun toRecipeIngredientInfo(getRecipeIngredientResponseV1: GetRecipeIngredientResponseV1): RecipeIngredientInfo
|
||||
fun toIngredient(addRecipeIngredientInfo: AddRecipeIngredientInfo): AddRecipeIngredient
|
||||
|
||||
fun toRecipeInstructionInfo(getRecipeInstructionResponseV1: GetRecipeInstructionResponseV1): RecipeInstructionInfo
|
||||
fun toInstruction(addRecipeInstructionInfo: AddRecipeInstructionInfo): AddRecipeInstruction
|
||||
|
||||
fun toV1CreateRequest(addRecipeInfo: AddRecipeInfo): CreateRecipeRequestV1
|
||||
|
||||
fun toV1UpdateRequest(addRecipeInfo: AddRecipeInfo): UpdateRecipeRequestV1
|
||||
|
||||
fun toV1Settings(addRecipeSettingsInfo: AddRecipeSettingsInfo): AddRecipeSettingsV1
|
||||
|
||||
fun toV1Ingredient(addRecipeIngredientInfo: AddRecipeIngredientInfo): AddRecipeIngredientV1
|
||||
|
||||
fun toV1Instruction(addRecipeInstructionInfo: AddRecipeInstructionInfo): AddRecipeInstructionV1
|
||||
|
||||
fun toV1Request(parseRecipeURLInfo: ParseRecipeURLInfo): ParseRecipeURLRequestV1
|
||||
|
||||
fun toFullShoppingListInfo(getShoppingListResponseV1: GetShoppingListResponseV1): FullShoppingListInfo
|
||||
|
||||
fun toShoppingListItemInfo(
|
||||
getShoppingListItemResponseV1: GetShoppingListItemResponseV1,
|
||||
recipes: Map<String, List<GetShoppingListItemRecipeReferenceFullResponseV1>>
|
||||
): ShoppingListItemInfo
|
||||
|
||||
fun toShoppingListItemRecipeReferenceInfo(
|
||||
getShoppingListItemRecipeReferenceFullResponseV1: GetShoppingListItemRecipeReferenceFullResponseV1
|
||||
): ShoppingListItemRecipeReferenceInfo
|
||||
|
||||
fun toShoppingListsInfo(getShoppingListsResponseV1: GetShoppingListsResponseV1): ShoppingListsInfo
|
||||
|
||||
fun toShoppingListInfo(getShoppingListsSummaryResponseV1: GetShoppingListsSummaryResponseV1): ShoppingListInfo
|
||||
|
||||
fun toRecipeSummaryInfo(getRecipeSummaryResponseV1: GetRecipeSummaryResponseV1): RecipeSummaryInfo
|
||||
|
||||
fun toRecipeSummaryInfo(getRecipeSummaryResponseV0: GetRecipeSummaryResponseV0): RecipeSummaryInfo
|
||||
|
||||
fun toVersionInfo(versionResponseV0: VersionResponseV0): VersionInfo
|
||||
|
||||
fun toFullRecipeInfo(getRecipeResponseV0: GetRecipeResponseV0): FullRecipeInfo
|
||||
|
||||
fun toRecipeIngredientInfo(getRecipeIngredientResponseV0: GetRecipeIngredientResponseV0): RecipeIngredientInfo
|
||||
|
||||
fun toRecipeInstructionInfo(getRecipeInstructionResponseV0: GetRecipeInstructionResponseV0): RecipeInstructionInfo
|
||||
|
||||
fun toV0Request(addRecipeInfo: AddRecipeInfo): AddRecipeRequestV0
|
||||
|
||||
fun toV0Settings(addRecipeSettingsInfo: AddRecipeSettingsInfo): AddRecipeSettingsV0
|
||||
|
||||
fun toV0Ingredient(addRecipeIngredientInfo: AddRecipeIngredientInfo): AddRecipeIngredientV0
|
||||
|
||||
fun toV0Instruction(addRecipeInstructionInfo: AddRecipeInstructionInfo): AddRecipeInstructionV0
|
||||
|
||||
fun toV0Request(parseRecipeURLInfo: ParseRecipeURLInfo): ParseRecipeURLRequestV0
|
||||
|
||||
fun toFoodInfo(getFoodsResponseV1: GetFoodsResponseV1): List<FoodInfo>
|
||||
|
||||
fun toUnitInfo(getUnitsResponseV1: GetUnitsResponseV1): List<UnitInfo>
|
||||
|
||||
fun toV1CreateRequest(addRecipeInfo: NewShoppingListItemInfo): CreateShoppingListItemRequestV1
|
||||
}
|
||||
@@ -5,58 +5,18 @@ import gq.kirmanak.mealient.database.recipe.entity.RecipeIngredientEntity
|
||||
import gq.kirmanak.mealient.database.recipe.entity.RecipeInstructionEntity
|
||||
import gq.kirmanak.mealient.database.recipe.entity.RecipeSummaryEntity
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeInfo
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeIngredient
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeIngredientInfo
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeInstruction
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeInstructionInfo
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeSettings
|
||||
import gq.kirmanak.mealient.datasource.models.AddRecipeSettingsInfo
|
||||
import gq.kirmanak.mealient.datasource.models.FoodInfo
|
||||
import gq.kirmanak.mealient.datasource.models.FullRecipeInfo
|
||||
import gq.kirmanak.mealient.datasource.models.FullShoppingListInfo
|
||||
import gq.kirmanak.mealient.datasource.models.NewShoppingListItemInfo
|
||||
import gq.kirmanak.mealient.datasource.models.ParseRecipeURLInfo
|
||||
import gq.kirmanak.mealient.datasource.models.RecipeIngredientInfo
|
||||
import gq.kirmanak.mealient.datasource.models.RecipeInstructionInfo
|
||||
import gq.kirmanak.mealient.datasource.models.RecipeSettingsInfo
|
||||
import gq.kirmanak.mealient.datasource.models.RecipeSummaryInfo
|
||||
import gq.kirmanak.mealient.datasource.models.ShoppingListInfo
|
||||
import gq.kirmanak.mealient.datasource.models.ShoppingListItemInfo
|
||||
import gq.kirmanak.mealient.datasource.models.ShoppingListItemRecipeReferenceInfo
|
||||
import gq.kirmanak.mealient.datasource.models.ShoppingListsInfo
|
||||
import gq.kirmanak.mealient.datasource.models.UnitInfo
|
||||
import gq.kirmanak.mealient.datasource.models.VersionInfo
|
||||
import gq.kirmanak.mealient.datasource.v0.models.AddRecipeIngredientV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.AddRecipeInstructionV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.AddRecipeRequestV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.AddRecipeSettingsV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.GetRecipeIngredientResponseV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.GetRecipeInstructionResponseV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.GetRecipeResponseV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.GetRecipeSummaryResponseV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.ParseRecipeURLRequestV0
|
||||
import gq.kirmanak.mealient.datasource.v0.models.VersionResponseV0
|
||||
import gq.kirmanak.mealient.datasource.v1.models.AddRecipeIngredientV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.AddRecipeInstructionV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.AddRecipeSettingsV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.CreateRecipeRequestV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.CreateShoppingListItemRequestV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetFoodResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetFoodsResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetRecipeIngredientFoodResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetRecipeIngredientResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetRecipeIngredientUnitResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetRecipeInstructionResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetRecipeResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetRecipeSettingsResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetRecipeSummaryResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetShoppingListItemRecipeReferenceFullResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetShoppingListItemResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetShoppingListResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetShoppingListsResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetShoppingListsSummaryResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetUnitResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.GetUnitsResponseV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.ParseRecipeURLRequestV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.UpdateRecipeRequestV1
|
||||
import gq.kirmanak.mealient.datasource.v1.models.VersionResponseV1
|
||||
import gq.kirmanak.mealient.datasource.models.CreateRecipeRequest
|
||||
import gq.kirmanak.mealient.datasource.models.GetRecipeIngredientResponse
|
||||
import gq.kirmanak.mealient.datasource.models.GetRecipeInstructionResponse
|
||||
import gq.kirmanak.mealient.datasource.models.GetRecipeResponse
|
||||
import gq.kirmanak.mealient.datasource.models.GetRecipeSummaryResponse
|
||||
import gq.kirmanak.mealient.datasource.models.UpdateRecipeRequest
|
||||
import gq.kirmanak.mealient.datastore.recipe.AddRecipeDraft
|
||||
import java.util.UUID
|
||||
import javax.inject.Inject
|
||||
@@ -64,30 +24,36 @@ import javax.inject.Inject
|
||||
class ModelMapperImpl @Inject constructor() : ModelMapper {
|
||||
|
||||
|
||||
override fun toRecipeEntity(fullRecipeInfo: FullRecipeInfo) = RecipeEntity(
|
||||
remoteId = fullRecipeInfo.remoteId,
|
||||
recipeYield = fullRecipeInfo.recipeYield,
|
||||
disableAmounts = fullRecipeInfo.settings.disableAmounts,
|
||||
override fun toRecipeEntity(getRecipeResponse: GetRecipeResponse) = RecipeEntity(
|
||||
remoteId = getRecipeResponse.remoteId,
|
||||
recipeYield = getRecipeResponse.recipeYield,
|
||||
disableAmounts = getRecipeResponse.settings?.disableAmount ?: true,
|
||||
)
|
||||
|
||||
override fun toRecipeIngredientEntity(
|
||||
recipeIngredientInfo: RecipeIngredientInfo, remoteId: String
|
||||
ingredientResponse: GetRecipeIngredientResponse,
|
||||
remoteId: String
|
||||
) = RecipeIngredientEntity(
|
||||
recipeId = remoteId,
|
||||
note = recipeIngredientInfo.note,
|
||||
unit = recipeIngredientInfo.unit,
|
||||
food = recipeIngredientInfo.food,
|
||||
quantity = recipeIngredientInfo.quantity,
|
||||
title = recipeIngredientInfo.title,
|
||||
note = ingredientResponse.note,
|
||||
unit = ingredientResponse.unit?.name,
|
||||
food = ingredientResponse.food?.name,
|
||||
quantity = ingredientResponse.quantity,
|
||||
title = ingredientResponse.title,
|
||||
)
|
||||
|
||||
override fun toRecipeInstructionEntity(
|
||||
recipeInstructionInfo: RecipeInstructionInfo, remoteId: String
|
||||
instructionResponse: GetRecipeInstructionResponse,
|
||||
remoteId: String
|
||||
) = RecipeInstructionEntity(
|
||||
recipeId = remoteId, text = recipeInstructionInfo.text
|
||||
recipeId = remoteId,
|
||||
text = instructionResponse.text,
|
||||
)
|
||||
|
||||
override fun toRecipeSummaryEntity(recipeSummaryInfo: RecipeSummaryInfo, isFavorite: Boolean) =
|
||||
override fun toRecipeSummaryEntity(
|
||||
recipeSummaryInfo: GetRecipeSummaryResponse,
|
||||
isFavorite: Boolean
|
||||
) =
|
||||
RecipeSummaryEntity(
|
||||
remoteId = recipeSummaryInfo.remoteId,
|
||||
name = recipeSummaryInfo.name,
|
||||
@@ -95,7 +61,7 @@ class ModelMapperImpl @Inject constructor() : ModelMapper {
|
||||
description = recipeSummaryInfo.description,
|
||||
dateAdded = recipeSummaryInfo.dateAdded,
|
||||
dateUpdated = recipeSummaryInfo.dateUpdated,
|
||||
imageId = recipeSummaryInfo.imageId,
|
||||
imageId = recipeSummaryInfo.remoteId,
|
||||
isFavorite = isFavorite,
|
||||
)
|
||||
|
||||
@@ -122,246 +88,35 @@ class ModelMapperImpl @Inject constructor() : ModelMapper {
|
||||
)
|
||||
|
||||
|
||||
override fun toVersionInfo(versionResponseV1: VersionResponseV1) =
|
||||
VersionInfo(versionResponseV1.version)
|
||||
|
||||
override fun toFullRecipeInfo(getRecipeResponseV1: GetRecipeResponseV1) = FullRecipeInfo(
|
||||
remoteId = getRecipeResponseV1.remoteId,
|
||||
name = getRecipeResponseV1.name,
|
||||
recipeYield = getRecipeResponseV1.recipeYield,
|
||||
recipeIngredients = getRecipeResponseV1.recipeIngredients.map { toRecipeIngredientInfo(it) },
|
||||
recipeInstructions = getRecipeResponseV1.recipeInstructions.map { toRecipeInstructionInfo(it) },
|
||||
settings = toRecipeSettingsInfo(getRecipeResponseV1.settings),
|
||||
)
|
||||
|
||||
override fun toRecipeSettingsInfo(getRecipeSettingsResponseV1: GetRecipeSettingsResponseV1?) =
|
||||
RecipeSettingsInfo(
|
||||
disableAmounts = getRecipeSettingsResponseV1?.disableAmount ?: true,
|
||||
)
|
||||
|
||||
override fun toRecipeIngredientInfo(getRecipeIngredientResponseV1: GetRecipeIngredientResponseV1) =
|
||||
RecipeIngredientInfo(
|
||||
note = getRecipeIngredientResponseV1.note,
|
||||
unit = getRecipeIngredientResponseV1.unit?.name,
|
||||
food = getRecipeIngredientResponseV1.food?.name,
|
||||
quantity = getRecipeIngredientResponseV1.quantity,
|
||||
title = getRecipeIngredientResponseV1.title,
|
||||
)
|
||||
|
||||
override fun toRecipeInstructionInfo(getRecipeInstructionResponseV1: GetRecipeInstructionResponseV1) =
|
||||
RecipeInstructionInfo(
|
||||
text = getRecipeInstructionResponseV1.text
|
||||
)
|
||||
|
||||
override fun toV1CreateRequest(addRecipeInfo: AddRecipeInfo) = CreateRecipeRequestV1(
|
||||
override fun toCreateRequest(addRecipeInfo: AddRecipeInfo) = CreateRecipeRequest(
|
||||
name = addRecipeInfo.name,
|
||||
)
|
||||
|
||||
override fun toV1UpdateRequest(addRecipeInfo: AddRecipeInfo) = UpdateRecipeRequestV1(
|
||||
override fun toUpdateRequest(addRecipeInfo: AddRecipeInfo) = UpdateRecipeRequest(
|
||||
description = addRecipeInfo.description,
|
||||
recipeYield = addRecipeInfo.recipeYield,
|
||||
recipeIngredient = addRecipeInfo.recipeIngredient.map { toV1Ingredient(it) },
|
||||
recipeInstructions = addRecipeInfo.recipeInstructions.map { toV1Instruction(it) },
|
||||
settings = toV1Settings(addRecipeInfo.settings),
|
||||
recipeIngredient = addRecipeInfo.recipeIngredient.map { toIngredient(it) },
|
||||
recipeInstructions = addRecipeInfo.recipeInstructions.map { toInstruction(it) },
|
||||
settings = toSettings(addRecipeInfo.settings),
|
||||
)
|
||||
|
||||
override fun toV1Settings(addRecipeSettingsInfo: AddRecipeSettingsInfo) = AddRecipeSettingsV1(
|
||||
override fun toSettings(addRecipeSettingsInfo: AddRecipeSettingsInfo) = AddRecipeSettings(
|
||||
disableComments = addRecipeSettingsInfo.disableComments,
|
||||
public = addRecipeSettingsInfo.public,
|
||||
)
|
||||
|
||||
override fun toV1Ingredient(addRecipeIngredientInfo: AddRecipeIngredientInfo) =
|
||||
AddRecipeIngredientV1(
|
||||
override fun toIngredient(addRecipeIngredientInfo: AddRecipeIngredientInfo) =
|
||||
AddRecipeIngredient(
|
||||
id = UUID.randomUUID().toString(),
|
||||
note = addRecipeIngredientInfo.note,
|
||||
)
|
||||
|
||||
override fun toV1Instruction(addRecipeInstructionInfo: AddRecipeInstructionInfo) =
|
||||
AddRecipeInstructionV1(
|
||||
override fun toInstruction(addRecipeInstructionInfo: AddRecipeInstructionInfo) =
|
||||
AddRecipeInstruction(
|
||||
id = UUID.randomUUID().toString(),
|
||||
text = addRecipeInstructionInfo.text,
|
||||
ingredientReferences = emptyList(),
|
||||
)
|
||||
|
||||
override fun toV1Request(parseRecipeURLInfo: ParseRecipeURLInfo) = ParseRecipeURLRequestV1(
|
||||
url = parseRecipeURLInfo.url,
|
||||
includeTags = parseRecipeURLInfo.includeTags,
|
||||
)
|
||||
|
||||
override fun toFullShoppingListInfo(getShoppingListResponseV1: GetShoppingListResponseV1): FullShoppingListInfo {
|
||||
val recipes = getShoppingListResponseV1.recipeReferences.groupBy { it.recipeId }
|
||||
return FullShoppingListInfo(
|
||||
id = getShoppingListResponseV1.id,
|
||||
name = getShoppingListResponseV1.name,
|
||||
items = getShoppingListResponseV1.listItems.map { toShoppingListItemInfo(it, recipes) },
|
||||
)
|
||||
}
|
||||
|
||||
override fun toShoppingListItemInfo(
|
||||
getShoppingListItemResponseV1: GetShoppingListItemResponseV1,
|
||||
recipes: Map<String, List<GetShoppingListItemRecipeReferenceFullResponseV1>>
|
||||
): ShoppingListItemInfo = ShoppingListItemInfo(
|
||||
shoppingListId = getShoppingListItemResponseV1.shoppingListId,
|
||||
id = getShoppingListItemResponseV1.id,
|
||||
checked = getShoppingListItemResponseV1.checked,
|
||||
position = getShoppingListItemResponseV1.position,
|
||||
isFood = getShoppingListItemResponseV1.isFood,
|
||||
note = getShoppingListItemResponseV1.note,
|
||||
quantity = getShoppingListItemResponseV1.quantity,
|
||||
unit = getShoppingListItemResponseV1.unit?.let { toUnitInfo(it) },
|
||||
food = getShoppingListItemResponseV1.food?.let { toFoodInfo(it) },
|
||||
recipeReferences = getShoppingListItemResponseV1.recipeReferences.map { it.recipeId }
|
||||
.mapNotNull { recipes[it] }.flatten().map { toShoppingListItemRecipeReferenceInfo(it) },
|
||||
)
|
||||
|
||||
private fun toUnitInfo(getRecipeIngredientUnitResponseV1: GetRecipeIngredientUnitResponseV1): UnitInfo {
|
||||
return UnitInfo(
|
||||
name = getRecipeIngredientUnitResponseV1.name,
|
||||
id = getRecipeIngredientUnitResponseV1.id,
|
||||
)
|
||||
}
|
||||
|
||||
private fun toFoodInfo(getRecipeIngredientFoodResponseV1: GetRecipeIngredientFoodResponseV1): FoodInfo {
|
||||
return FoodInfo(
|
||||
name = getRecipeIngredientFoodResponseV1.name,
|
||||
id = getRecipeIngredientFoodResponseV1.id,
|
||||
)
|
||||
}
|
||||
|
||||
override fun toShoppingListItemRecipeReferenceInfo(
|
||||
getShoppingListItemRecipeReferenceFullResponseV1: GetShoppingListItemRecipeReferenceFullResponseV1
|
||||
) = ShoppingListItemRecipeReferenceInfo(
|
||||
recipeId = getShoppingListItemRecipeReferenceFullResponseV1.recipeId,
|
||||
recipeQuantity = getShoppingListItemRecipeReferenceFullResponseV1.recipeQuantity,
|
||||
id = getShoppingListItemRecipeReferenceFullResponseV1.id,
|
||||
shoppingListId = getShoppingListItemRecipeReferenceFullResponseV1.shoppingListId,
|
||||
recipe = toFullRecipeInfo(getShoppingListItemRecipeReferenceFullResponseV1.recipe),
|
||||
)
|
||||
|
||||
override fun toShoppingListsInfo(getShoppingListsResponseV1: GetShoppingListsResponseV1) =
|
||||
ShoppingListsInfo(
|
||||
page = getShoppingListsResponseV1.page,
|
||||
perPage = getShoppingListsResponseV1.perPage,
|
||||
totalPages = getShoppingListsResponseV1.totalPages,
|
||||
totalItems = getShoppingListsResponseV1.total,
|
||||
items = getShoppingListsResponseV1.items.map { toShoppingListInfo(it) },
|
||||
)
|
||||
|
||||
override fun toShoppingListInfo(getShoppingListsSummaryResponseV1: GetShoppingListsSummaryResponseV1) =
|
||||
ShoppingListInfo(
|
||||
name = getShoppingListsSummaryResponseV1.name.orEmpty(),
|
||||
id = getShoppingListsSummaryResponseV1.id,
|
||||
)
|
||||
|
||||
override fun toRecipeSummaryInfo(getRecipeSummaryResponseV1: GetRecipeSummaryResponseV1) =
|
||||
RecipeSummaryInfo(
|
||||
remoteId = getRecipeSummaryResponseV1.remoteId,
|
||||
name = getRecipeSummaryResponseV1.name,
|
||||
slug = getRecipeSummaryResponseV1.slug,
|
||||
description = getRecipeSummaryResponseV1.description,
|
||||
dateAdded = getRecipeSummaryResponseV1.dateAdded,
|
||||
dateUpdated = getRecipeSummaryResponseV1.dateUpdated,
|
||||
imageId = getRecipeSummaryResponseV1.remoteId,
|
||||
)
|
||||
|
||||
|
||||
override fun toRecipeSummaryInfo(getRecipeSummaryResponseV0: GetRecipeSummaryResponseV0) =
|
||||
RecipeSummaryInfo(
|
||||
remoteId = getRecipeSummaryResponseV0.remoteId.toString(),
|
||||
name = getRecipeSummaryResponseV0.name,
|
||||
slug = getRecipeSummaryResponseV0.slug,
|
||||
description = getRecipeSummaryResponseV0.description,
|
||||
dateAdded = getRecipeSummaryResponseV0.dateAdded,
|
||||
dateUpdated = getRecipeSummaryResponseV0.dateUpdated,
|
||||
imageId = getRecipeSummaryResponseV0.slug,
|
||||
)
|
||||
|
||||
override fun toVersionInfo(versionResponseV0: VersionResponseV0) =
|
||||
VersionInfo(versionResponseV0.version)
|
||||
|
||||
override fun toFullRecipeInfo(getRecipeResponseV0: GetRecipeResponseV0) = FullRecipeInfo(
|
||||
remoteId = getRecipeResponseV0.remoteId.toString(),
|
||||
name = getRecipeResponseV0.name,
|
||||
recipeYield = getRecipeResponseV0.recipeYield,
|
||||
recipeIngredients = getRecipeResponseV0.recipeIngredients.map { toRecipeIngredientInfo(it) },
|
||||
recipeInstructions = getRecipeResponseV0.recipeInstructions.map { toRecipeInstructionInfo(it) },
|
||||
settings = RecipeSettingsInfo(disableAmounts = true)
|
||||
)
|
||||
|
||||
override fun toRecipeIngredientInfo(getRecipeIngredientResponseV0: GetRecipeIngredientResponseV0) =
|
||||
RecipeIngredientInfo(
|
||||
note = getRecipeIngredientResponseV0.note,
|
||||
unit = null,
|
||||
food = null,
|
||||
quantity = 1.0,
|
||||
title = null,
|
||||
)
|
||||
|
||||
override fun toRecipeInstructionInfo(getRecipeInstructionResponseV0: GetRecipeInstructionResponseV0) =
|
||||
RecipeInstructionInfo(
|
||||
text = getRecipeInstructionResponseV0.text
|
||||
)
|
||||
|
||||
override fun toV0Request(addRecipeInfo: AddRecipeInfo) = AddRecipeRequestV0(
|
||||
name = addRecipeInfo.name,
|
||||
description = addRecipeInfo.description,
|
||||
recipeYield = addRecipeInfo.recipeYield,
|
||||
recipeIngredient = addRecipeInfo.recipeIngredient.map { toV0Ingredient(it) },
|
||||
recipeInstructions = addRecipeInfo.recipeInstructions.map { toV0Instruction(it) },
|
||||
settings = toV0Settings(addRecipeInfo.settings),
|
||||
)
|
||||
|
||||
override fun toV0Settings(addRecipeSettingsInfo: AddRecipeSettingsInfo) = AddRecipeSettingsV0(
|
||||
disableComments = addRecipeSettingsInfo.disableComments,
|
||||
public = addRecipeSettingsInfo.public,
|
||||
)
|
||||
|
||||
override fun toV0Ingredient(addRecipeIngredientInfo: AddRecipeIngredientInfo) =
|
||||
AddRecipeIngredientV0(
|
||||
note = addRecipeIngredientInfo.note,
|
||||
)
|
||||
|
||||
override fun toV0Instruction(addRecipeInstructionInfo: AddRecipeInstructionInfo) =
|
||||
AddRecipeInstructionV0(
|
||||
text = addRecipeInstructionInfo.text,
|
||||
)
|
||||
|
||||
override fun toV0Request(parseRecipeURLInfo: ParseRecipeURLInfo) = ParseRecipeURLRequestV0(
|
||||
url = parseRecipeURLInfo.url,
|
||||
)
|
||||
|
||||
override fun toFoodInfo(getFoodsResponseV1: GetFoodsResponseV1): List<FoodInfo> {
|
||||
return getFoodsResponseV1.items.map { toFoodInfo(it) }
|
||||
}
|
||||
|
||||
private fun toFoodInfo(getFoodResponseV1: GetFoodResponseV1): FoodInfo {
|
||||
return FoodInfo(
|
||||
name = getFoodResponseV1.name,
|
||||
id = getFoodResponseV1.id,
|
||||
)
|
||||
}
|
||||
|
||||
override fun toUnitInfo(getUnitsResponseV1: GetUnitsResponseV1): List<UnitInfo> {
|
||||
return getUnitsResponseV1.items.map { toUnitInfo(it) }
|
||||
}
|
||||
|
||||
private fun toUnitInfo(getUnitResponseV1: GetUnitResponseV1): UnitInfo {
|
||||
return UnitInfo(
|
||||
name = getUnitResponseV1.name,
|
||||
id = getUnitResponseV1.id,
|
||||
)
|
||||
}
|
||||
|
||||
override fun toV1CreateRequest(addRecipeInfo: NewShoppingListItemInfo): CreateShoppingListItemRequestV1 {
|
||||
return CreateShoppingListItemRequestV1(
|
||||
shoppingListId = addRecipeInfo.shoppingListId,
|
||||
checked = false,
|
||||
position = addRecipeInfo.position,
|
||||
isFood = addRecipeInfo.isFood,
|
||||
note = addRecipeInfo.note,
|
||||
quantity = addRecipeInfo.quantity,
|
||||
foodId = addRecipeInfo.food?.id,
|
||||
unitId = addRecipeInfo.unit?.id,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -4,31 +4,12 @@ import com.google.common.truth.Truth.assertThat
|
||||
import gq.kirmanak.mealient.database.CAKE_RECIPE_ENTITY
|
||||
import gq.kirmanak.mealient.database.CAKE_SUGAR_RECIPE_INGREDIENT_ENTITY
|
||||
import gq.kirmanak.mealient.database.MIX_CAKE_RECIPE_INSTRUCTION_ENTITY
|
||||
import gq.kirmanak.mealient.database.PORRIDGE_RECIPE_SUMMARY_ENTITY
|
||||
import gq.kirmanak.mealient.datasource_test.CAKE_FULL_RECIPE_INFO
|
||||
import gq.kirmanak.mealient.datasource_test.MILK_RECIPE_INGREDIENT_INFO
|
||||
import gq.kirmanak.mealient.datasource_test.MILK_RECIPE_INGREDIENT_RESPONSE_V0
|
||||
import gq.kirmanak.mealient.datasource_test.MILK_RECIPE_INGREDIENT_RESPONSE_V1
|
||||
import gq.kirmanak.mealient.datasource_test.MIX_INSTRUCTION
|
||||
import gq.kirmanak.mealient.datasource_test.MIX_RECIPE_INSTRUCTION_INFO
|
||||
import gq.kirmanak.mealient.datasource_test.MIX_RECIPE_INSTRUCTION_RESPONSE_V0
|
||||
import gq.kirmanak.mealient.datasource_test.MIX_RECIPE_INSTRUCTION_RESPONSE_V1
|
||||
import gq.kirmanak.mealient.datasource_test.CAKE_RECIPE_RESPONSE
|
||||
import gq.kirmanak.mealient.datasource_test.MIX_RECIPE_INSTRUCTION_RESPONSE
|
||||
import gq.kirmanak.mealient.datasource_test.PORRIDGE_ADD_RECIPE_INFO
|
||||
import gq.kirmanak.mealient.datasource_test.PORRIDGE_ADD_RECIPE_REQUEST_V0
|
||||
import gq.kirmanak.mealient.datasource_test.PORRIDGE_CREATE_RECIPE_REQUEST_V1
|
||||
import gq.kirmanak.mealient.datasource_test.PORRIDGE_FULL_RECIPE_INFO
|
||||
import gq.kirmanak.mealient.datasource_test.PORRIDGE_RECIPE_RESPONSE_V0
|
||||
import gq.kirmanak.mealient.datasource_test.PORRIDGE_RECIPE_RESPONSE_V1
|
||||
import gq.kirmanak.mealient.datasource_test.PORRIDGE_RECIPE_SUMMARY_RESPONSE_V0
|
||||
import gq.kirmanak.mealient.datasource_test.PORRIDGE_RECIPE_SUMMARY_RESPONSE_V1
|
||||
import gq.kirmanak.mealient.datasource_test.PORRIDGE_UPDATE_RECIPE_REQUEST_V1
|
||||
import gq.kirmanak.mealient.datasource_test.RECIPE_SUMMARY_PORRIDGE_V0
|
||||
import gq.kirmanak.mealient.datasource_test.RECIPE_SUMMARY_PORRIDGE_V1
|
||||
import gq.kirmanak.mealient.datasource_test.SUGAR_INGREDIENT
|
||||
import gq.kirmanak.mealient.datasource_test.VERSION_INFO_V0
|
||||
import gq.kirmanak.mealient.datasource_test.VERSION_INFO_V1
|
||||
import gq.kirmanak.mealient.datasource_test.VERSION_RESPONSE_V0
|
||||
import gq.kirmanak.mealient.datasource_test.VERSION_RESPONSE_V1
|
||||
import gq.kirmanak.mealient.datasource_test.PORRIDGE_CREATE_RECIPE_REQUEST
|
||||
import gq.kirmanak.mealient.datasource_test.PORRIDGE_UPDATE_RECIPE_REQUEST
|
||||
import gq.kirmanak.mealient.datasource_test.SUGAR_RECIPE_INGREDIENT_RESPONSE
|
||||
import gq.kirmanak.mealient.datastore_test.PORRIDGE_RECIPE_DRAFT
|
||||
import gq.kirmanak.mealient.test.BaseUnitTest
|
||||
import org.junit.Before
|
||||
@@ -58,100 +39,30 @@ class ModelMappingsTest : BaseUnitTest() {
|
||||
|
||||
@Test
|
||||
fun `when full recipe info to entity expect correct entity`() {
|
||||
assertThat(subject.toRecipeEntity(CAKE_FULL_RECIPE_INFO)).isEqualTo(CAKE_RECIPE_ENTITY)
|
||||
assertThat(subject.toRecipeEntity(CAKE_RECIPE_RESPONSE)).isEqualTo(CAKE_RECIPE_ENTITY)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when ingredient info to entity expect correct entity`() {
|
||||
val actual = subject.toRecipeIngredientEntity(SUGAR_INGREDIENT, "1")
|
||||
val actual = subject.toRecipeIngredientEntity(SUGAR_RECIPE_INGREDIENT_RESPONSE, "1")
|
||||
assertThat(actual).isEqualTo(CAKE_SUGAR_RECIPE_INGREDIENT_ENTITY)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when instruction info to entity expect correct entity`() {
|
||||
val actual = subject.toRecipeInstructionEntity(MIX_INSTRUCTION, "1")
|
||||
val actual = subject.toRecipeInstructionEntity(MIX_RECIPE_INSTRUCTION_RESPONSE, "1")
|
||||
assertThat(actual).isEqualTo(MIX_CAKE_RECIPE_INSTRUCTION_ENTITY)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when summary v0 to info expect correct info`() {
|
||||
val actual = subject.toRecipeSummaryInfo(PORRIDGE_RECIPE_SUMMARY_RESPONSE_V0)
|
||||
assertThat(actual).isEqualTo(RECIPE_SUMMARY_PORRIDGE_V0)
|
||||
fun `when add recipe info to create request expect correct request`() {
|
||||
val actual = subject.toCreateRequest(PORRIDGE_ADD_RECIPE_INFO)
|
||||
assertThat(actual).isEqualTo(PORRIDGE_CREATE_RECIPE_REQUEST)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when summary v1 to info expect correct info`() {
|
||||
val actual = subject.toRecipeSummaryInfo(PORRIDGE_RECIPE_SUMMARY_RESPONSE_V1)
|
||||
assertThat(actual).isEqualTo(RECIPE_SUMMARY_PORRIDGE_V1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when summary info to entity expect correct entity`() {
|
||||
val actual = subject.toRecipeSummaryEntity(RECIPE_SUMMARY_PORRIDGE_V0, isFavorite = false)
|
||||
assertThat(actual).isEqualTo(PORRIDGE_RECIPE_SUMMARY_ENTITY)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when version response v0 to info expect correct info`() {
|
||||
assertThat(subject.toVersionInfo(VERSION_RESPONSE_V0)).isEqualTo(VERSION_INFO_V0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when version response v1 to info expect correct info`() {
|
||||
assertThat(subject.toVersionInfo(VERSION_RESPONSE_V1)).isEqualTo(VERSION_INFO_V1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when recipe ingredient response v0 to info expect correct info`() {
|
||||
val actual = subject.toRecipeIngredientInfo(MILK_RECIPE_INGREDIENT_RESPONSE_V0)
|
||||
assertThat(actual).isEqualTo(MILK_RECIPE_INGREDIENT_INFO)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when recipe ingredient response v1 to info expect correct info`() {
|
||||
val actual = subject.toRecipeIngredientInfo(MILK_RECIPE_INGREDIENT_RESPONSE_V1)
|
||||
assertThat(actual).isEqualTo(MILK_RECIPE_INGREDIENT_INFO)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when recipe instruction response v0 to info expect correct info`() {
|
||||
val actual = subject.toRecipeInstructionInfo(MIX_RECIPE_INSTRUCTION_RESPONSE_V0)
|
||||
assertThat(actual).isEqualTo(MIX_RECIPE_INSTRUCTION_INFO)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when recipe instruction response v1 to info expect correct info`() {
|
||||
val actual = subject.toRecipeInstructionInfo(MIX_RECIPE_INSTRUCTION_RESPONSE_V1)
|
||||
assertThat(actual).isEqualTo(MIX_RECIPE_INSTRUCTION_INFO)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when recipe response v0 to info expect correct info`() {
|
||||
val actual = subject.toFullRecipeInfo(PORRIDGE_RECIPE_RESPONSE_V0)
|
||||
assertThat(actual).isEqualTo(PORRIDGE_FULL_RECIPE_INFO)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when recipe response v1 to info expect correct info`() {
|
||||
val actual = subject.toFullRecipeInfo(PORRIDGE_RECIPE_RESPONSE_V1)
|
||||
assertThat(actual).isEqualTo(PORRIDGE_FULL_RECIPE_INFO)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when add recipe info to request v0 expect correct request`() {
|
||||
val actual = subject.toV0Request(PORRIDGE_ADD_RECIPE_INFO)
|
||||
assertThat(actual).isEqualTo(PORRIDGE_ADD_RECIPE_REQUEST_V0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when add recipe info to create request v1 expect correct request`() {
|
||||
val actual = subject.toV1CreateRequest(PORRIDGE_ADD_RECIPE_INFO)
|
||||
assertThat(actual).isEqualTo(PORRIDGE_CREATE_RECIPE_REQUEST_V1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when add recipe info to update request v1 expect correct request`() {
|
||||
val actual = subject.toV1UpdateRequest(PORRIDGE_ADD_RECIPE_INFO)
|
||||
assertThat(actual).isEqualTo(PORRIDGE_UPDATE_RECIPE_REQUEST_V1)
|
||||
fun `when add recipe info to update request expect correct request`() {
|
||||
val actual = subject.toUpdateRequest(PORRIDGE_ADD_RECIPE_INFO)
|
||||
assertThat(actual).isEqualTo(PORRIDGE_UPDATE_RECIPE_REQUEST)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user