From 1ca498029375ad1be5e77b52994e8a4c3499eb25 Mon Sep 17 00:00:00 2001 From: SEAN Date: Mon, 2 Mar 2026 13:43:14 +0900 Subject: [PATCH] =?UTF-8?q?improvement:=20=ED=83=9C=EA=B7=B8=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=20API=20=ED=94=84=EB=A1=A0=ED=8A=B8=EC=97=94=EB=93=9C?= =?UTF-8?q?=20=EC=97=B0=EB=8F=99=20=EC=88=98=EC=A0=95=20(#267)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - TagSummaryDto에 tag_index 필드 추가 (서비스별 Id 순서 1-based 동적 계산) - ServiceSummaryDto/ServiceResponseDto에 service_id 필드 추가 - ServiceCodeMiddleware OPTIONAL_FOR_ADMIN에 /v1/in/tag 경로 추가 Closes #267 --- SPMS.API/Middlewares/ServiceCodeMiddleware.cs | 3 ++- .../DTOs/Service/ServiceListResponseDto.cs | 1 + SPMS.Application/DTOs/Service/ServiceResponseDto.cs | 1 + SPMS.Application/DTOs/Tag/TagListResponseDto.cs | 3 +++ SPMS.Application/Services/ServiceManagementService.cs | 2 ++ SPMS.Application/Services/TagService.cs | 10 ++++++++++ 6 files changed, 19 insertions(+), 1 deletion(-) diff --git a/SPMS.API/Middlewares/ServiceCodeMiddleware.cs b/SPMS.API/Middlewares/ServiceCodeMiddleware.cs index 2fc5313..9bcb197 100644 --- a/SPMS.API/Middlewares/ServiceCodeMiddleware.cs +++ b/SPMS.API/Middlewares/ServiceCodeMiddleware.cs @@ -34,7 +34,8 @@ public class ServiceCodeMiddleware // === OPTIONAL_FOR_ADMIN: 관리자는 X-Service-Code 선택 === if (path.StartsWithSegments("/v1/in/stats") || path.StartsWithSegments("/v1/in/device/list") || - path.StartsWithSegments("/v1/in/message/list")) + path.StartsWithSegments("/v1/in/message/list") || + path.StartsWithSegments("/v1/in/tag")) { if (context.Request.Headers.TryGetValue("X-Service-Code", out var optionalCode) && !string.IsNullOrWhiteSpace(optionalCode)) diff --git a/SPMS.Application/DTOs/Service/ServiceListResponseDto.cs b/SPMS.Application/DTOs/Service/ServiceListResponseDto.cs index 115b517..080c4ef 100644 --- a/SPMS.Application/DTOs/Service/ServiceListResponseDto.cs +++ b/SPMS.Application/DTOs/Service/ServiceListResponseDto.cs @@ -11,6 +11,7 @@ public class ServiceListResponseDto public class ServiceSummaryDto { + public long ServiceId { get; set; } public string ServiceCode { get; set; } = string.Empty; public string ServiceName { get; set; } = string.Empty; public string? Description { get; set; } diff --git a/SPMS.Application/DTOs/Service/ServiceResponseDto.cs b/SPMS.Application/DTOs/Service/ServiceResponseDto.cs index a41cfe5..d646a79 100644 --- a/SPMS.Application/DTOs/Service/ServiceResponseDto.cs +++ b/SPMS.Application/DTOs/Service/ServiceResponseDto.cs @@ -2,6 +2,7 @@ namespace SPMS.Application.DTOs.Service; public class ServiceResponseDto { + public long ServiceId { get; set; } public string ServiceCode { get; set; } = string.Empty; public string ServiceName { get; set; } = string.Empty; public string? Description { get; set; } diff --git a/SPMS.Application/DTOs/Tag/TagListResponseDto.cs b/SPMS.Application/DTOs/Tag/TagListResponseDto.cs index a4983a4..a00038e 100644 --- a/SPMS.Application/DTOs/Tag/TagListResponseDto.cs +++ b/SPMS.Application/DTOs/Tag/TagListResponseDto.cs @@ -14,6 +14,9 @@ public class TagListResponseDto public class TagSummaryDto { + [JsonPropertyName("tag_index")] + public int TagIndex { get; set; } + [JsonPropertyName("tag_id")] public long TagId { get; set; } diff --git a/SPMS.Application/Services/ServiceManagementService.cs b/SPMS.Application/Services/ServiceManagementService.cs index a2eee0b..94a2e63 100644 --- a/SPMS.Application/Services/ServiceManagementService.cs +++ b/SPMS.Application/Services/ServiceManagementService.cs @@ -982,6 +982,7 @@ public class ServiceManagementService : IServiceManagementService { return new ServiceSummaryDto { + ServiceId = service.Id, ServiceCode = service.ServiceCode, ServiceName = service.ServiceName, Description = service.Description, @@ -997,6 +998,7 @@ public class ServiceManagementService : IServiceManagementService { return new ServiceResponseDto { + ServiceId = service.Id, ServiceCode = service.ServiceCode, ServiceName = service.ServiceName, Description = service.Description, diff --git a/SPMS.Application/Services/TagService.cs b/SPMS.Application/Services/TagService.cs index 10967c9..00a838a 100644 --- a/SPMS.Application/Services/TagService.cs +++ b/SPMS.Application/Services/TagService.cs @@ -42,12 +42,22 @@ public class TagService : ITagService var tagIds = items.Select(t => t.Id).ToList(); var deviceCounts = await _deviceRepository.GetDeviceCountsByTagIdsAsync(tagIds); + // 서비스별 태그 순번 계산 (Id 오름차순 기준 1-based) + var serviceIds = items.Select(t => t.ServiceId).Distinct().ToList(); + var serviceTagOrders = new Dictionary>(); + foreach (var sid in serviceIds) + { + var allTags = await _tagRepository.FindAsync(t => t.ServiceId == sid); + serviceTagOrders[sid] = allTags.OrderBy(t => t.Id).Select(t => t.Id).ToList(); + } + var totalPages = (int)Math.Ceiling((double)totalCount / request.Size); return new TagListResponseDto { Items = items.Select(t => new TagSummaryDto { + TagIndex = serviceTagOrders[t.ServiceId].IndexOf(t.Id) + 1, TagId = t.Id, TagName = t.Name, Description = t.Description,