added recipe data access object and interface

This commit is contained in:
Wyatt J. Miller 2022-05-04 14:30:29 -04:00
parent 9b22a6df31
commit e71aeaa708
2 changed files with 48 additions and 0 deletions

View File

@ -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<Recipe> {
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")
}
}

View File

@ -0,0 +1,11 @@
package com.wyattjmiller.repositories
import com.wyattjmiller.entities.Recipe
interface RecipeRepository {
fun getAllRecipies() : List<Recipe>
fun getRecipe(id: Int) : Recipe?
fun createRecipe(recipe: Recipe)
fun updateRecipe(id: Int, recipe: Recipe): Boolean
fun deleteRecipe(id: Int)
}