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