Skip to content

Commit

Permalink
Move AbstractQueuedCheckIn.formatDatetime to new model
Browse files Browse the repository at this point in the history
  • Loading branch information
antweb committed Dec 13, 2024
1 parent 4842644 commit 206d05c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package eu.pretix.libpretixsync.api
import eu.pretix.libpretixsync.DummySentryImplementation
import eu.pretix.libpretixsync.SentryInterface
import eu.pretix.libpretixsync.config.ConfigStore
import eu.pretix.libpretixsync.db.AbstractQueuedCheckIn
import eu.pretix.libpretixsync.db.Answer
import eu.pretix.libpretixsync.models.Question
import eu.pretix.libpretixsync.models.QueuedCheckIn
import eu.pretix.libpretixsync.utils.NetUtils
import eu.pretix.libpretixsync.utils.URLFragmentEncoder
import okhttp3.MediaType
Expand Down Expand Up @@ -46,7 +46,7 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
fun redeem(eventSlug: String, secret: String, datetime: Date?, force: Boolean, nonce: String?, answers: List<Answer>?, listId: Long, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, source_type: String?, callTimeout: Long? = null, questions_supported: Boolean = true): ApiResponse {
var dt: String? = null
if (datetime != null) {
dt = AbstractQueuedCheckIn.formatDatetime(datetime)
dt = QueuedCheckIn.formatDatetime(datetime)
}
return redeem(eventSlug, secret, dt, force, nonce, answers, listId, ignore_unpaid, pdf_data, type, source_type, callTimeout, questions_supported)
}
Expand Down Expand Up @@ -93,7 +93,7 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
fun redeem(lists: List<Long>, secret: String, datetime: Date?, force: Boolean, nonce: String?, answers: List<Answer>?, ignore_unpaid: Boolean, pdf_data: Boolean, type: String?, source_type: String?, callTimeout: Long? = null, questions_supported: Boolean = true): ApiResponse {
var dt: String? = null
if (datetime != null) {
dt = AbstractQueuedCheckIn.formatDatetime(datetime)
dt = QueuedCheckIn.formatDatetime(datetime)
}
return redeem(lists, secret, dt, force, nonce, answers, ignore_unpaid, pdf_data, type, source_type, callTimeout, questions_supported)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import eu.pretix.libpretixsync.config.ConfigStore
import eu.pretix.libpretixsync.crypto.isValidSignature
import eu.pretix.libpretixsync.crypto.readPubkeyFromPem
import eu.pretix.libpretixsync.crypto.sig1.TicketProtos
import eu.pretix.libpretixsync.db.AbstractQueuedCheckIn
import eu.pretix.libpretixsync.db.Answer
import eu.pretix.libpretixsync.db.NonceGenerator
import eu.pretix.libpretixsync.db.QuestionLike
Expand Down Expand Up @@ -66,7 +65,7 @@ class AsyncCheckProvider(private val config: ConfigStore, private val db: SyncDa

val dt = now()
val jdoc = JSONObject()
jdoc.put("datetime", AbstractQueuedCheckIn.formatDatetime(dt.toDate()))
jdoc.put("datetime", QueuedCheckIn.formatDatetime(dt.toDate()))
if (raw_barcode.contains(Regex("[\\p{C}]"))) {
jdoc.put("raw_barcode", "binary:" + Base64.encodeBase64(raw_barcode.toByteArray(Charset.defaultCharset())).toString(Charset.defaultCharset()))
} else {
Expand Down Expand Up @@ -521,7 +520,7 @@ class AsyncCheckProvider(private val config: ConfigStore, private val db: SyncDa
answers = givenAnswers.toString(),
checkinListId = listId,
datetime = dt.toDate(),
datetime_string = AbstractQueuedCheckIn.formatDatetime(dt.toDate()),
datetime_string = QueuedCheckIn.formatDatetime(dt.toDate()),
event_slug = eventSlug,
nonce = nonce ?: NonceGenerator.nextNonce(),
secret = ticketid,
Expand Down Expand Up @@ -929,7 +928,7 @@ class AsyncCheckProvider(private val config: ConfigStore, private val db: SyncDa
answers = givenAnswers.toString(),
checkinListId = listId,
datetime = dt.toDate(),
datetime_string = AbstractQueuedCheckIn.formatDatetime(dt.toDate()),
datetime_string = QueuedCheckIn.formatDatetime(dt.toDate()),
event_slug = eventSlug,
nonce = nonce ?: NonceGenerator.nextNonce(),
secret = position.secret,
Expand All @@ -943,7 +942,7 @@ class AsyncCheckProvider(private val config: ConfigStore, private val db: SyncDa
position = position.id,
type = type.toString().lowercase(Locale.getDefault()),
datetime = dt.toDate(),
json_data = "{\"local\": true, \"type\": \"${type.toString().lowercase(Locale.getDefault())}\", \"datetime\": \"${AbstractQueuedCheckIn.formatDatetime(dt.toDate())}\"}",
json_data = "{\"local\": true, \"type\": \"${type.toString().lowercase(Locale.getDefault())}\", \"datetime\": \"${QueuedCheckIn.formatDatetime(dt.toDate())}\"}",
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package eu.pretix.libpretixsync.models

import java.text.DateFormat
import java.text.SimpleDateFormat
import java.time.OffsetDateTime
import java.util.Date
import java.util.Locale
import java.util.TimeZone

data class QueuedCheckIn(
val id: Long,
Expand All @@ -12,4 +17,18 @@ data class QueuedCheckIn(
val secret: String?,
val sourceType: String?,
val type: String?,
)
) {
companion object {
// Migrated from AbstractQueuedCheckIn
// TODO: Find a better place for this?
fun formatDatetime(date: Date): String {
val tz = TimeZone.getTimeZone("UTC")
val df: DateFormat = SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss'Z'",
Locale.ENGLISH
) // Quoted "Z" to indicate UTC, no timezone offset
df.timeZone = tz
return df.format(date)
}
}
}

0 comments on commit 206d05c

Please sign in to comment.