1
0

refactor: leverage mappie

Signed-off-by: Alan Brault <alan.brault@visus.io>
This commit is contained in:
2026-03-02 07:45:48 -05:00
parent 767f0f9f0f
commit b316d0fbb4
6 changed files with 37 additions and 28 deletions
@@ -1,7 +1,6 @@
package io.visus.demos.kotlinapi.api.dto
import io.swagger.v3.oas.annotations.media.Schema
import io.visus.demos.kotlinapi.domain.model.ComponentHealth
@Schema(description = "Health status of an individual component")
data class ComponentHealthDto(
@@ -9,12 +8,4 @@ data class ComponentHealthDto(
val status: String,
@Schema(description = "Optional message with additional details", example = "MongoDB connection is active")
val message: String? = null,
) {
companion object {
fun from(componentHealth: ComponentHealth): ComponentHealthDto =
ComponentHealthDto(
status = componentHealth.status.name,
message = componentHealth.message,
)
}
}
)
@@ -1,8 +1,6 @@
package io.visus.demos.kotlinapi.api.dto
import io.swagger.v3.oas.annotations.media.Schema
import io.visus.demos.kotlinapi.domain.model.ComponentHealth
import io.visus.demos.kotlinapi.domain.model.HealthStatus
@Schema(description = "Health check response")
data class HealthResponse(
@@ -12,18 +10,4 @@ data class HealthResponse(
val timestamp: String,
@Schema(description = "Status of individual components")
val components: Map<String, ComponentHealthDto>? = null,
) {
companion object {
fun from(healthStatus: HealthStatus): HealthResponse =
HealthResponse(
status = healthStatus.status.name,
timestamp = healthStatus.timestamp.toString(),
components =
if (healthStatus.components.isNotEmpty()) {
healthStatus.components.mapValues { ComponentHealthDto.from(it.value) }
} else {
null
},
)
}
}
)
@@ -0,0 +1,14 @@
package io.visus.demos.kotlinapi.api.mappers
import io.visus.demos.kotlinapi.api.dto.ComponentHealthDto
import io.visus.demos.kotlinapi.domain.model.ComponentHealth
import tech.mappie.api.ObjectMappie
object ComponentHealthDtoMapper : ObjectMappie<ComponentHealth, ComponentHealthDto>() {
override fun map(from: ComponentHealth): ComponentHealthDto {
return ComponentHealthDto(
status = from.status.name,
message = from.message,
)
}
}
@@ -0,0 +1,17 @@
package io.visus.demos.kotlinapi.api.mappers
import io.visus.demos.kotlinapi.api.dto.HealthResponse
import io.visus.demos.kotlinapi.domain.model.HealthStatus
import tech.mappie.api.ObjectMappie
object HealthResponseMapper : ObjectMappie<HealthStatus, HealthResponse>() {
override fun map(from: HealthStatus): HealthResponse {
return HealthResponse(
status = from.status.name,
timestamp = from.timestamp.toString(),
components = from.components.mapValues { (_, componentHealth) ->
ComponentHealthDtoMapper.map(componentHealth)
}
)
}
}