chore: initial commit
Signed-off-by: Alan Brault <alan.brault@visus.io>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
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(
|
||||
@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,
|
||||
@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
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Schema(description = "Health status of an individual component")
|
||||
data class ComponentHealthDto(
|
||||
@Schema(description = "Component status", example = "UP")
|
||||
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,
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user