1
0

refactor: optimize mappers

Signed-off-by: Alan Brault <alan.brault@visus.io>
This commit is contained in:
2026-03-03 07:30:20 -05:00
parent 67c1460217
commit 9f5c48fffc
3 changed files with 11 additions and 14 deletions

View File

@@ -1,13 +1,14 @@
package io.visus.demos.kotlinapi.api.dto
import io.swagger.v3.oas.annotations.media.Schema
import java.time.Instant
@Schema(description = "Health check response")
data class HealthResponse(
@Schema(description = "Current status of the API", example = "UP")
val status: String,
@Schema(description = "Timestamp of the health check", example = "2024-01-01T12:00:00Z")
val timestamp: String,
val timestamp: Instant,
@Schema(description = "Status of individual components")
val components: Map<String, ComponentHealthDto>? = null,
)

View File

@@ -6,8 +6,7 @@ import tech.mappie.api.ObjectMappie
object ComponentHealthDtoMapper : ObjectMappie<ComponentHealth, ComponentHealthDto>() {
override fun map(from: ComponentHealth): ComponentHealthDto =
ComponentHealthDto(
status = from.status.name,
message = from.message,
)
mapping {
ComponentHealthDto::status fromProperty ComponentHealth::status transform { it.name }
}
}

View File

@@ -5,13 +5,10 @@ import io.visus.demos.kotlinapi.domain.model.HealthStatus
import tech.mappie.api.ObjectMappie
object HealthResponseMapper : ObjectMappie<HealthStatus, HealthResponse>() {
override fun map(from: HealthStatus): HealthResponse =
HealthResponse(
status = from.status.name,
timestamp = from.timestamp.toString(),
components =
from.components.mapValues { (_, componentHealth) ->
ComponentHealthDtoMapper.map(componentHealth)
},
)
override fun map(from: HealthStatus): HealthResponse = mapping {
HealthResponse::status fromProperty HealthStatus::status transform { it.name }
HealthResponse::components fromProperty HealthStatus::components transform {
it.mapValues { (_, value) -> ComponentHealthDtoMapper.map(value) }
}
}
}