refactor: optimize mappers
Signed-off-by: Alan Brault <alan.brault@visus.io>
This commit is contained in:
@@ -1,13 +1,14 @@
|
|||||||
package io.visus.demos.kotlinapi.api.dto
|
package io.visus.demos.kotlinapi.api.dto
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema
|
import io.swagger.v3.oas.annotations.media.Schema
|
||||||
|
import java.time.Instant
|
||||||
|
|
||||||
@Schema(description = "Health check response")
|
@Schema(description = "Health check response")
|
||||||
data class HealthResponse(
|
data class HealthResponse(
|
||||||
@Schema(description = "Current status of the API", example = "UP")
|
@Schema(description = "Current status of the API", example = "UP")
|
||||||
val status: String,
|
val status: String,
|
||||||
@Schema(description = "Timestamp of the health check", example = "2024-01-01T12:00:00Z")
|
@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")
|
@Schema(description = "Status of individual components")
|
||||||
val components: Map<String, ComponentHealthDto>? = null,
|
val components: Map<String, ComponentHealthDto>? = null,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ import tech.mappie.api.ObjectMappie
|
|||||||
|
|
||||||
object ComponentHealthDtoMapper : ObjectMappie<ComponentHealth, ComponentHealthDto>() {
|
object ComponentHealthDtoMapper : ObjectMappie<ComponentHealth, ComponentHealthDto>() {
|
||||||
override fun map(from: ComponentHealth): ComponentHealthDto =
|
override fun map(from: ComponentHealth): ComponentHealthDto =
|
||||||
ComponentHealthDto(
|
mapping {
|
||||||
status = from.status.name,
|
ComponentHealthDto::status fromProperty ComponentHealth::status transform { it.name }
|
||||||
message = from.message,
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,10 @@ import io.visus.demos.kotlinapi.domain.model.HealthStatus
|
|||||||
import tech.mappie.api.ObjectMappie
|
import tech.mappie.api.ObjectMappie
|
||||||
|
|
||||||
object HealthResponseMapper : ObjectMappie<HealthStatus, HealthResponse>() {
|
object HealthResponseMapper : ObjectMappie<HealthStatus, HealthResponse>() {
|
||||||
override fun map(from: HealthStatus): HealthResponse =
|
override fun map(from: HealthStatus): HealthResponse = mapping {
|
||||||
HealthResponse(
|
HealthResponse::status fromProperty HealthStatus::status transform { it.name }
|
||||||
status = from.status.name,
|
HealthResponse::components fromProperty HealthStatus::components transform {
|
||||||
timestamp = from.timestamp.toString(),
|
it.mapValues { (_, value) -> ComponentHealthDtoMapper.map(value) }
|
||||||
components =
|
}
|
||||||
from.components.mapValues { (_, componentHealth) ->
|
}
|
||||||
ComponentHealthDtoMapper.map(componentHealth)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user