SPMS_API/SPMS.API/Controllers/MessageController.cs
SEAN ef6d71a921 feat: 메시지 미리보기 API 구현 (#120)
- POST /v1/in/message/preview 엔드포인트 추가
- MessageService: 메시지 조회 → 변수 치환 → 미리보기 데이터 반환
- IMessageService 인터페이스 정의 (향후 CRUD 확장용)

Closes #120
2026-02-10 17:27:56 +09:00

48 lines
1.8 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using SPMS.Application.DTOs.Message;
using SPMS.Application.Interfaces;
using SPMS.Domain.Common;
namespace SPMS.API.Controllers;
[ApiController]
[Route("v1/in/message")]
[ApiExplorerSettings(GroupName = "message")]
public class MessageController : ControllerBase
{
private readonly IMessageValidationService _validationService;
private readonly IMessageService _messageService;
public MessageController(IMessageValidationService validationService, IMessageService messageService)
{
_validationService = validationService;
_messageService = messageService;
}
[HttpPost("validate")]
[SwaggerOperation(Summary = "메시지 유효성 검사", Description = "메시지 내용의 유효성을 검사합니다.")]
public IActionResult ValidateAsync([FromBody] MessageValidateRequestDto request)
{
var result = _validationService.Validate(request);
return Ok(ApiResponse<MessageValidationResultDto>.Success(result));
}
[HttpPost("preview")]
[SwaggerOperation(Summary = "메시지 미리보기", Description = "메시지 템플릿에 변수를 치환하여 미리보기를 생성합니다.")]
public async Task<IActionResult> PreviewAsync([FromBody] MessagePreviewRequestDto request)
{
var serviceId = GetServiceId();
var result = await _messageService.PreviewAsync(serviceId, request);
return Ok(ApiResponse<MessagePreviewResponseDto>.Success(result));
}
private long GetServiceId()
{
if (HttpContext.Items.TryGetValue("ServiceId", out var serviceIdObj) && serviceIdObj is long serviceId)
return serviceId;
throw new Domain.Exceptions.SpmsException(ErrorCodes.BadRequest, "서비스 식별 정보가 없습니다.", 400);
}
}