feat: 앱 기본 설정 API 구현 (#88)

This commit is contained in:
SEAN 2026-02-10 14:17:22 +09:00
parent f07beda6c9
commit 7485e139cd
6 changed files with 79 additions and 0 deletions

View File

@ -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<IActionResult> 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<AppSettingsResponseDto>.Success(result));
}
}

View File

@ -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; }
}

View File

@ -7,4 +7,5 @@ public interface IAppConfigService
Task<AppConfigResponseDto> GetTermsAsync(string serviceCode); Task<AppConfigResponseDto> GetTermsAsync(string serviceCode);
Task<AppConfigResponseDto> GetPrivacyAsync(string serviceCode); Task<AppConfigResponseDto> GetPrivacyAsync(string serviceCode);
Task<AppVersionResponseDto> GetAppVersionAsync(string serviceCode, AppVersionRequestDto request); Task<AppVersionResponseDto> GetAppVersionAsync(string serviceCode, AppVersionRequestDto request);
Task<AppSettingsResponseDto> GetAppSettingsAsync(string serviceCode);
} }

View File

@ -49,6 +49,25 @@ public class AppConfigService : IAppConfigService
}; };
} }
public async Task<AppSettingsResponseDto> 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<AppConfigResponseDto> GetConfigUrlAsync(string serviceCode, string configKey) private async Task<AppConfigResponseDto> GetConfigUrlAsync(string serviceCode, string configKey)
{ {
var service = await _serviceRepository.GetByServiceCodeAsync(serviceCode); var service = await _serviceRepository.GetByServiceCodeAsync(serviceCode);

View File

@ -5,4 +5,5 @@ namespace SPMS.Domain.Interfaces;
public interface IAppConfigRepository : IRepository<AppConfig> public interface IAppConfigRepository : IRepository<AppConfig>
{ {
Task<AppConfig?> GetByKeyAsync(long serviceId, string configKey); Task<AppConfig?> GetByKeyAsync(long serviceId, string configKey);
Task<IReadOnlyList<AppConfig>> GetAllByServiceAsync(long serviceId);
} }

View File

@ -12,4 +12,9 @@ public class AppConfigRepository : Repository<AppConfig>, IAppConfigRepository
{ {
return await _dbSet.FirstOrDefaultAsync(c => c.ServiceId == serviceId && c.ConfigKey == configKey); return await _dbSet.FirstOrDefaultAsync(c => c.ServiceId == serviceId && c.ConfigKey == configKey);
} }
public async Task<IReadOnlyList<AppConfig>> GetAllByServiceAsync(long serviceId)
{
return await _dbSet.Where(c => c.ServiceId == serviceId).ToListAsync();
}
} }