Skip to content

Commit

Permalink
Convert BadgeLayout and TicketLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
robbi5 authored and antweb committed Jul 19, 2024
1 parent 586419b commit 3e2bfd1
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package eu.pretix.libpretixsync.database

import eu.pretix.libpretixsync.sqldelight.BadgeLayout
import org.json.JSONArray
import org.json.JSONObject
import eu.pretix.libpretixsync.models.BadgeLayout as BadgeLayoutModel

fun BadgeLayout.toModel() =
BadgeLayoutModel(
id = this.id,
backgroundFilename = this.background_filename,
eventSlug = this.event_slug!!,
isDefault = this.is_default,
layout = JSONObject(this.json_data!!).optJSONArray("layout") ?: JSONArray(),
serverId = this.server_id!!,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package eu.pretix.libpretixsync.database

import eu.pretix.libpretixsync.sqldelight.TicketLayout
import org.json.JSONArray
import org.json.JSONObject
import eu.pretix.libpretixsync.models.TicketLayout as TicketLayoutModel

fun TicketLayout.toModel() =
TicketLayoutModel(
id = this.id,
backgroundFilename = this.background_filename,
eventSlug = this.event_slug!!,
isDefault = this.is_default,
layout = JSONObject(this.json_data!!).optJSONArray("layout") ?: JSONArray(),
serverId = this.server_id!!,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package eu.pretix.libpretixsync.models

import org.json.JSONArray

data class BadgeLayout(
val id: Long,
val backgroundFilename: String?,
val eventSlug: String,
val isDefault: Boolean,
val layout: JSONArray,
val serverId: Long,
) {
companion object {
fun defaultWithLayout(layout: String): BadgeLayout {
return BadgeLayout(
id = 0L,
backgroundFilename = null,
eventSlug = "",
isDefault = true,
layout = JSONArray(layout),
serverId = 0L,
)
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package eu.pretix.libpretixsync.models

import org.json.JSONArray

data class TicketLayout(
val id: Long,
val backgroundFilename: String?,
val eventSlug: String,
val isDefault: Boolean,
val layout: JSONArray,
val serverId: Long,
) {
companion object {
fun defaultWithLayout(layout: String): TicketLayout {
return TicketLayout(
id = 0L,
backgroundFilename = null,
eventSlug = "",
isDefault = true,
layout = JSONArray(layout),
serverId = 0L,
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
selectById:
SELECT *
FROM BadgeLayout
WHERE id = ?;

selectDefaultForEventSlug:
SELECT *
FROM BadgeLayout
WHERE
is_default = TRUE
AND event_slug = ?;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
selectByItemId:
SELECT *
FROM BadgeLayoutItem
WHERE item = ?;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
selectByServerId:
SELECT *
FROM TicketLayout
WHERE server_id = ?;

selectDefaultForEventSlug:
SELECT *
FROM TicketLayout
WHERE
is_default = TRUE
AND event_slug = ?;

0 comments on commit 3e2bfd1

Please sign in to comment.