-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert BadgeLayout and TicketLayout
- Loading branch information
Showing
7 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
libpretixsync/src/main/java/eu/pretix/libpretixsync/database/BadgeLayoutExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!!, | ||
) |
16 changes: 16 additions & 0 deletions
16
libpretixsync/src/main/java/eu/pretix/libpretixsync/database/TicketLayoutExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!!, | ||
) |
26 changes: 26 additions & 0 deletions
26
libpretixsync/src/main/java/eu/pretix/libpretixsync/models/BadgeLayout.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
} | ||
} | ||
|
25 changes: 25 additions & 0 deletions
25
libpretixsync/src/main/java/eu/pretix/libpretixsync/models/TicketLayout.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
libpretixsync/src/main/sqldelight/common/eu/pretix/libpretixsync/sqldelight/BadgeLayout.sq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ?; |
4 changes: 4 additions & 0 deletions
4
...etixsync/src/main/sqldelight/common/eu/pretix/libpretixsync/sqldelight/BadgeLayoutItem.sq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
selectByItemId: | ||
SELECT * | ||
FROM BadgeLayoutItem | ||
WHERE item = ?; |
11 changes: 11 additions & 0 deletions
11
libpretixsync/src/main/sqldelight/common/eu/pretix/libpretixsync/sqldelight/TicketLayout.sq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ?; |