From 46a2105c139f8745bb2e8d88d601f5150efc5173 Mon Sep 17 00:00:00 2001 From: SEAN Date: Wed, 25 Feb 2026 15:09:01 +0900 Subject: [PATCH] =?UTF-8?q?improvement:=20=EB=A9=94=EC=8B=9C=EC=A7=80=20?= =?UTF-8?q?=EB=B0=9C=EC=86=A1=20=EC=83=81=ED=83=9C=20=EC=A7=91=EA=B3=84=20?= =?UTF-8?q?=EA=B7=9C=EC=B9=99=20=EA=B3=A0=EC=A0=95=20(#178)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #178 --- SPMS.API/Controllers/MessageController.cs | 4 ++-- SPMS.Application/Services/MessageService.cs | 11 +++-------- SPMS.Domain/Enums/SendStatus.cs | 18 ++++++++++++++++++ .../Repositories/MessageRepository.cs | 8 ++++---- 4 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 SPMS.Domain/Enums/SendStatus.cs diff --git a/SPMS.API/Controllers/MessageController.cs b/SPMS.API/Controllers/MessageController.cs index 239a928..200b6ab 100644 --- a/SPMS.API/Controllers/MessageController.cs +++ b/SPMS.API/Controllers/MessageController.cs @@ -32,7 +32,7 @@ public class MessageController : ControllerBase } [HttpPost("list")] - [SwaggerOperation(Summary = "메시지 목록 조회", Description = "메시지 목록을 페이지 단위로 조회합니다. X-Service-Code 헤더가 있으면 해당 서비스만, 없으면 전체 서비스 메시지를 반환합니다. send_status 필터(complete/pending/failed)를 지원합니다.")] + [SwaggerOperation(Summary = "메시지 목록 조회", Description = "메시지 목록을 페이지 단위로 조회합니다. X-Service-Code 헤더가 있으면 해당 서비스만, 없으면 전체 서비스 메시지를 반환합니다. send_status 필터(complete/pending/failed)를 지원합니다. 발송 상태는 통일된 SendStatus 규칙(pending=미발송, complete=1건 이상 성공, failed=전건 실패)으로 판정됩니다.")] public async Task GetListAsync([FromBody] MessageListRequestDto request) { var serviceId = GetServiceIdOrNull(); @@ -41,7 +41,7 @@ public class MessageController : ControllerBase } [HttpPost("info")] - [SwaggerOperation(Summary = "메시지 상세 조회", Description = "메시지 코드로 상세 정보를 조회합니다. 서비스 정보(service_name, service_code), 작성자(created_by_name), 발송 상태(latest_send_status), 템플릿 변수 목록을 포함합니다.")] + [SwaggerOperation(Summary = "메시지 상세 조회", Description = "메시지 코드로 상세 정보를 조회합니다. 서비스 정보(service_name, service_code), 작성자(created_by_name), 발송 상태(latest_send_status), 템플릿 변수 목록을 포함합니다. 발송 상태는 통일된 SendStatus 규칙(pending=미발송, complete=1건 이상 성공, failed=전건 실패)으로 판정됩니다.")] public async Task GetInfoAsync([FromBody] MessageInfoRequestDto request) { var serviceId = GetServiceId(); diff --git a/SPMS.Application/Services/MessageService.cs b/SPMS.Application/Services/MessageService.cs index 87a547c..697295f 100644 --- a/SPMS.Application/Services/MessageService.cs +++ b/SPMS.Application/Services/MessageService.cs @@ -4,6 +4,7 @@ using SPMS.Application.DTOs.Message; using SPMS.Application.DTOs.Notice; using SPMS.Application.Interfaces; using SPMS.Domain.Common; +using SPMS.Domain.Enums; using SPMS.Domain.Exceptions; using SPMS.Domain.Interfaces; @@ -84,7 +85,7 @@ public class MessageService : IMessageService CreatedAt = p.CreatedAt, ServiceName = p.ServiceName, ServiceCode = p.ServiceCode, - LatestSendStatus = DetermineSendStatus(p.TotalSendCount, p.SuccessCount) + LatestSendStatus = SendStatus.Determine(p.TotalSendCount, p.SuccessCount) }).ToList(), Pagination = new PaginationDto { @@ -96,12 +97,6 @@ public class MessageService : IMessageService }; } - private static string DetermineSendStatus(int totalSend, int successCount) - { - if (totalSend == 0) return "pending"; - return successCount > 0 ? "complete" : "failed"; - } - public async Task GetInfoAsync(long serviceId, MessageInfoRequestDto request) { if (string.IsNullOrWhiteSpace(request.MessageCode)) @@ -135,7 +130,7 @@ public class MessageService : IMessageService ServiceName = message.Service.ServiceName, ServiceCode = message.Service.ServiceCode, CreatedByName = message.CreatedByAdmin.Name, - LatestSendStatus = DetermineSendStatus(totalSend, successCount), + LatestSendStatus = SendStatus.Determine(totalSend, successCount), CreatedAt = message.CreatedAt }; } diff --git a/SPMS.Domain/Enums/SendStatus.cs b/SPMS.Domain/Enums/SendStatus.cs new file mode 100644 index 0000000..bfcc6e5 --- /dev/null +++ b/SPMS.Domain/Enums/SendStatus.cs @@ -0,0 +1,18 @@ +namespace SPMS.Domain.Enums; + +/// +/// 메시지 발송 상태 판정 규칙 (PRD FR-MSG-006) +/// 목록/상세/통계 API에서 동일 규칙을 적용해야 함 +/// +public static class SendStatus +{ + public const string Pending = "pending"; + public const string Complete = "complete"; + public const string Failed = "failed"; + + public static string Determine(int totalSendCount, int successCount) + { + if (totalSendCount == 0) return Pending; + return successCount > 0 ? Complete : Failed; + } +} diff --git a/SPMS.Infrastructure/Persistence/Repositories/MessageRepository.cs b/SPMS.Infrastructure/Persistence/Repositories/MessageRepository.cs index 1cb4e4e..04babc0 100644 --- a/SPMS.Infrastructure/Persistence/Repositories/MessageRepository.cs +++ b/SPMS.Infrastructure/Persistence/Repositories/MessageRepository.cs @@ -104,12 +104,12 @@ public class MessageRepository : Repository, IMessageRepository SuccessCount = _context.PushSendLogs.Count(l => l.MessageId == m.Id && l.Status == PushResult.Success) }); - // 발송 상태 필터 - if (sendStatus == "complete") + // 발송 상태 필터 (SendStatus 상수 사용 — PRD FR-MSG-006) + if (sendStatus == SendStatus.Complete) projected = projected.Where(p => p.SuccessCount > 0); - else if (sendStatus == "failed") + else if (sendStatus == SendStatus.Failed) projected = projected.Where(p => p.TotalSendCount > 0 && p.SuccessCount == 0); - else if (sendStatus == "pending") + else if (sendStatus == SendStatus.Pending) projected = projected.Where(p => p.TotalSendCount == 0); var totalCount = await projected.CountAsync(); -- 2.45.1