refactor: Migrate from monolithic to modular architecture

- Restructure project into domain-specific modules (core, masterdata, members, horses, events, infrastructure)
- Create shared client components in common-ui module
- Implement CI/CD workflows with GitHub Actions
- Consolidate documentation in docs directory
- Remove deprecated modules and documentation files
- Add cleanup and migration scripts for transition
- Update README with new project structure and setup instructions
This commit is contained in:
stefan
2025-07-22 18:44:18 +02:00
parent 8229e8e571
commit a256622f37
314 changed files with 5930 additions and 19817 deletions
@@ -0,0 +1,10 @@
plugins {
kotlin("jvm")
}
dependencies {
implementation(projects.events.eventsDomain)
implementation(projects.core.coreDomain)
implementation(projects.core.coreUtils)
testImplementation(projects.platform.platformTesting)
}
@@ -0,0 +1,173 @@
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.utils.validation.ValidationResult
import at.mocode.core.utils.validation.ValidationError
import com.benasher44.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)
}
}
}
@@ -0,0 +1,108 @@
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 com.benasher44.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}"
)
)
}
}
}
@@ -0,0 +1,68 @@
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 com.benasher44.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}"
)
)
}
}
}
@@ -0,0 +1,185 @@
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.utils.validation.ValidationResult
import at.mocode.core.utils.validation.ValidationError
import com.benasher44.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)
}
}
}