added recipe data access object and interface
This commit is contained in:
parent
9b22a6df31
commit
e71aeaa708
37
src/main/kotlin/com/wyattjmiller/repositories/RecipeDao.kt
Normal file
37
src/main/kotlin/com/wyattjmiller/repositories/RecipeDao.kt
Normal 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")
|
||||
}
|
||||
}
|
@ -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)
|
||||
}
|
Reference in New Issue
Block a user