fix Redis
This commit is contained in:
@@ -4,7 +4,8 @@ import at.mocode.core.domain.serialization.KotlinInstantSerializer
|
||||
import at.mocode.core.domain.serialization.UuidSerializer
|
||||
import com.benasher44.uuid.Uuid
|
||||
import com.benasher44.uuid.uuid4
|
||||
import kotlinx.datetime.Instant
|
||||
import kotlin.time.Clock
|
||||
import kotlin.time.Instant
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
@@ -15,8 +16,8 @@ interface DomainEvent {
|
||||
val eventId: Uuid
|
||||
val aggregateId: Uuid
|
||||
val eventType: String
|
||||
val timestamp: kotlin.time.Instant
|
||||
val version: Long // KORRIGIERT: Einheitlich auf Long
|
||||
val timestamp: Instant
|
||||
val version: Long
|
||||
val correlationId: Uuid?
|
||||
val causationId: Uuid?
|
||||
}
|
||||
@@ -29,11 +30,11 @@ abstract class BaseDomainEvent(
|
||||
@Serializable(with = UuidSerializer::class)
|
||||
override val aggregateId: Uuid,
|
||||
override val eventType: String,
|
||||
override val version: Long, // KORRIGIERT: Einheitlich auf Long
|
||||
override val version: Long,
|
||||
@Serializable(with = UuidSerializer::class)
|
||||
override val eventId: Uuid = uuid4(),
|
||||
@Serializable(with = KotlinInstantSerializer::class)
|
||||
override val timestamp: kotlin.time.Instant = kotlin.time.Clock.System.now(), // KORRIGIERT: Einheitlich auf kotlinx.datetime.Instant
|
||||
override val timestamp: Instant = Clock.System.now(),
|
||||
@Serializable(with = UuidSerializer::class)
|
||||
override val correlationId: Uuid? = null,
|
||||
@Serializable(with = UuidSerializer::class)
|
||||
|
||||
@@ -9,13 +9,11 @@ import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* A marker interface for all Data Transfer Objects.
|
||||
* While not strictly necessary, it can be useful for generic constraints.
|
||||
*/
|
||||
interface BaseDto
|
||||
|
||||
/**
|
||||
* Base DTO for domain entities that have a unique ID and audit timestamps.
|
||||
* Ensures that all primary entities share a common structure.
|
||||
* Base DTO for domain entities that have unique ID and audit timestamps.
|
||||
*/
|
||||
@Serializable
|
||||
abstract class EntityDto : BaseDto {
|
||||
@@ -34,16 +32,13 @@ abstract class EntityDto : BaseDto {
|
||||
*/
|
||||
@Serializable
|
||||
data class ErrorDto(
|
||||
val code: String, // A machine-readable error code, e.g., "VALIDATION_ERROR"
|
||||
val message: String, // A human-readable message, e.g., "Email is not valid"
|
||||
val field: String? = null // Optional: The specific field the error relates to
|
||||
val code: String,
|
||||
val message: String,
|
||||
val field: String? = null
|
||||
) : BaseDto
|
||||
|
||||
/**
|
||||
* A standardized and consistent wrapper for all API responses.
|
||||
* It clearly separates the data payload from metadata about the request's success and potential errors.
|
||||
*
|
||||
* @param T The type of the data payload.
|
||||
*/
|
||||
@Serializable
|
||||
data class ApiResponse<T>(
|
||||
@@ -54,16 +49,10 @@ data class ApiResponse<T>(
|
||||
val timestamp: Instant = Clock.System.now()
|
||||
) {
|
||||
companion object {
|
||||
/**
|
||||
* Factory function to create a standardized success response.
|
||||
*/
|
||||
fun <T> success(data: T): ApiResponse<T> {
|
||||
return ApiResponse(data = data, success = true)
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory function to create a standardized error response.
|
||||
*/
|
||||
fun <T> error(
|
||||
code: String,
|
||||
message: String,
|
||||
@@ -76,9 +65,6 @@ data class ApiResponse<T>(
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory function to create a standardized error response with multiple errors.
|
||||
*/
|
||||
fun <T> error(errors: List<ErrorDto>): ApiResponse<T> {
|
||||
return ApiResponse(data = null, success = false, errors = errors)
|
||||
}
|
||||
@@ -87,9 +73,6 @@ data class ApiResponse<T>(
|
||||
|
||||
/**
|
||||
* A standardized wrapper for paginated API responses.
|
||||
* Contains the list of items for the current page as well as all necessary pagination metadata.
|
||||
*
|
||||
* @param T The type of the content in the page.
|
||||
*/
|
||||
@Serializable
|
||||
data class PagedResponse<T>(
|
||||
@@ -101,5 +84,3 @@ data class PagedResponse<T>(
|
||||
val hasNext: Boolean,
|
||||
val hasPrevious: Boolean
|
||||
)
|
||||
|
||||
// REMOVED: The PaginationDto was redundant as all its information is already contained within PagedResponse.
|
||||
|
||||
+1
-16
@@ -2,7 +2,7 @@ package at.mocode.core.domain.serialization
|
||||
|
||||
import com.benasher44.uuid.Uuid
|
||||
import com.benasher44.uuid.uuidFrom
|
||||
import kotlin.time.Instant
|
||||
import kotlin.time.Instant // KORRIGIERT: Finaler Wechsel zu kotlin.time
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.LocalDateTime
|
||||
import kotlinx.datetime.LocalTime
|
||||
@@ -13,45 +13,30 @@ import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
/**
|
||||
* Serializer for UUID values
|
||||
*/
|
||||
object UuidSerializer : KSerializer<Uuid> {
|
||||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("UUID", PrimitiveKind.STRING)
|
||||
override fun serialize(encoder: Encoder, value: Uuid) = encoder.encodeString(value.toString())
|
||||
override fun deserialize(decoder: Decoder): Uuid = uuidFrom(decoder.decodeString())
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializer for Instant values
|
||||
*/
|
||||
object KotlinInstantSerializer : KSerializer<Instant> {
|
||||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("Instant", PrimitiveKind.STRING)
|
||||
override fun serialize(encoder: Encoder, value: Instant) = encoder.encodeString(value.toString())
|
||||
override fun deserialize(decoder: Decoder): Instant = Instant.parse(decoder.decodeString())
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializer for LocalDate values
|
||||
*/
|
||||
object KotlinLocalDateSerializer : KSerializer<LocalDate> {
|
||||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("LocalDate", PrimitiveKind.STRING)
|
||||
override fun serialize(encoder: Encoder, value: LocalDate) = encoder.encodeString(value.toString())
|
||||
override fun deserialize(decoder: Decoder): LocalDate = LocalDate.parse(decoder.decodeString())
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializer for LocalDateTime values
|
||||
*/
|
||||
object KotlinLocalDateTimeSerializer : KSerializer<LocalDateTime> {
|
||||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("LocalDateTime", PrimitiveKind.STRING)
|
||||
override fun serialize(encoder: Encoder, value: LocalDateTime) = encoder.encodeString(value.toString())
|
||||
override fun deserialize(decoder: Decoder): LocalDateTime = LocalDateTime.parse(decoder.decodeString())
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializer for LocalTime values
|
||||
*/
|
||||
object KotlinLocalTimeSerializer : KSerializer<LocalTime> {
|
||||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("LocalTime", PrimitiveKind.STRING)
|
||||
override fun serialize(encoder: Encoder, value: LocalTime) = encoder.encodeString(value.toString())
|
||||
|
||||
Reference in New Issue
Block a user