From a9c944a27deba36a11168199752c84f4dd2c042d Mon Sep 17 00:00:00 2001 From: SEAN Date: Mon, 9 Feb 2026 15:17:45 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Health=20Check=20=EC=97=94=EB=93=9C?= =?UTF-8?q?=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EA=B5=AC=ED=98=84=20(#24)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PublicController 생성 (POST /v1/out/health) - MariaDB 연결 확인 (SELECT 1) - Redis, RabbitMQ 연결 확인 (Phase 2에서 구현 예정, not_configured 상태) - 정상: HTTP 200 + ApiResponse.Success / 이상: HTTP 503 + 상세 상태 --- SPMS.API/Controllers/PublicController.cs | 54 ++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 SPMS.API/Controllers/PublicController.cs diff --git a/SPMS.API/Controllers/PublicController.cs b/SPMS.API/Controllers/PublicController.cs new file mode 100644 index 0000000..96ee4e6 --- /dev/null +++ b/SPMS.API/Controllers/PublicController.cs @@ -0,0 +1,54 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using SPMS.Domain.Common; +using SPMS.Infrastructure; + +namespace SPMS.API.Controllers; + +[ApiController] +[Route("v1/out")] +[AllowAnonymous] +public class PublicController : ControllerBase +{ + private readonly AppDbContext _dbContext; + + public PublicController(AppDbContext dbContext) + { + _dbContext = dbContext; + } + + [HttpPost("health")] + public async Task HealthCheckAsync() + { + var checks = new Dictionary(); + var allHealthy = true; + + // 1. MariaDB 연결 확인 + try + { + await _dbContext.Database.ExecuteSqlRawAsync("SELECT 1"); + checks["database"] = new { status = "healthy" }; + } + catch (Exception ex) + { + checks["database"] = new { status = "unhealthy", error = ex.Message }; + allHealthy = false; + } + + // 2. Redis 연결 확인 (Phase 2에서 구현 예정) + checks["redis"] = new { status = "not_configured" }; + + // 3. RabbitMQ 연결 확인 (Phase 2에서 구현 예정) + checks["rabbitmq"] = new { status = "not_configured" }; + + if (allHealthy) + { + return Ok(ApiResponse.Success(checks)); + } + + return StatusCode(503, ApiResponse.Fail( + ErrorCodes.InternalError, + "하나 이상의 서비스에 문제가 있습니다.")); + } +}