This commit is contained in:
stefan
2025-06-05 18:20:43 +02:00
parent ab1f5d0f7f
commit 05108d389c
14 changed files with 190 additions and 103 deletions
Binary file not shown.
@@ -56,7 +56,7 @@ class EmailService private constructor(
}
/**
* Creates email session with the configured properties.
* Creates an email session with the configured properties.
*
* @param debug Whether to enable debug mode for the mail session
* @return The configured mail session
@@ -93,7 +93,7 @@ class EmailService private constructor(
/**
* Sends an email notification with the form submission data.
* Includes retry mechanism for transient failures.
* Includes a retry mechanism for transient failures.
*
* @param nennung The form submission data
* @return true if the email was sent successfully, false otherwise
@@ -123,7 +123,7 @@ class EmailService private constructor(
subject = nennung.turnier?.let { "Neue Nennung für ${it.name}: ${nennung.riderName} mit ${nennung.horseName}" }
?: "Neue Nennung: ${nennung.riderName} mit ${nennung.horseName}"
// Create multipart message with both plain text and HTML versions
// Create a multipart message with both plain text and HTML versions
val multipart = MimeMultipart("alternative")
// Plain text part
@@ -8,7 +8,7 @@ import kotlinx.serialization.Serializable
*/
@Serializable
data class Bewerb(
/** Competition number, e.g. 1, 2, etc. */
/** Competition number, e.g., 1, 2, etc. */
val nummer: Int,
/** Title of the competition, e.g. "Stilspringprüfung" or "Dressurprüfung" */
@@ -38,7 +38,7 @@ fun configureDatabase() {
}
} else {
// Check if we should use SQLite (either in IDEA or in Docker with SQLite)
// First check for explicit SQLite flag
// First check for an explicit SQLite flag
val useSqlite = System.getenv("USE_SQLITE")?.toBoolean() ?: false
// Then check if we're in IDEA (no Docker environment variables set)
@@ -59,7 +59,7 @@ fun configureDatabase() {
connectionSuccessful = true
} catch (e: Exception) {
log.error("Failed to connect to SQLite (dev)!", e)
// Maybe don't throw here so the app starts in IDE anyway? Currently it throws.
// Maybe don't throw here so the app starts in IDE anyway? Currently, it throws.
throw e
}
} else {
@@ -76,7 +76,7 @@ fun configureDatabase() {
val maxPoolSize = System.getenv("DB_POOL_SIZE")?.toIntOrNull() ?: 10
val jdbcURL = "jdbc:postgresql://$dbHost:$dbPort/$dbName"
log.info("Attempting to connect to PostgreSQL at URL: {}", jdbcURL)
log.info("Attempting to connect to PostgresQL at URL: {}", jdbcURL)
val hikariConfig = HikariConfig().apply {
this.driverClassName = driverClassName
@@ -88,7 +88,7 @@ fun configureDatabase() {
}
val dataSource = HikariDataSource(hikariConfig)
Database.connect(dataSource)
log.info("PostgreSQL connection pool initialized successfully!")
log.info("PostgresQL connection pool initialized successfully!")
connectionSuccessful = true
} catch (e: Exception) {
log.error("Failed to initialize PostgreSQL connection pool!", e)
@@ -109,7 +109,7 @@ fun configureDatabase() {
} catch (e: Exception) {
log.error("Failed to initialize database schema!", e)
// Here you could decide if a schema error is critical
// throw e // Commented out: App might start anyway, even if schema is missing/wrong
// throw e // Commented out: App might start anyway, even if the schema is missing/wrong
}
}
}
@@ -27,7 +27,7 @@ class TurnierRepository {
fun createTurnier(number: Int, name: String, datum: String, bewerbe: List<Bewerb>): Turnier? = transaction {
try {
// Check if a tournament with this number already exists
val existingTurnier = TurniereTable.select { TurniereTable.number eq number }.singleOrNull()
val existingTurnier = TurniereTable.selectAll().where { TurniereTable.number eq number }.singleOrNull()
if (existingTurnier != null) {
log.error("Tournament with number $number already exists")
return@transaction null
@@ -75,7 +75,7 @@ class TurnierRepository {
fun updateTurnier(number: Int, name: String, datum: String, bewerbe: List<Bewerb>): Turnier? = transaction {
try {
// Check if the tournament exists
val existingTurnier = TurniereTable.select { TurniereTable.number eq number }.singleOrNull()
val existingTurnier = TurniereTable.selectAll().where { TurniereTable.number eq number }.singleOrNull()
if (existingTurnier == null) {
log.error("Tournament with number $number not found")
return@transaction null
@@ -1,8 +1,7 @@
package at.mocode.routes
import at.mocode.model.Bewerb
import at.mocode.config.DependencyInjection
import at.mocode.repository.TurnierRepository
import at.mocode.model.Bewerb
import at.mocode.views.AdminView
import io.ktor.http.*
import io.ktor.server.application.*
@@ -75,7 +74,7 @@ fun Route.adminRoutes() {
log.info("Received competitions for creation: ${bewerbNummern.size} numbers, ${bewerbTitel.size} titles, ${bewerbKlasse.size} classes, ${bewerbTask.size} tasks")
// Create list of competitions
// Create a list of competitions
val bewerbe = mutableListOf<Bewerb>()
for (i in bewerbNummern.indices) {
val titel = if (i < bewerbTitel.size) bewerbTitel[i] else "Unbenannter Bewerb"
@@ -133,7 +132,7 @@ fun Route.adminRoutes() {
log.info("Received competitions for update: ${bewerbNummern.size} numbers, ${bewerbTitel.size} titles, ${bewerbKlasse.size} classes, ${bewerbTask.size} tasks")
// Create list of competitions
// Create a list of competitions
val bewerbe = mutableListOf<Bewerb>()
for (i in bewerbNummern.indices) {
val titel = if (i < bewerbTitel.size) bewerbTitel[i] else "Unbenannter Bewerb"
@@ -77,6 +77,12 @@ fun Route.nennungRoutes() {
return@post
}
// Validate that at least one competition is selected
if (selectedEvents.isEmpty()) {
call.respond(HttpStatusCode.BadRequest, "Bitte wählen Sie mindestens einen Bewerb aus")
return@post
}
// Create Nennung object using repository
val nennung = nennungRepository.createNennung(
riderName = riderName,
@@ -105,7 +111,7 @@ fun Route.nennungRoutes() {
}
// Render confirmation page
nennungView.renderConfirmationPage(call, turnier, riderName, horseName)
nennungView.renderConfirmationPage(call, turnier, riderName, horseName, selectedEvents)
}
}
@@ -8,7 +8,7 @@ import org.jetbrains.exposed.sql.Column
*/
object TurniereTable : Table("turniere") {
/**
* Unique number for the tournament, used as primary key.
* Unique number for the tournament, used as a primary key.
*/
val number: Column<Int> = integer("number").uniqueIndex()
@@ -36,7 +36,7 @@ object BewerbeTable : Table("bewerbe") {
val id: Column<Int> = integer("id").autoIncrement()
/**
* Number of the competition.
* Amount of the competition.
*/
val nummer: Column<Int> = integer("nummer")
@@ -131,7 +131,7 @@ object NennungEventsTable : Table("nennung_events") {
val nennungId: Column<Int> = integer("nennung_id")
/**
* Number of the selected competition.
* Amount of the selected competition.
*/
val eventNumber: Column<String> = varchar("event_number", 100)
@@ -18,6 +18,7 @@ class LayoutTemplate {
title: String,
showNavbar: Boolean = true,
showAdminLink: Boolean = true,
showFooter: Boolean = true,
content: FlowContent.() -> Unit
) {
head {
@@ -152,6 +153,7 @@ class LayoutTemplate {
}
}
}
if (showFooter) {
footer(classes = "footer mt-5") {
attributes["data-aos"] = "fade-up"
attributes["data-aos-delay"] = "200"
@@ -214,3 +216,4 @@ class LayoutTemplate {
}
}
}
}
@@ -23,7 +23,8 @@ class NennungView {
applyLayout(
title = "Online-Nennen - ${turnier.name}",
showNavbar = false,
showAdminLink = false
showAdminLink = false,
showFooter = false
) {
h1 { +"Online-Nennen" }
@@ -44,7 +45,7 @@ class NennungView {
div(classes = "competition-item") {
div(classes = "participant-details") {
label(classes = "required") { +"Reiter-Name" }
input(type = InputType.text, name = "riderName") {
input(type = InputType.text, name = "riderName", classes = "form-control") {
attributes["required"] = "required"
attributes["placeholder"] = "Vor- und Nachname"
}
@@ -55,7 +56,7 @@ class NennungView {
div(classes = "competition-item") {
div(classes = "participant-details") {
label(classes = "required") { +"Kopf-Nr./Pferd" }
input(type = InputType.text, name = "horseName") {
input(type = InputType.text, name = "horseName", classes = "form-control") {
attributes["required"] = "required"
attributes["placeholder"] = "Name des Pferdes"
}
@@ -65,12 +66,11 @@ class NennungView {
// Contact information
div(classes = "competition-item") {
div(classes = "participant-details") {
div(classes = "form-row") {
div(classes = "form-group form-group-half") {
div(classes = "form-group") {
label { +"E-Mail" }
input(type = InputType.email, name = "email") {
attributes["placeholder"] = "ihre@email.com"
}
attributes["class"] = "form-control"
}
}
}
@@ -79,12 +79,11 @@ class NennungView {
// Contact information
div(classes = "competition-item") {
div(classes = "participant-details") {
div(classes = "form-row") {
div(classes = "form-group form-group-half") {
div(classes = "form-group") {
label { +"Telefon-Nr." }
input(type = InputType.tel, name = "phone") {
attributes["placeholder"] = "Ihre Telefonnummer"
}
attributes["class"] = "form-control"
}
}
}
@@ -104,8 +103,8 @@ class NennungView {
div(classes = "competitions-list") {
turnier.bewerbe.forEach { bewerb ->
div(classes = "competition-item") {
label {
input(type = InputType.checkBox, name = "selectedEvents") {
label(classes = "form-check") {
input(type = InputType.checkBox, name = "selectedEvents", classes = "form-check-input") {
attributes["value"] = bewerb.nummer.toString()
}
span(classes = "competition-details") {
@@ -128,7 +127,7 @@ class NennungView {
div(classes = "form-group") {
label { +"Wünsche/Bemerkungen" }
textArea {
textArea(classes = "form-control") {
attributes["rows"] = "4"
attributes["name"] = "comments"
attributes["placeholder"] = "Ihre Wünsche oder Bemerkungen zur Nennung..."
@@ -137,7 +136,8 @@ class NennungView {
}
// Submit button
div(classes = "form-actions text-center mt-4") {
div(classes = "form-actions mt-4") {
attributes["style"] = "justify-content: center;"
button(type = ButtonType.submit, classes = "button") {
+"Jetzt Nennen"
}
@@ -155,16 +155,17 @@ class NennungView {
* @param turnier The tournament the registration was for
* @param riderName The name of the rider
* @param horseName The name of the horse
* @param selectedEvents The list of selected competition IDs
*/
suspend fun renderConfirmationPage(call: ApplicationCall, turnier: Turnier, riderName: String, horseName: String) {
suspend fun renderConfirmationPage(call: ApplicationCall, turnier: Turnier, riderName: String, horseName: String, selectedEvents: List<String>) {
call.respondHtml(HttpStatusCode.OK) {
layoutTemplate.apply {
applyLayout(
title = "Nennung bestätigt - ${turnier.name}",
showNavbar = false,
showAdminLink = false
showAdminLink = false,
showFooter = false
) {
h1 { +"Nennung bestätigt" }
div(classes = "confirmation-box") {
div(classes = "confirmation-icon") {
@@ -189,6 +190,28 @@ class NennungView {
span(classes = "detail-label") { +"Pferd:" }
span(classes = "detail-value") { +horseName }
}
// Display selected competitions
if (selectedEvents.isNotEmpty()) {
div(classes = "detail-item mt-3") {
span(classes = "detail-label") { +"Ausgewählte Bewerbe:" }
div(classes = "selected-competitions") {
ul(classes = "competition-list") {
selectedEvents.forEach { eventId ->
val bewerb = turnier.bewerbe.find { it.nummer.toString() == eventId }
if (bewerb != null) {
li {
+"${bewerb.nummer}. ${bewerb.titel} - ${bewerb.klasse}"
if (bewerb.task != null) {
+" - ${bewerb.task}"
}
}
}
}
}
}
}
}
}
p(classes = "confirmation-message") {
@@ -15,9 +15,7 @@
left: 0;
width: 100%;
height: 100%;
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320"><path fill="rgba(255, 255, 255, 0.05)" fill-opacity="1" d="M0,192L48,197.3C96,203,192,213,288,229.3C384,245,480,267,576,250.7C672,235,768,181,864,181.3C960,181,1056,235,1152,234.7C1248,235,1344,181,1392,154.7L1440,128L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z"></path></svg>');
background-repeat: no-repeat;
background-position: bottom;
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320"><path fill="rgba(255, 255, 255, 0.05)" fill-opacity="1" d="M0,192L48,197.3C96,203,192,213,288,229.3C384,245,480,267,576,250.7C672,235,768,181,864,181.3C960,181,1056,235,1152,234.7C1248,235,1344,181,1392,154.7L1440,128L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z"></path></svg>') no-repeat bottom;
background-size: cover;
opacity: 0.1;
z-index: 0;
@@ -250,6 +250,8 @@
color: var(--primary-color);
font-size: 1.25rem;
font-weight: 600;
font-family: 'Inter', 'Roboto', 'Segoe UI', system-ui, -apple-system, sans-serif;
line-height: 1.3;
}
/* Custom form action buttons container */
@@ -354,6 +356,24 @@
}
}
/* Selected competitions list in confirmation page */
.selected-competitions ul.competition-list {
list-style: none;
padding-left: 0;
margin-top: 0.5rem;
}
.selected-competitions ul.competition-list li {
padding: 0.5rem 0;
border-bottom: 1px dashed var(--border-color);
margin-bottom: 0.5rem;
}
.selected-competitions ul.competition-list li:last-child {
border-bottom: none;
margin-bottom: 0;
}
@media (max-width: 480px) {
.form-section {
padding: 1.25rem;
@@ -146,10 +146,9 @@
}
.tournament-competitions li {
padding: 0.5rem 0;
border-bottom: 1px dashed var(--border-color);
transition: transform var(--transition-fast);
padding-left: 1.5rem;
padding: 0.5rem 0 0.5rem 1.5rem;
position: relative;
}
@@ -244,14 +243,14 @@
.competitions-list {
width: 100%;
margin: 0;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 1.5rem;
display: flex;
flex-direction: column;
gap: 0.75rem;
}
/* Competition item */
.competition-item {
padding: 1.25rem;
padding: 0.75rem;
border-radius: var(--border-radius);
transition: all var(--transition-fast);
border: 1px solid var(--border-color);
@@ -259,7 +258,8 @@
box-shadow: var(--box-shadow-sm);
height: 100%;
display: flex;
flex-direction: column;
flex-direction: row;
align-items: center;
}
.competition-item:hover {
@@ -272,43 +272,81 @@
/* Custom form check styling */
.competition-item .form-check {
display: flex;
align-items: flex-start;
align-items: center;
padding-left: 0;
margin-bottom: 0;
height: 100%;
width: 100%;
}
.competition-item .form-check-input {
margin-right: 1rem;
margin-top: 0.25rem;
float: none;
flex-shrink: 0;
width: 1.25rem;
height: 1.25rem;
cursor: pointer;
border: 2px solid var(--primary-color);
border-radius: 0.25rem;
transition: all var(--transition-fast);
position: relative;
background-color: white;
}
.competition-item .form-check-input:checked {
background-color: var(--primary-color);
border-color: var(--primary-color);
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='M6 10l3 3l6-6'/%3e%3c/svg%3e");
background-position: center;
background-repeat: no-repeat;
background-size: 75%;
}
.competition-item .form-check-input:focus {
outline: 0;
box-shadow: 0 0 0 0.25rem rgba(67, 97, 238, 0.25);
border-color: var(--primary-hover);
}
.competition-item .form-check-input:hover {
border-color: var(--primary-hover);
}
.competition-details {
flex-grow: 1;
font-family: 'Inter', 'Roboto', 'Segoe UI', system-ui, -apple-system, sans-serif;
color: var(--text-color);
line-height: 1.5;
font-size: 1rem;
}
.competition-details strong {
color: var(--primary-color);
font-weight: 700;
font-size: 1.1rem;
display: block;
margin-bottom: 0.5rem;
display: inline;
margin-right: 0.25rem;
}
/* Participant details section */
.participant-details {
width: 100%;
font-family: 'Inter', 'Roboto', 'Segoe UI', system-ui, -apple-system, sans-serif;
}
.participant-details .form-label {
font-weight: 600;
margin-bottom: 0.5rem;
color: var(--text-color);
font-size: 1rem;
line-height: 1.5;
}
.participant-details input,
.participant-details textarea {
font-family: 'Inter', 'Roboto', 'Segoe UI', system-ui, -apple-system, sans-serif;
color: var(--text-color);
font-size: 1rem;
}
/* Custom form spacing */
@@ -5,7 +5,7 @@
--secondary-color: #7209b7;
--secondary-hover: #6008a0;
--accent-color: #f72585;
--text-color: #2b2d42;
--text-color: #555555;
--light-text: #6c757d;
--lighter-text: #adb5bd;
--border-color: #e9ecef;