Merge pull request #18
* MP-19 Refactoring: Einführung der "Registry" & "Masterdata" Trennung … * MP-19 Refactoring: Frontend Tabula Rasa * MP-19 Refactoring: Frontend Tabula Rasa * refactoring: * MP-20 fix(docker/clients): include `:domains` module in web/desktop b… * MP-20 fix(web-app build): resolve JS compile error and add dev/prod b… * MP-20 fix(web-app): remove vendor.js reference and harden JS bootstra… * MP-20 fixing: clients * MP-20 fixing: clients
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
plugins {
|
||||
// KORREKTUR: Von 'kotlin("jvm")' zu Multiplattform wechseln.
|
||||
alias(libs.plugins.kotlin.multiplatform)
|
||||
alias(libs.plugins.kotlin.serialization)
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
js(IR) {
|
||||
browser()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
val commonMain by getting {
|
||||
dependencies {
|
||||
// Hier die jeweiligen Modul-Abhängigkeiten eintragen
|
||||
// z.B. für events-domain:
|
||||
implementation(projects.core.coreDomain)
|
||||
|
||||
// z.B. für events-application:
|
||||
// implementation(projects.events.eventsDomain)
|
||||
}
|
||||
}
|
||||
|
||||
val commonTest by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("test"))
|
||||
implementation(projects.platform.platformTesting)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
@file:OptIn(kotlin.uuid.ExperimentalUuidApi::class)
|
||||
package at.mocode.events.application.usecase
|
||||
|
||||
import at.mocode.core.domain.model.ApiResponse
|
||||
import at.mocode.core.domain.model.ErrorDto
|
||||
import at.mocode.events.domain.model.Veranstaltung
|
||||
import at.mocode.events.domain.repository.VeranstaltungRepository
|
||||
import at.mocode.core.domain.model.SparteE
|
||||
import at.mocode.core.domain.model.ValidationResult
|
||||
import at.mocode.core.domain.model.ValidationError
|
||||
import kotlin.uuid.Uuid
|
||||
import kotlinx.datetime.Clock
|
||||
import kotlinx.datetime.LocalDate
|
||||
|
||||
/**
|
||||
* Use case for creating new events (Veranstaltung).
|
||||
*
|
||||
* This use case handles the business logic for creating events,
|
||||
* including validation and persistence.
|
||||
*/
|
||||
class CreateVeranstaltungUseCase(
|
||||
private val veranstaltungRepository: VeranstaltungRepository
|
||||
) {
|
||||
|
||||
/**
|
||||
* Request data for creating a new event.
|
||||
*/
|
||||
data class CreateVeranstaltungRequest(
|
||||
val name: String,
|
||||
val beschreibung: String? = null,
|
||||
val startDatum: LocalDate,
|
||||
val endDatum: LocalDate,
|
||||
val ort: String,
|
||||
val veranstalterVereinId: Uuid,
|
||||
val sparten: List<SparteE> = emptyList(),
|
||||
val istAktiv: Boolean = true,
|
||||
val istOeffentlich: Boolean = true,
|
||||
val maxTeilnehmer: Int? = null,
|
||||
val anmeldeschluss: LocalDate? = null
|
||||
)
|
||||
|
||||
/**
|
||||
* Response data containing the created event.
|
||||
*/
|
||||
data class CreateVeranstaltungResponse(
|
||||
val veranstaltung: Veranstaltung
|
||||
)
|
||||
|
||||
/**
|
||||
* Executes the create event use case.
|
||||
*
|
||||
* @param request The request containing event data
|
||||
* @return ApiResponse with the created event or error information
|
||||
*/
|
||||
suspend fun execute(request: CreateVeranstaltungRequest): ApiResponse<CreateVeranstaltungResponse> {
|
||||
return try {
|
||||
// Validate the request
|
||||
val validationResult = validateRequest(request)
|
||||
if (!validationResult.isValid()) {
|
||||
val errors = (validationResult as ValidationResult.Invalid).errors
|
||||
return ApiResponse(
|
||||
success = false,
|
||||
error = ErrorDto(
|
||||
code = "VALIDATION_ERROR",
|
||||
message = "Invalid input data",
|
||||
details = errors.associate { it.field to it.message }
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// Create the domain object
|
||||
val veranstaltung = Veranstaltung(
|
||||
name = request.name.trim(),
|
||||
beschreibung = request.beschreibung?.trim(),
|
||||
startDatum = request.startDatum,
|
||||
endDatum = request.endDatum,
|
||||
ort = request.ort.trim(),
|
||||
veranstalterVereinId = request.veranstalterVereinId,
|
||||
sparten = request.sparten,
|
||||
istAktiv = request.istAktiv,
|
||||
istOeffentlich = request.istOeffentlich,
|
||||
maxTeilnehmer = request.maxTeilnehmer,
|
||||
anmeldeschluss = request.anmeldeschluss,
|
||||
createdAt = Clock.System.now(),
|
||||
updatedAt = Clock.System.now()
|
||||
)
|
||||
|
||||
// Validate the domain object
|
||||
val domainValidationErrors = veranstaltung.validate()
|
||||
if (domainValidationErrors.isNotEmpty()) {
|
||||
return ApiResponse(
|
||||
success = false,
|
||||
error = ErrorDto(
|
||||
code = "DOMAIN_VALIDATION_ERROR",
|
||||
message = "Domain validation failed",
|
||||
details = domainValidationErrors.mapIndexed { index, error ->
|
||||
"error_$index" to error
|
||||
}.toMap()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// Save the event
|
||||
val savedVeranstaltung = veranstaltungRepository.save(veranstaltung)
|
||||
|
||||
ApiResponse(
|
||||
success = true,
|
||||
data = CreateVeranstaltungResponse(savedVeranstaltung)
|
||||
)
|
||||
|
||||
} catch (e: Exception) {
|
||||
ApiResponse(
|
||||
success = false,
|
||||
error = ErrorDto(
|
||||
code = "INTERNAL_ERROR",
|
||||
message = "Failed to create event: ${e.message}"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the create event request.
|
||||
*/
|
||||
private fun validateRequest(request: CreateVeranstaltungRequest): ValidationResult {
|
||||
val errors = mutableListOf<ValidationError>()
|
||||
|
||||
// Validate name
|
||||
if (request.name.isBlank()) {
|
||||
errors.add(ValidationError("name", "Event name is required"))
|
||||
} else if (request.name.length > 255) {
|
||||
errors.add(ValidationError("name", "Event name must not exceed 255 characters"))
|
||||
}
|
||||
|
||||
// Validate location
|
||||
if (request.ort.isBlank()) {
|
||||
errors.add(ValidationError("ort", "Event location is required"))
|
||||
} else if (request.ort.length > 255) {
|
||||
errors.add(ValidationError("ort", "Event location must not exceed 255 characters"))
|
||||
}
|
||||
|
||||
// Validate dates
|
||||
if (request.endDatum < request.startDatum) {
|
||||
errors.add(ValidationError("endDatum", "End date cannot be before start date"))
|
||||
}
|
||||
|
||||
// Validate registration deadline
|
||||
request.anmeldeschluss?.let { deadline ->
|
||||
if (deadline > request.startDatum) {
|
||||
errors.add(ValidationError("anmeldeschluss", "Registration deadline cannot be after event start date"))
|
||||
}
|
||||
}
|
||||
|
||||
// Validate max participants
|
||||
request.maxTeilnehmer?.let { max ->
|
||||
if (max <= 0) {
|
||||
errors.add(ValidationError("maxTeilnehmer", "Maximum participants must be positive"))
|
||||
}
|
||||
}
|
||||
|
||||
// Validate description length
|
||||
request.beschreibung?.let { desc ->
|
||||
if (desc.length > 5000) {
|
||||
errors.add(ValidationError("beschreibung", "Description must not exceed 5000 characters"))
|
||||
}
|
||||
}
|
||||
|
||||
return if (errors.isEmpty()) {
|
||||
ValidationResult.Valid
|
||||
} else {
|
||||
ValidationResult.Invalid(errors)
|
||||
}
|
||||
}
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
@file:OptIn(kotlin.uuid.ExperimentalUuidApi::class)
|
||||
package at.mocode.events.application.usecase
|
||||
|
||||
import at.mocode.core.domain.model.ApiResponse
|
||||
import at.mocode.core.domain.model.ErrorDto
|
||||
import at.mocode.events.domain.repository.VeranstaltungRepository
|
||||
import kotlin.uuid.Uuid
|
||||
|
||||
/**
|
||||
* Use case for deleting events (Veranstaltung).
|
||||
*
|
||||
* This use case handles the business logic for deleting events,
|
||||
* including validation and cleanup.
|
||||
*/
|
||||
class DeleteVeranstaltungUseCase(
|
||||
private val veranstaltungRepository: VeranstaltungRepository
|
||||
) {
|
||||
|
||||
/**
|
||||
* Request data for deleting an event.
|
||||
*/
|
||||
data class DeleteVeranstaltungRequest(
|
||||
val veranstaltungId: Uuid,
|
||||
val forceDelete: Boolean = false
|
||||
)
|
||||
|
||||
/**
|
||||
* Response data for successful deletion.
|
||||
*/
|
||||
data class DeleteVeranstaltungResponse(
|
||||
val deleted: Boolean,
|
||||
val message: String
|
||||
)
|
||||
|
||||
/**
|
||||
* Executes the delete event use case.
|
||||
*
|
||||
* @param request The request containing the event ID to delete
|
||||
* @return ApiResponse with deletion result or error information
|
||||
*/
|
||||
suspend fun execute(request: DeleteVeranstaltungRequest): ApiResponse<DeleteVeranstaltungResponse> {
|
||||
return try {
|
||||
// Check if event exists
|
||||
val existingVeranstaltung = veranstaltungRepository.findById(request.veranstaltungId)
|
||||
if (existingVeranstaltung == null) {
|
||||
return ApiResponse(
|
||||
success = false,
|
||||
error = ErrorDto(
|
||||
code = "NOT_FOUND",
|
||||
message = "Event not found"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// Check if event can be safely deleted
|
||||
if (!request.forceDelete) {
|
||||
// In a real implementation, you might check for:
|
||||
// - Active registrations
|
||||
// - Related competitions
|
||||
// - Financial transactions
|
||||
// For now, we'll allow deletion if the event is not active or is in the future
|
||||
|
||||
if (existingVeranstaltung.istAktiv) {
|
||||
return ApiResponse(
|
||||
success = false,
|
||||
error = ErrorDto(
|
||||
code = "CANNOT_DELETE_ACTIVE_EVENT",
|
||||
message = "Cannot delete active event. Use forceDelete=true to override.",
|
||||
details = mapOf(
|
||||
"eventId" to request.veranstaltungId.toString(),
|
||||
"eventName" to existingVeranstaltung.name
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Perform the deletion
|
||||
val deleted = veranstaltungRepository.delete(request.veranstaltungId)
|
||||
|
||||
if (deleted) {
|
||||
ApiResponse(
|
||||
success = true,
|
||||
data = DeleteVeranstaltungResponse(
|
||||
deleted = true,
|
||||
message = "Event '${existingVeranstaltung.name}' has been successfully deleted"
|
||||
)
|
||||
)
|
||||
} else {
|
||||
ApiResponse(
|
||||
success = false,
|
||||
error = ErrorDto(
|
||||
code = "DELETE_FAILED",
|
||||
message = "Failed to delete event from database"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
ApiResponse(
|
||||
success = false,
|
||||
error = ErrorDto(
|
||||
code = "INTERNAL_ERROR",
|
||||
message = "Failed to delete event: ${e.message}"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
@file:OptIn(kotlin.uuid.ExperimentalUuidApi::class)
|
||||
package at.mocode.events.application.usecase
|
||||
|
||||
import at.mocode.core.domain.model.ApiResponse
|
||||
import at.mocode.core.domain.model.ErrorDto
|
||||
import at.mocode.events.domain.model.Veranstaltung
|
||||
import at.mocode.events.domain.repository.VeranstaltungRepository
|
||||
import kotlin.uuid.Uuid
|
||||
|
||||
/**
|
||||
* Use case for retrieving events (Veranstaltung) by ID.
|
||||
*
|
||||
* This use case handles the business logic for fetching events
|
||||
* from the repository.
|
||||
*/
|
||||
class GetVeranstaltungUseCase(
|
||||
private val veranstaltungRepository: VeranstaltungRepository
|
||||
) {
|
||||
|
||||
/**
|
||||
* Request data for retrieving an event.
|
||||
*/
|
||||
data class GetVeranstaltungRequest(
|
||||
val veranstaltungId: Uuid
|
||||
)
|
||||
|
||||
/**
|
||||
* Response data containing the retrieved event.
|
||||
*/
|
||||
data class GetVeranstaltungResponse(
|
||||
val veranstaltung: Veranstaltung
|
||||
)
|
||||
|
||||
/**
|
||||
* Executes the get event use case.
|
||||
*
|
||||
* @param request The request containing the event ID
|
||||
* @return ApiResponse with the event or error information
|
||||
*/
|
||||
suspend fun execute(request: GetVeranstaltungRequest): ApiResponse<GetVeranstaltungResponse> {
|
||||
return try {
|
||||
val veranstaltung = veranstaltungRepository.findById(request.veranstaltungId)
|
||||
|
||||
if (veranstaltung != null) {
|
||||
ApiResponse(
|
||||
success = true,
|
||||
data = GetVeranstaltungResponse(veranstaltung)
|
||||
)
|
||||
} else {
|
||||
ApiResponse(
|
||||
success = false,
|
||||
error = ErrorDto(
|
||||
code = "NOT_FOUND",
|
||||
message = "Event not found"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
ApiResponse(
|
||||
success = false,
|
||||
error = ErrorDto(
|
||||
code = "INTERNAL_ERROR",
|
||||
message = "Failed to retrieve event: ${e.message}"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
@file:OptIn(kotlin.uuid.ExperimentalUuidApi::class)
|
||||
package at.mocode.events.application.usecase
|
||||
|
||||
import at.mocode.core.domain.model.ApiResponse
|
||||
import at.mocode.core.domain.model.ErrorDto
|
||||
import at.mocode.events.domain.model.Veranstaltung
|
||||
import at.mocode.events.domain.repository.VeranstaltungRepository
|
||||
import at.mocode.core.domain.model.SparteE
|
||||
import at.mocode.core.domain.model.ValidationResult
|
||||
import at.mocode.core.domain.model.ValidationError
|
||||
import kotlin.uuid.Uuid
|
||||
import kotlinx.datetime.Clock
|
||||
import kotlinx.datetime.LocalDate
|
||||
|
||||
/**
|
||||
* Use case for updating existing events (Veranstaltung).
|
||||
*
|
||||
* This use case handles the business logic for updating events,
|
||||
* including validation and persistence.
|
||||
*/
|
||||
class UpdateVeranstaltungUseCase(
|
||||
private val veranstaltungRepository: VeranstaltungRepository
|
||||
) {
|
||||
|
||||
/**
|
||||
* Request data for updating an event.
|
||||
*/
|
||||
data class UpdateVeranstaltungRequest(
|
||||
val veranstaltungId: Uuid,
|
||||
val name: String,
|
||||
val beschreibung: String? = null,
|
||||
val startDatum: LocalDate,
|
||||
val endDatum: LocalDate,
|
||||
val ort: String,
|
||||
val veranstalterVereinId: Uuid,
|
||||
val sparten: List<SparteE> = emptyList(),
|
||||
val istAktiv: Boolean = true,
|
||||
val istOeffentlich: Boolean = true,
|
||||
val maxTeilnehmer: Int? = null,
|
||||
val anmeldeschluss: LocalDate? = null
|
||||
)
|
||||
|
||||
/**
|
||||
* Response data containing the updated event.
|
||||
*/
|
||||
data class UpdateVeranstaltungResponse(
|
||||
val veranstaltung: Veranstaltung
|
||||
)
|
||||
|
||||
/**
|
||||
* Executes the update event use case.
|
||||
*
|
||||
* @param request The request containing updated event data
|
||||
* @return ApiResponse with the updated event or error information
|
||||
*/
|
||||
suspend fun execute(request: UpdateVeranstaltungRequest): ApiResponse<UpdateVeranstaltungResponse> {
|
||||
return try {
|
||||
// Check if event exists
|
||||
val existingVeranstaltung = veranstaltungRepository.findById(request.veranstaltungId)
|
||||
if (existingVeranstaltung == null) {
|
||||
return ApiResponse(
|
||||
success = false,
|
||||
error = ErrorDto(
|
||||
code = "NOT_FOUND",
|
||||
message = "Event not found"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// Validate the request
|
||||
val validationResult = validateRequest(request)
|
||||
if (!validationResult.isValid()) {
|
||||
val errors = (validationResult as ValidationResult.Invalid).errors
|
||||
return ApiResponse(
|
||||
success = false,
|
||||
error = ErrorDto(
|
||||
code = "VALIDATION_ERROR",
|
||||
message = "Invalid input data",
|
||||
details = errors.associate { it.field to it.message }
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// Create updated domain object
|
||||
val updatedVeranstaltung = existingVeranstaltung.copy(
|
||||
name = request.name.trim(),
|
||||
beschreibung = request.beschreibung?.trim(),
|
||||
startDatum = request.startDatum,
|
||||
endDatum = request.endDatum,
|
||||
ort = request.ort.trim(),
|
||||
veranstalterVereinId = request.veranstalterVereinId,
|
||||
sparten = request.sparten,
|
||||
istAktiv = request.istAktiv,
|
||||
istOeffentlich = request.istOeffentlich,
|
||||
maxTeilnehmer = request.maxTeilnehmer,
|
||||
anmeldeschluss = request.anmeldeschluss,
|
||||
updatedAt = Clock.System.now()
|
||||
)
|
||||
|
||||
// Validate the domain object
|
||||
val domainValidationErrors = updatedVeranstaltung.validate()
|
||||
if (domainValidationErrors.isNotEmpty()) {
|
||||
return ApiResponse(
|
||||
success = false,
|
||||
error = ErrorDto(
|
||||
code = "DOMAIN_VALIDATION_ERROR",
|
||||
message = "Domain validation failed",
|
||||
details = domainValidationErrors.mapIndexed { index, error ->
|
||||
"error_$index" to error
|
||||
}.toMap()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// Save the updated event
|
||||
val savedVeranstaltung = veranstaltungRepository.save(updatedVeranstaltung)
|
||||
|
||||
ApiResponse(
|
||||
success = true,
|
||||
data = UpdateVeranstaltungResponse(savedVeranstaltung)
|
||||
)
|
||||
|
||||
} catch (e: Exception) {
|
||||
ApiResponse(
|
||||
success = false,
|
||||
error = ErrorDto(
|
||||
code = "INTERNAL_ERROR",
|
||||
message = "Failed to update event: ${e.message}"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the update event request.
|
||||
*/
|
||||
private fun validateRequest(request: UpdateVeranstaltungRequest): ValidationResult {
|
||||
val errors = mutableListOf<ValidationError>()
|
||||
|
||||
// Validate name
|
||||
if (request.name.isBlank()) {
|
||||
errors.add(ValidationError("name", "Event name is required"))
|
||||
} else if (request.name.length > 255) {
|
||||
errors.add(ValidationError("name", "Event name must not exceed 255 characters"))
|
||||
}
|
||||
|
||||
// Validate location
|
||||
if (request.ort.isBlank()) {
|
||||
errors.add(ValidationError("ort", "Event location is required"))
|
||||
} else if (request.ort.length > 255) {
|
||||
errors.add(ValidationError("ort", "Event location must not exceed 255 characters"))
|
||||
}
|
||||
|
||||
// Validate dates
|
||||
if (request.endDatum < request.startDatum) {
|
||||
errors.add(ValidationError("endDatum", "End date cannot be before start date"))
|
||||
}
|
||||
|
||||
// Validate registration deadline
|
||||
request.anmeldeschluss?.let { deadline ->
|
||||
if (deadline > request.startDatum) {
|
||||
errors.add(ValidationError("anmeldeschluss", "Registration deadline cannot be after event start date"))
|
||||
}
|
||||
}
|
||||
|
||||
// Validate max participants
|
||||
request.maxTeilnehmer?.let { max ->
|
||||
if (max <= 0) {
|
||||
errors.add(ValidationError("maxTeilnehmer", "Maximum participants must be positive"))
|
||||
}
|
||||
}
|
||||
|
||||
// Validate description length
|
||||
request.beschreibung?.let { desc ->
|
||||
if (desc.length > 5000) {
|
||||
errors.add(ValidationError("beschreibung", "Description must not exceed 5000 characters"))
|
||||
}
|
||||
}
|
||||
|
||||
return if (errors.isEmpty()) {
|
||||
ValidationResult.Valid
|
||||
} else {
|
||||
ValidationResult.Invalid(errors)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user