Refactor: Enhance healthcheck response with version info and DTO (#2378)

* Refactor: Enhance healthcheck response with version info and DTO

* test: Enhance healthcheck response with version info and DTO
This commit is contained in:
BAE
2026-01-21 22:38:44 -07:00
committed by GitHub
parent c42f62c338
commit 48b615d529
3 changed files with 136 additions and 3 deletions
@@ -1,21 +1,36 @@
package com.adityachandel.booklore.controller;
import com.adityachandel.booklore.model.dto.HealthcheckResponse;
import com.adityachandel.booklore.model.dto.response.SuccessResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
@RestController
@RequestMapping("/api/v1/healthcheck")
@Tag(name = "Healthcheck", description = "Endpoints for checking the healch of the application")
public class HealthcheckController {
@Operation(summary = "Get a ping response", description = "Check if the application is responding to requests")
@Value("${app.version}")
private String appVersion;
@Operation(summary = "Get a ping response", description = "Check if the application is responding")
@ApiResponse(responseCode = "200", description = "Health status returned successfully")
@GetMapping
public ResponseEntity<?> getPing() {
return ResponseEntity.ok(new SuccessResponse<>(200, "Pong"));
public ResponseEntity<SuccessResponse<HealthcheckResponse>> getPing() {
HealthcheckResponse healthData = HealthcheckResponse.builder()
.status("UP")
.message("Application is running smoothly.")
.version(appVersion) // ex) 'development' Insert
.timestamp(LocalDateTime.now())
.build();
return ResponseEntity.ok(new SuccessResponse<>(200, "Pong", healthData));
}
}
@@ -0,0 +1,15 @@
package com.adityachandel.booklore.model.dto;
import lombok.Builder;
import lombok.Data;
import java.time.LocalDateTime;
@Data
@Builder
public class HealthcheckResponse {
private String status;
private String message;
private LocalDateTime timestamp;
private String version;
}