SPMS_API/SPMS.API/Controllers/PublicController.cs
SEAN 65b4207f94
All checks were successful
SPMS_API/pipeline/head This commit looks good
revert: Health Check GET 메서드 제거, POST만 유지 (#24)
2026-02-09 15:28:04 +09:00

55 lines
1.5 KiB
C#

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,
"하나 이상의 서비스에 문제가 있습니다."));
}
}