From 7485e139cdd22cb1b7662b5598083f22132f3e5d Mon Sep 17 00:00:00 2001 From: SEAN Date: Tue, 10 Feb 2026 14:17:22 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=95=B1=20=EA=B8=B0=EB=B3=B8=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20API=20=EA=B5=AC=ED=98=84=20(#88)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SPMS.API/Controllers/AppConfigController.cs | 32 +++++++++++++++++++ .../DTOs/AppConfig/AppSettingsResponseDto.cs | 21 ++++++++++++ .../Interfaces/IAppConfigService.cs | 1 + SPMS.Application/Services/AppConfigService.cs | 19 +++++++++++ .../Interfaces/IAppConfigRepository.cs | 1 + .../Repositories/AppConfigRepository.cs | 5 +++ 6 files changed, 79 insertions(+) create mode 100644 SPMS.API/Controllers/AppConfigController.cs create mode 100644 SPMS.Application/DTOs/AppConfig/AppSettingsResponseDto.cs diff --git a/SPMS.API/Controllers/AppConfigController.cs b/SPMS.API/Controllers/AppConfigController.cs new file mode 100644 index 0000000..57c9afe --- /dev/null +++ b/SPMS.API/Controllers/AppConfigController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; +using Swashbuckle.AspNetCore.Annotations; +using SPMS.Application.DTOs.AppConfig; +using SPMS.Application.Interfaces; +using SPMS.Domain.Common; + +namespace SPMS.API.Controllers; + +[ApiController] +[Route("v1/in/public")] +[ApiExplorerSettings(GroupName = "public")] +public class AppConfigController : ControllerBase +{ + private readonly IAppConfigService _appConfigService; + + public AppConfigController(IAppConfigService appConfigService) + { + _appConfigService = appConfigService; + } + + [HttpPost("config")] + [SwaggerOperation(Summary = "앱 기본 설정", Description = "앱 기본 설정 정보를 조회합니다.")] + public async Task GetAppSettingsAsync() + { + var serviceCode = Request.Headers["X-Service-Code"].FirstOrDefault(); + if (string.IsNullOrWhiteSpace(serviceCode)) + return BadRequest(ApiResponse.Fail(ErrorCodes.BadRequest, "X-Service-Code 헤더가 필요합니다.")); + + var result = await _appConfigService.GetAppSettingsAsync(serviceCode); + return Ok(ApiResponse.Success(result)); + } +} diff --git a/SPMS.Application/DTOs/AppConfig/AppSettingsResponseDto.cs b/SPMS.Application/DTOs/AppConfig/AppSettingsResponseDto.cs new file mode 100644 index 0000000..22d3177 --- /dev/null +++ b/SPMS.Application/DTOs/AppConfig/AppSettingsResponseDto.cs @@ -0,0 +1,21 @@ +using System.Text.Json.Serialization; + +namespace SPMS.Application.DTOs.AppConfig; + +public class AppSettingsResponseDto +{ + [JsonPropertyName("min_app_version")] + public string? MinAppVersion { get; set; } + + [JsonPropertyName("is_maintenance")] + public bool IsMaintenance { get; set; } + + [JsonPropertyName("maintenance_msg")] + public string? MaintenanceMsg { get; set; } + + [JsonPropertyName("cs_email")] + public string? CsEmail { get; set; } + + [JsonPropertyName("cs_phone")] + public string? CsPhone { get; set; } +} diff --git a/SPMS.Application/Interfaces/IAppConfigService.cs b/SPMS.Application/Interfaces/IAppConfigService.cs index b9e84b6..f8fccbd 100644 --- a/SPMS.Application/Interfaces/IAppConfigService.cs +++ b/SPMS.Application/Interfaces/IAppConfigService.cs @@ -7,4 +7,5 @@ public interface IAppConfigService Task GetTermsAsync(string serviceCode); Task GetPrivacyAsync(string serviceCode); Task GetAppVersionAsync(string serviceCode, AppVersionRequestDto request); + Task GetAppSettingsAsync(string serviceCode); } diff --git a/SPMS.Application/Services/AppConfigService.cs b/SPMS.Application/Services/AppConfigService.cs index 966827e..0b0ca31 100644 --- a/SPMS.Application/Services/AppConfigService.cs +++ b/SPMS.Application/Services/AppConfigService.cs @@ -49,6 +49,25 @@ public class AppConfigService : IAppConfigService }; } + public async Task GetAppSettingsAsync(string serviceCode) + { + var service = await _serviceRepository.GetByServiceCodeAsync(serviceCode); + if (service == null) + throw new SpmsException(ErrorCodes.NotFound, "존재하지 않는 서비스입니다.", 404); + + var configs = await _appConfigRepository.GetAllByServiceAsync(service.Id); + var configDict = configs.ToDictionary(c => c.ConfigKey, c => c.ConfigValue); + + return new AppSettingsResponseDto + { + MinAppVersion = configDict.GetValueOrDefault("min_version"), + IsMaintenance = string.Equals(configDict.GetValueOrDefault("maintenance_mode"), "true", StringComparison.OrdinalIgnoreCase), + MaintenanceMsg = configDict.GetValueOrDefault("maintenance_message"), + CsEmail = configDict.GetValueOrDefault("cs_email"), + CsPhone = configDict.GetValueOrDefault("cs_phone") + }; + } + private async Task GetConfigUrlAsync(string serviceCode, string configKey) { var service = await _serviceRepository.GetByServiceCodeAsync(serviceCode); diff --git a/SPMS.Domain/Interfaces/IAppConfigRepository.cs b/SPMS.Domain/Interfaces/IAppConfigRepository.cs index e61c187..01cf381 100644 --- a/SPMS.Domain/Interfaces/IAppConfigRepository.cs +++ b/SPMS.Domain/Interfaces/IAppConfigRepository.cs @@ -5,4 +5,5 @@ namespace SPMS.Domain.Interfaces; public interface IAppConfigRepository : IRepository { Task GetByKeyAsync(long serviceId, string configKey); + Task> GetAllByServiceAsync(long serviceId); } diff --git a/SPMS.Infrastructure/Persistence/Repositories/AppConfigRepository.cs b/SPMS.Infrastructure/Persistence/Repositories/AppConfigRepository.cs index d4f4a34..8079bde 100644 --- a/SPMS.Infrastructure/Persistence/Repositories/AppConfigRepository.cs +++ b/SPMS.Infrastructure/Persistence/Repositories/AppConfigRepository.cs @@ -12,4 +12,9 @@ public class AppConfigRepository : Repository, IAppConfigRepository { return await _dbSet.FirstOrDefaultAsync(c => c.ServiceId == serviceId && c.ConfigKey == configKey); } + + public async Task> GetAllByServiceAsync(long serviceId) + { + return await _dbSet.Where(c => c.ServiceId == serviceId).ToListAsync(); + } }