feat: 앱 버전 체크 API 구현 (#86) #87

Merged
seonkyu.kim merged 1 commits from feature/#86-app-version into develop 2026-02-10 05:14:49 +00:00
5 changed files with 85 additions and 0 deletions
Showing only changes of commit 0d80b8c25f - Show all commits

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/app")]
[ApiExplorerSettings(GroupName = "public")]
public class AppVersionController : ControllerBase
{
private readonly IAppConfigService _appConfigService;
public AppVersionController(IAppConfigService appConfigService)
{
_appConfigService = appConfigService;
}
[HttpPost("version")]
[SwaggerOperation(Summary = "앱 버전 체크", Description = "현재 앱 버전 정보를 확인하고 업데이트 필요 여부를 반환합니다.")]
public async Task<IActionResult> CheckVersionAsync([FromBody] AppVersionRequestDto request)
{
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.GetAppVersionAsync(serviceCode, request);
return Ok(ApiResponse<AppVersionResponseDto>.Success(result));
}
}

View File

@ -0,0 +1,12 @@
using System.Text.Json.Serialization;
namespace SPMS.Application.DTOs.AppConfig;
public class AppVersionRequestDto
{
[JsonPropertyName("platform")]
public string Platform { get; set; } = string.Empty;
[JsonPropertyName("app_version")]
public string AppVersion { get; set; } = string.Empty;
}

View File

@ -0,0 +1,18 @@
using System.Text.Json.Serialization;
namespace SPMS.Application.DTOs.AppConfig;
public class AppVersionResponseDto
{
[JsonPropertyName("latest_version")]
public string? LatestVersion { get; set; }
[JsonPropertyName("min_version")]
public string? MinVersion { get; set; }
[JsonPropertyName("is_force_update")]
public bool IsForceUpdate { get; set; }
[JsonPropertyName("update_url")]
public string? UpdateUrl { get; set; }
}

View File

@ -6,4 +6,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);
} }

View File

@ -27,6 +27,28 @@ public class AppConfigService : IAppConfigService
return await GetConfigUrlAsync(serviceCode, "privacy_url"); return await GetConfigUrlAsync(serviceCode, "privacy_url");
} }
public async Task<AppVersionResponseDto> GetAppVersionAsync(string serviceCode, AppVersionRequestDto request)
{
var service = await _serviceRepository.GetByServiceCodeAsync(serviceCode);
if (service == null)
throw new SpmsException(ErrorCodes.NotFound, "존재하지 않는 서비스입니다.", 404);
var latestVersion = await _appConfigRepository.GetByKeyAsync(service.Id, "latest_version");
var minVersion = await _appConfigRepository.GetByKeyAsync(service.Id, "min_version");
var forceUpdate = await _appConfigRepository.GetByKeyAsync(service.Id, "force_update");
var updateUrlKey = request.Platform?.ToLowerInvariant() == "ios" ? "update_url_ios" : "update_url_android";
var updateUrl = await _appConfigRepository.GetByKeyAsync(service.Id, updateUrlKey);
return new AppVersionResponseDto
{
LatestVersion = latestVersion?.ConfigValue,
MinVersion = minVersion?.ConfigValue,
IsForceUpdate = string.Equals(forceUpdate?.ConfigValue, "true", StringComparison.OrdinalIgnoreCase),
UpdateUrl = updateUrl?.ConfigValue
};
}
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);