diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index b45c76d..8012d92 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -5,24 +5,16 @@ import java.sql.Connection import java.io.File import java.sql.PreparedStatement +import dev.thebread.Model.PreparedStatementCase + class KlistApp { - enum class PreparedStatementCase { - GET_USERS, GET_LIST_FOR_USER, GET_LISTS, GET_STAGES_FOR_LIST, - ADD_LIST, ADD_USER, ADD_LIST_FOR_USER, ADD_STAGE_FOR_LIST, ADD_TASK_TO_LIST, - MOVE_TASK_TO_STAGE, - REMOVE_TASK, REMOVE_USER, REMOVE_LIST_FOR_USER, - REG_LOCAL_FOR_USER, REG_DISCORD_FOR_USER, REG_GOOGLE_FOR_USER, - CLEANUP, - } - private var conn: Connection - private var stmts: Map constructor(path: String?) { conn = DriverManager.getConnection(if (!path.isNullOrBlank()) path else "jdbc:sqlite::memory:") dbSetup(conn) - stmts = dbPrepare(conn) + Model.Common.stmts = dbPrepare(conn) } private fun dbSetup(conn: Connection) { @@ -46,15 +38,15 @@ class KlistApp { private fun assureListForUser() {} private fun assureStageForList() {} - fun createTask() {} - fun moveTask() {} - fun deleteTask() {} + public fun createTask() {} + public fun moveTask() {} + public fun deleteTask() {} - fun createStage() {} - fun moveStage() {} - fun deleteStage() {} + public fun createStage() {} + public fun moveStage() {} + public fun deleteStage() {} - fun deleteUser() {} + public fun deleteUser() {} } fun main() { diff --git a/src/main/kotlin/Models.kt b/src/main/kotlin/Models.kt new file mode 100644 index 0000000..a4961e4 --- /dev/null +++ b/src/main/kotlin/Models.kt @@ -0,0 +1,67 @@ +package dev.thebread + +import java.sql.PreparedStatement +import java.time.LocalDate + + +abstract class Model { + enum class PreparedStatementCase { + GET_USERS, GET_LIST_FOR_USER, GET_LISTS, GET_STAGES_FOR_LIST, + ADD_LIST, ADD_USER, ADD_LIST_FOR_USER, ADD_STAGE_FOR_LIST, ADD_TASK_TO_LIST, + MOVE_TASK_TO_STAGE, + REMOVE_TASK, REMOVE_USER, REMOVE_LIST_FOR_USER, + REG_LOCAL_FOR_USER, REG_DISCORD_FOR_USER, REG_GOOGLE_FOR_USER, + CLEANUP, + } + + companion object Common { + public var stmts: Map? = null + } + + abstract var id: Int? + + fun id(): Int? { + if(id == null) { + this.id = create().id + } + return id + } + fun setStatements(stmts: Map) { + Common.stmts = stmts + } + + abstract fun get(id: Int): Model? + abstract fun getAll(): Set + abstract fun create(): Model + +} + +class Models { + class User { + val name: String? = null + val discord: Int? = null + val google: Int? = null + } + + class List { + val id: Int? = null + val name: String? = null + val description: String? = null + } + + class Task { + class Stage { + val id: Int? = null + val name: String? = null + val description: String? = null + val list: List? = null + } + + val id: Int? = null + val name: String? = null + val description: String? = null + val stage: Stage? = null + val due: LocalDate? = null + val dueStage: Stage? = null + } +} \ No newline at end of file diff --git a/src/main/resources/prepare/move_task_to_stage.sql b/src/main/resources/prepare/move_task_to_stage.sql new file mode 100644 index 0000000..b18e4a4 --- /dev/null +++ b/src/main/resources/prepare/move_task_to_stage.sql @@ -0,0 +1,3 @@ +update tasks +set stage = ?1 +where id = ?2 \ No newline at end of file