diff --git a/app/src/main/java/com/cookit/MainViewModel.kt b/app/src/main/java/com/cookit/MainViewModel.kt index c352fbc..d010c4d 100644 --- a/app/src/main/java/com/cookit/MainViewModel.kt +++ b/app/src/main/java/com/cookit/MainViewModel.kt @@ -68,6 +68,9 @@ class MainViewModel(var recipeService: IRecipeService = RecipeService()) : ViewM } } + /** + * Fetches recipes from IRecipeDAO and adds it to an arraylist + */ internal fun fetchRecipes() { viewModelScope.launch { val innerRecipeList = recipeService.fetchRecipes() diff --git a/app/src/main/java/com/cookit/dto/Recipe.kt b/app/src/main/java/com/cookit/dto/Recipe.kt index 75f83fc..7a76355 100644 --- a/app/src/main/java/com/cookit/dto/Recipe.kt +++ b/app/src/main/java/com/cookit/dto/Recipe.kt @@ -3,6 +3,17 @@ package com.cookit.dto import com.google.gson.annotations.Expose import com.google.gson.annotations.SerializedName +/** + * A class to represent recipes + * + * This class serializes the JSON from IRecipeDAO and parses it into a kotlin object + * @property recipeID + * @property name Name of the recipe + * @property category Category of the recipe + * @property cuisine Cuisine of the recipe + * @property instructions Instructions of how to create the recipe + * @property imageURL URL of the image associated with the recipe + */ data class Recipe( @SerializedName("idMeal")var recipeID : String = "", @SerializedName("strMeal")var name : String = "", diff --git a/app/src/main/java/com/cookit/service/IngredientMapService.kt b/app/src/main/java/com/cookit/service/IngredientMapService.kt index 8cba503..66caced 100644 --- a/app/src/main/java/com/cookit/service/IngredientMapService.kt +++ b/app/src/main/java/com/cookit/service/IngredientMapService.kt @@ -1,26 +1,14 @@ package com.cookit.service -/** - * Ingredient mapping service interface that has 2 functions - * [stringToMap] converts a string into a map - * [mapToString] converts a map to a string - */ interface IIngredientMapService { fun stringToMap(input: String): MutableMap fun mapToString(input: MutableMap): String } -/** - * This implementation of the [IIngredientMapService] converts strings and maps based on the - * format expected from a text field in our UI. - * The format looks like this: - * ingredient=amount,\ningredient2=amount,\ningredient3=amount,\n ... ingredient20=amount - * \n is converted into a new line in the text field - */ -class TextFieldIngredientMapService : IIngredientMapService { +class IngredientMapService : IIngredientMapService { override fun stringToMap(input: String): MutableMap { val outputMap = input.split(",\n").associate { - val (left, right) = it.trim().split("=") + val (left, right) = it.split("=") left to right }.toMutableMap() return outputMap