outline models

This commit is contained in:
theBreadCompany 2025-06-01 23:46:24 +02:00
parent f41d2c2b2c
commit 2a1d6ca031
3 changed files with 80 additions and 18 deletions

View file

@ -5,24 +5,16 @@ import java.sql.Connection
import java.io.File import java.io.File
import java.sql.PreparedStatement import java.sql.PreparedStatement
import dev.thebread.Model.PreparedStatementCase
class KlistApp { 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 conn: Connection
private var stmts: Map<PreparedStatementCase, PreparedStatement>
constructor(path: String?) { constructor(path: String?) {
conn = DriverManager.getConnection(if (!path.isNullOrBlank()) path else "jdbc:sqlite::memory:") conn = DriverManager.getConnection(if (!path.isNullOrBlank()) path else "jdbc:sqlite::memory:")
dbSetup(conn) dbSetup(conn)
stmts = dbPrepare(conn) Model.Common.stmts = dbPrepare(conn)
} }
private fun dbSetup(conn: Connection) { private fun dbSetup(conn: Connection) {
@ -46,15 +38,15 @@ class KlistApp {
private fun assureListForUser() {} private fun assureListForUser() {}
private fun assureStageForList() {} private fun assureStageForList() {}
fun createTask() {} public fun createTask() {}
fun moveTask() {} public fun moveTask() {}
fun deleteTask() {} public fun deleteTask() {}
fun createStage() {} public fun createStage() {}
fun moveStage() {} public fun moveStage() {}
fun deleteStage() {} public fun deleteStage() {}
fun deleteUser() {} public fun deleteUser() {}
} }
fun main() { fun main() {

67
src/main/kotlin/Models.kt Normal file
View file

@ -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<PreparedStatementCase, PreparedStatement>? = null
}
abstract var id: Int?
fun id(): Int? {
if(id == null) {
this.id = create().id
}
return id
}
fun setStatements(stmts: Map<PreparedStatementCase, PreparedStatement>) {
Common.stmts = stmts
}
abstract fun get(id: Int): Model?
abstract fun getAll(): Set<Model>
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
}
}

View file

@ -0,0 +1,3 @@
update tasks
set stage = ?1
where id = ?2