(vision) SCS/DDD

This commit is contained in:
2025-07-16 00:38:19 +02:00
parent 6e52015f46
commit 67c52f7381
34 changed files with 4679 additions and 119 deletions
@@ -20,11 +20,13 @@ data class ArtikelDto(
val preis: BigDecimal,
val einheit: String,
val istVerbandsabgabe: Boolean,
@Since("1.1")
val kategorie: String? = null, // New field in version 1.1
@Serializable(with = KotlinInstantSerializer::class)
val createdAt: Instant,
@Serializable(with = KotlinInstantSerializer::class)
val updatedAt: Instant,
override val schemaVersion: String = "1.0",
override val schemaVersion: String = "1.1",
override val dataVersion: Long? = null
) : VersionedDto
@@ -36,7 +38,9 @@ data class CreateArtikelDto(
val preis: BigDecimal,
val einheit: String,
val istVerbandsabgabe: Boolean = false,
override val schemaVersion: String = "1.0",
@Since("1.1")
val kategorie: String? = null, // New field in version 1.1
override val schemaVersion: String = "1.1",
override val dataVersion: Long? = null
) : VersionedDto
@@ -48,6 +52,8 @@ data class UpdateArtikelDto(
val preis: BigDecimal,
val einheit: String,
val istVerbandsabgabe: Boolean = false,
override val schemaVersion: String = "1.0",
@Since("1.1")
val kategorie: String? = null, // New field in version 1.1
override val schemaVersion: String = "1.1",
override val dataVersion: Long? = null
) : VersionedDto
@@ -6,13 +6,13 @@ package at.mocode.dto.base
object VersionManager {
// Current API version
const val CURRENT_API_VERSION = "1.0"
const val CURRENT_API_VERSION = "1.1"
// Supported API versions (newest first)
val SUPPORTED_VERSIONS = listOf("1.0")
val SUPPORTED_VERSIONS = listOf("1.1", "1.0")
// Deprecated versions (still supported but discouraged)
val DEPRECATED_VERSIONS = emptyList<String>()
val DEPRECATED_VERSIONS = listOf("1.0")
// Minimum client version required
const val MINIMUM_CLIENT_VERSION = "1.0"
@@ -12,8 +12,9 @@ class ArtikelDtoMigrator : VersionMigrator<ArtikelDto> {
override fun migrate(dto: ArtikelDto, fromVersion: String, toVersion: String): ArtikelDto {
return when {
fromVersion == "1.0" && toVersion == "1.0" -> dto
fromVersion == "1.0" && toVersion == "1.1" -> migrateFrom1_0To1_1(dto)
fromVersion == "1.1" && toVersion == "1.1" -> dto
// Future migrations would be handled here
// fromVersion == "1.0" && toVersion == "1.1" -> migrateFrom1_0To1_1(dto)
// fromVersion == "1.1" && toVersion == "1.2" -> migrateFrom1_1To1_2(dto)
else -> throw IllegalArgumentException("Unsupported migration from $fromVersion to $toVersion")
}
@@ -22,19 +23,22 @@ class ArtikelDtoMigrator : VersionMigrator<ArtikelDto> {
override fun canMigrate(fromVersion: String, toVersion: String): Boolean {
return when {
fromVersion == "1.0" && toVersion == "1.0" -> true
fromVersion == "1.0" && toVersion == "1.1" -> true
fromVersion == "1.1" && toVersion == "1.1" -> true
// Future migration paths would be defined here
// fromVersion == "1.0" && toVersion == "1.1" -> true
// fromVersion == "1.1" && toVersion == "1.2" -> true
else -> false
}
}
// Example of a future migration method
// private fun migrateFrom1_0To1_1(dto: ArtikelDto): ArtikelDto {
// return dto.copy(
// schemaVersion = "1.1",
// // Add new fields with default values
// // newField = "defaultValue"
// )
// }
/**
* Migrate ArtikelDto from version 1.0 to 1.1
* Adds the new kategorie field with a default value
*/
private fun migrateFrom1_0To1_1(dto: ArtikelDto): ArtikelDto {
return dto.copy(
schemaVersion = "1.1",
kategorie = "Allgemein" // Default category for existing articles
)
}
}
@@ -19,6 +19,7 @@ data class Artikel(
var preis: BigDecimal,
var einheit: String,
var istVerbandsabgabe: Boolean = false,
var kategorie: String? = null, // New field for version 1.1
@Serializable(with = KotlinInstantSerializer::class)
val createdAt: Instant = Clock.System.now(),
@Serializable(with = KotlinInstantSerializer::class)