Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/src/main/java/com/cookit/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class MainViewModel(var recipeService: IRecipeService = RecipeService()) : ViewM
}
}

/**
* Fetches recipes from IRecipeDAO and adds it to an arraylist
*/
Comment on lines +71 to +73
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments to provide context for the function

internal fun fetchRecipes() {
viewModelScope.launch {
val innerRecipeList = recipeService.fetchRecipes()
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/cookit/dto/Recipe.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Comment on lines +6 to +16
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added documentation to the data class.

data class Recipe(
@SerializedName("idMeal")var recipeID : String = "",
@SerializedName("strMeal")var name : String = "",
Expand Down
16 changes: 2 additions & 14 deletions app/src/main/java/com/cookit/service/IngredientMapService.kt
Original file line number Diff line number Diff line change
@@ -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
*/
Comment on lines -3 to -7
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ignore these deletions, seems like the merge caused accidental deletions

interface IIngredientMapService {
fun stringToMap(input: String): MutableMap<String, String>
fun mapToString(input: MutableMap<String, String>): 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<String, String> {
val outputMap = input.split(",\n").associate {
val (left, right) = it.trim().split("=")
val (left, right) = it.split("=")
left to right
}.toMutableMap()
return outputMap
Expand Down