Signed-off-by: Chaoscaot <max@maxsp.de>
This commit is contained in:
2025-10-28 21:31:57 +01:00
parent b51ea484e4
commit a8eaf3daa7
3 changed files with 21 additions and 23 deletions
@@ -59,7 +59,7 @@ class SchematicNode(id: EntityID<Int>) : IntEntity(id) {
@JvmStatic
fun getAll(user: SteamwarUser) = fromSql(
"WITH RECURSIVE Nodes AS (SELECT NodeId, ParentId as ParentNode FROM NodeMember WHERE UserId = ?} UNION SELECT NodeId, ParentNode FROM SchematicNode WHERE NodeOwner = ?), RSN AS ( SELECT NodeId, ParentNode FROM Nodes UNION SELECT SN.NodeId, SN.ParentNode FROM SchematicNode SN, RSN WHERE SN.ParentNode = RSN.NodeId ) SELECT SN.* FROM RSN INNER JOIN SchematicNode SN ON RSN.NodeId = SN.NodeId",
"WITH RECURSIVE Nodes AS (SELECT NodeId, ParentId as ParentNode FROM NodeMember WHERE UserId = ? UNION SELECT NodeId, ParentNode FROM SchematicNode WHERE NodeOwner = ?), RSN AS ( SELECT NodeId, ParentNode FROM Nodes UNION SELECT SN.NodeId, SN.ParentNode FROM SchematicNode SN, RSN WHERE SN.ParentNode = RSN.NodeId ) SELECT SN.* FROM RSN INNER JOIN SchematicNode SN ON RSN.NodeId = SN.NodeId",
listOf(
IntegerColumnType() to user.getId(),
IntegerColumnType() to user.getId()
@@ -72,11 +72,10 @@ class SchematicNode(id: EntityID<Int>) : IntEntity(id) {
@JvmStatic
fun list(user: SteamwarUser, schematicId: Int?) = fromSql(
"SELECT SchematicNode.NodeId, NodeOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId <=> ? AND NM.UserId = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode WHERE (? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?) ORDER BY NodeName",
"SELECT SchematicNode.NodeId, NodeOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId <=> ? AND NM.UserId = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode WHERE (? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?) ORDER BY NodeName",
listOf(
IntegerColumnType() to schematicId,
IntegerColumnType() to user.getId(),
IntegerColumnType() to user.getId(),
IntegerColumnType() to schematicId,
IntegerColumnType() to user.getId(),
IntegerColumnType() to schematicId,
@@ -86,12 +85,11 @@ class SchematicNode(id: EntityID<Int>) : IntEntity(id) {
@JvmStatic
fun byParentName(user: SteamwarUser, schematicId: Int?, name: String) = fromSql(
"SELECT SchematicNode.NodeId, NodeOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId <=> ? AND NM.UserId = ? AND SchematicNode.NodeName = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, ? AS EffectiveOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode WHERE ((? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?)) AND NodeName = ?",
"SELECT SchematicNode.NodeId, NodeOwner, NodeName, NM.ParentId AS ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode INNER JOIN NodeMember NM on SchematicNode.NodeId = NM.NodeId WHERE NM.ParentId <=> ? AND NM.UserId = ? AND SchematicNode.NodeName = ? UNION ALL SELECT SchematicNode.NodeId, NodeOwner, NodeName, ParentNode, LastUpdate, NodeItem, NodeType, NodeRank, Config FROM SchematicNode WHERE ((? IS NULL AND ParentNode IS NULL AND NodeOwner = ?) OR (? IS NOT NULL AND ParentNode = ?)) AND NodeName = ?",
listOf(
IntegerColumnType() to schematicId,
IntegerColumnType() to user.getId(),
VarCharColumnType() to name,
IntegerColumnType() to user.getId(),
IntegerColumnType() to schematicId,
IntegerColumnType() to user.getId(),
IntegerColumnType() to schematicId,
@@ -342,8 +340,8 @@ class SchematicNode(id: EntityID<Int>) : IntEntity(id) {
fun isDir() = nodeType == null
private fun <T> checkDir(block: () -> T): T {
if (!isDir()) {
throw IllegalStateException("Node is not a directory")
if (isDir()) {
throw IllegalStateException("Node is a directory")
}
return block()
@@ -387,12 +385,12 @@ class SchematicNode(id: EntityID<Int>) : IntEntity(id) {
return breadcrumbs
}
fun generateBreadcrumbs(split: String, user: SteamwarUser): String {
fun generateBreadcrumbs(split: String, user: SteamwarUser): String = useDb {
val builder: StringBuilder = StringBuilder(name)
if (isDir()) {
builder.append(split)
}
var currentNode: SchematicNode? = this
var currentNode: SchematicNode? = this@SchematicNode
while (currentNode != null) {
currentNode = currentNode
.let {
@@ -404,12 +402,12 @@ class SchematicNode(id: EntityID<Int>) : IntEntity(id) {
builder.insert(0, split).insert(0, it.name)
}
}
return builder.toString()
return@useDb builder.toString()
}
fun generateBreadcrumbsMap(user: SteamwarUser): List<Pair<String, Int>> {
fun generateBreadcrumbsMap(user: SteamwarUser): List<Pair<String, Int>> = useDb {
val map = mutableListOf<Pair<String, Int>>()
var currentNode: SchematicNode? = this
var currentNode: SchematicNode? = this@SchematicNode
while (currentNode != null) {
currentNode = currentNode
.also {
@@ -421,7 +419,7 @@ class SchematicNode(id: EntityID<Int>) : IntEntity(id) {
}
?.let { findById(it) }
}
return map
return@useDb map
}
fun accessibleByUser(user: SteamwarUser) = schematicAccessibleForUser(user, nodeId)
@@ -42,7 +42,7 @@ object SteamwarUserTable : IntIdTable("UserData", "id") {
val team = integer("Team")
val leader = bool("Leader")
val locale = varchar("Locale", 16).nullable()
val manualeLocale = bool("ManualeLocale")
val manualLocale = bool("ManualLocale")
val bedrock = bool("Bedrock")
val password = text("Password").nullable()
val discordId = long("DiscordId").nullable()
@@ -171,7 +171,7 @@ class SteamwarUser(id: EntityID<Int>): IntEntity(id) {
var locale: Locale by SteamwarUserTable.locale
.transform({ it.toLanguageTag() }, { it?.let { Locale.forLanguageTag(it) } ?: Locale.getDefault()})
var manualLocale by SteamwarUserTable.manualeLocale
var manualLocale by SteamwarUserTable.manualLocale
var bedrock by SteamwarUserTable.bedrock
private var passwordInternal by SteamwarUserTable.password
var password: String?
@@ -31,22 +31,22 @@ import org.jetbrains.exposed.v1.jdbc.upsert
import java.util.UUID
object UserConfigTable: CompositeIdTable("UserConfig") {
val userId = reference("userId", SteamwarUserTable)
val key = varchar("Key", 32)
val value = text("Value")
val userId = reference("User", SteamwarUserTable)
val config = varchar("Config", 32)
val value = text("Value", eagerLoading = true)
override val primaryKey = PrimaryKey(userId, key)
override val primaryKey = PrimaryKey(userId, config)
}
class UserConfig(id: EntityID<CompositeID>): CompositeEntity(id) {
val userId by UserConfigTable.userId
val key by UserConfigTable.key
val config by UserConfigTable.config
var value by UserConfigTable.value
companion object: CompositeEntityClass<UserConfig>(UserConfigTable) {
@JvmStatic
fun getConfig(userId: Int, config: String) = useDb {
find { (UserConfigTable.userId eq userId) and (UserConfigTable.key eq config) }.firstOrNull()?.value
find { (UserConfigTable.userId eq userId) and (UserConfigTable.config eq config) }.firstOrNull()?.value
}
@JvmStatic
@@ -59,7 +59,7 @@ class UserConfig(id: EntityID<CompositeID>): CompositeEntity(id) {
} else {
UserConfigTable.upsert {
it[UserConfigTable.userId] = id
it[UserConfigTable.key] = config
it[UserConfigTable.config] = config
it[UserConfigTable.value] = value
}
}
@@ -70,7 +70,7 @@ class UserConfig(id: EntityID<CompositeID>): CompositeEntity(id) {
@JvmStatic
fun removePlayerConfig(id: Int, config: String) = useDb {
find { (UserConfigTable.userId eq id) and (UserConfigTable.key eq config) }.firstOrNull()?.delete()
find { (UserConfigTable.userId eq id) and (UserConfigTable.config eq config) }.firstOrNull()?.delete()
}
@JvmStatic