SPMS_API/SPMS.API/Controllers/PublicController.cs
SEAN 58b94c6298 feat: API Rate Limiting 및 Swagger UI 구현 (#30)
- ASP.NET Core 내장 Rate Limiting (FixedWindow, IP 기반 분당 100회)
- 한도 초과 시 HTTP 429 + ApiResponse(에러코드 106) 반환
- Swashbuckle.AspNetCore 6.9.0 기반 Swagger UI 추가
- 도메인별 API 문서 그룹 (all, public, auth 등 10개)
- JWT Bearer 인증 UI (Authorize 버튼)
- X-Service-Code/X-API-KEY 커스텀 헤더 자동 표시 필터
- Microsoft.AspNetCore.OpenApi 제거 (Swashbuckle과 호환 충돌)

Closes #30
2026-02-09 17:11:46 +09:00

58 lines
1.7 KiB
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Swashbuckle.AspNetCore.Annotations;
using SPMS.Domain.Common;
using SPMS.Infrastructure;
namespace SPMS.API.Controllers;
[ApiController]
[Route("v1/out")]
[AllowAnonymous]
[ApiExplorerSettings(GroupName = "public")]
public class PublicController : ControllerBase
{
private readonly AppDbContext _dbContext;
public PublicController(AppDbContext dbContext)
{
_dbContext = dbContext;
}
[HttpPost("health")]
[SwaggerOperation(Summary = "서버 상태 확인", Description = "MariaDB, Redis, RabbitMQ 연결 상태를 확인합니다.")]
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,
"하나 이상의 서비스에 문제가 있습니다."));
}
}