feat: Health Check 엔드포인트 구현 (#24) #25

Merged
seonkyu.kim merged 1 commits from feature/#24-health-check into develop 2026-02-09 06:20:51 +00:00

View File

@ -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<IActionResult> HealthCheckAsync()
{
var checks = new Dictionary<string, object>();
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<object>.Success(checks));
}
return StatusCode(503, ApiResponse<object>.Fail(
ErrorCodes.InternalError,
"하나 이상의 서비스에 문제가 있습니다."));
}
}