diff --git a/src/main/kotlin/com/wyattjmiller/repositories/RecipeDao.kt b/src/main/kotlin/com/wyattjmiller/repositories/RecipeDao.kt new file mode 100644 index 0000000..db6afab --- /dev/null +++ b/src/main/kotlin/com/wyattjmiller/repositories/RecipeDao.kt @@ -0,0 +1,37 @@ +package com.wyattjmiller.repositories + +import com.wyattjmiller.data.DatabaseManager +import com.wyattjmiller.data.DbRecipeTable +import com.wyattjmiller.entities.Recipe +import org.ktorm.dsl.eq +import org.ktorm.entity.* + +class RecipeDao : RecipeRepository { + private val db = DatabaseManager() + + override fun getAllRecipies() : List { + return db.database + .sequenceOf(DbRecipeTable) + .toList() + .map { Recipe(it.id, it.name, it.desc, it.ingredients) } + } + + override fun getRecipe(id: Int) : Recipe { + return db.database + .sequenceOf(DbRecipeTable) + .firstOrNull { it.id eq id } + .let { Recipe(it!!.id, it.name, it.desc, it.ingredients) } + } + + override fun createRecipe(recipe: Recipe) { + TODO("Not yet implemented") + } + + override fun updateRecipe(id: Int, recipe: Recipe): Boolean { + TODO("Not yet implemented") + } + + override fun deleteRecipe(id: Int) { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/wyattjmiller/repositories/RecipeRepository.kt b/src/main/kotlin/com/wyattjmiller/repositories/RecipeRepository.kt new file mode 100644 index 0000000..2c55b92 --- /dev/null +++ b/src/main/kotlin/com/wyattjmiller/repositories/RecipeRepository.kt @@ -0,0 +1,11 @@ +package com.wyattjmiller.repositories + +import com.wyattjmiller.entities.Recipe + +interface RecipeRepository { + fun getAllRecipies() : List + fun getRecipe(id: Int) : Recipe? + fun createRecipe(recipe: Recipe) + fun updateRecipe(id: Int, recipe: Recipe): Boolean + fun deleteRecipe(id: Int) +} \ No newline at end of file