From 3e2bfd12c661a20843d0a082f2dc10fca30245fe Mon Sep 17 00:00:00 2001 From: Maximilian Richt Date: Mon, 15 Jul 2024 14:46:48 +0200 Subject: [PATCH] Convert BadgeLayout and TicketLayout --- .../database/BadgeLayoutExtensions.kt | 16 ++++++++++++ .../database/TicketLayoutExtensions.kt | 16 ++++++++++++ .../libpretixsync/models/BadgeLayout.kt | 26 +++++++++++++++++++ .../libpretixsync/models/TicketLayout.kt | 25 ++++++++++++++++++ .../libpretixsync/sqldelight/BadgeLayout.sq | 11 ++++++++ .../sqldelight/BadgeLayoutItem.sq | 4 +++ .../libpretixsync/sqldelight/TicketLayout.sq | 11 ++++++++ 7 files changed, 109 insertions(+) create mode 100644 libpretixsync/src/main/java/eu/pretix/libpretixsync/database/BadgeLayoutExtensions.kt create mode 100644 libpretixsync/src/main/java/eu/pretix/libpretixsync/database/TicketLayoutExtensions.kt create mode 100644 libpretixsync/src/main/java/eu/pretix/libpretixsync/models/BadgeLayout.kt create mode 100644 libpretixsync/src/main/java/eu/pretix/libpretixsync/models/TicketLayout.kt create mode 100644 libpretixsync/src/main/sqldelight/common/eu/pretix/libpretixsync/sqldelight/BadgeLayout.sq create mode 100644 libpretixsync/src/main/sqldelight/common/eu/pretix/libpretixsync/sqldelight/BadgeLayoutItem.sq create mode 100644 libpretixsync/src/main/sqldelight/common/eu/pretix/libpretixsync/sqldelight/TicketLayout.sq diff --git a/libpretixsync/src/main/java/eu/pretix/libpretixsync/database/BadgeLayoutExtensions.kt b/libpretixsync/src/main/java/eu/pretix/libpretixsync/database/BadgeLayoutExtensions.kt new file mode 100644 index 00000000..cad84c08 --- /dev/null +++ b/libpretixsync/src/main/java/eu/pretix/libpretixsync/database/BadgeLayoutExtensions.kt @@ -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!!, + ) diff --git a/libpretixsync/src/main/java/eu/pretix/libpretixsync/database/TicketLayoutExtensions.kt b/libpretixsync/src/main/java/eu/pretix/libpretixsync/database/TicketLayoutExtensions.kt new file mode 100644 index 00000000..5dfe46d6 --- /dev/null +++ b/libpretixsync/src/main/java/eu/pretix/libpretixsync/database/TicketLayoutExtensions.kt @@ -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!!, + ) diff --git a/libpretixsync/src/main/java/eu/pretix/libpretixsync/models/BadgeLayout.kt b/libpretixsync/src/main/java/eu/pretix/libpretixsync/models/BadgeLayout.kt new file mode 100644 index 00000000..c02c2807 --- /dev/null +++ b/libpretixsync/src/main/java/eu/pretix/libpretixsync/models/BadgeLayout.kt @@ -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, + ) + } + } +} + diff --git a/libpretixsync/src/main/java/eu/pretix/libpretixsync/models/TicketLayout.kt b/libpretixsync/src/main/java/eu/pretix/libpretixsync/models/TicketLayout.kt new file mode 100644 index 00000000..9c3d0c56 --- /dev/null +++ b/libpretixsync/src/main/java/eu/pretix/libpretixsync/models/TicketLayout.kt @@ -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, + ) + } + } +} diff --git a/libpretixsync/src/main/sqldelight/common/eu/pretix/libpretixsync/sqldelight/BadgeLayout.sq b/libpretixsync/src/main/sqldelight/common/eu/pretix/libpretixsync/sqldelight/BadgeLayout.sq new file mode 100644 index 00000000..9a65d593 --- /dev/null +++ b/libpretixsync/src/main/sqldelight/common/eu/pretix/libpretixsync/sqldelight/BadgeLayout.sq @@ -0,0 +1,11 @@ +selectById: +SELECT * +FROM BadgeLayout +WHERE id = ?; + +selectDefaultForEventSlug: +SELECT * +FROM BadgeLayout +WHERE + is_default = TRUE + AND event_slug = ?; diff --git a/libpretixsync/src/main/sqldelight/common/eu/pretix/libpretixsync/sqldelight/BadgeLayoutItem.sq b/libpretixsync/src/main/sqldelight/common/eu/pretix/libpretixsync/sqldelight/BadgeLayoutItem.sq new file mode 100644 index 00000000..7fb15ee4 --- /dev/null +++ b/libpretixsync/src/main/sqldelight/common/eu/pretix/libpretixsync/sqldelight/BadgeLayoutItem.sq @@ -0,0 +1,4 @@ +selectByItemId: +SELECT * +FROM BadgeLayoutItem +WHERE item = ?; \ No newline at end of file diff --git a/libpretixsync/src/main/sqldelight/common/eu/pretix/libpretixsync/sqldelight/TicketLayout.sq b/libpretixsync/src/main/sqldelight/common/eu/pretix/libpretixsync/sqldelight/TicketLayout.sq new file mode 100644 index 00000000..7dbe403b --- /dev/null +++ b/libpretixsync/src/main/sqldelight/common/eu/pretix/libpretixsync/sqldelight/TicketLayout.sq @@ -0,0 +1,11 @@ +selectByServerId: +SELECT * +FROM TicketLayout +WHERE server_id = ?; + +selectDefaultForEventSlug: +SELECT * +FROM TicketLayout +WHERE + is_default = TRUE + AND event_slug = ?;