From e71aeaa70888d8792c8b04cf22769587e64fca9b Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Wed, 4 May 2022 14:30:29 -0400 Subject: [PATCH] added recipe data access object and interface --- .../wyattjmiller/repositories/RecipeDao.kt | 37 +++++++++++++++++++ .../repositories/RecipeRepository.kt | 11 ++++++ 2 files changed, 48 insertions(+) create mode 100644 src/main/kotlin/com/wyattjmiller/repositories/RecipeDao.kt create mode 100644 src/main/kotlin/com/wyattjmiller/repositories/RecipeRepository.kt 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